(Iterable<? extends K> keys)
| 4029 | } |
| 4030 | |
| 4031 | ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { |
| 4032 | int hits = 0; |
| 4033 | int misses = 0; |
| 4034 | |
| 4035 | Map<K, V> result = new LinkedHashMap<>(); |
| 4036 | Set<K> keysToLoad = new LinkedHashSet<>(); |
| 4037 | for (K key : keys) { |
| 4038 | V value = get(key); |
| 4039 | if (!result.containsKey(key)) { |
| 4040 | result.put(key, value); |
| 4041 | if (value == null) { |
| 4042 | misses++; |
| 4043 | keysToLoad.add(key); |
| 4044 | } else { |
| 4045 | hits++; |
| 4046 | } |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | try { |
| 4051 | if (!keysToLoad.isEmpty()) { |
| 4052 | try { |
| 4053 | Map<K, V> newEntries = loadAll(unmodifiableSet(keysToLoad), defaultLoader); |
| 4054 | for (K key : keysToLoad) { |
| 4055 | V value = newEntries.get(key); |
| 4056 | if (value == null) { |
| 4057 | throw new InvalidCacheLoadException(class="st">"loadAll failed to return a value for " + key); |
| 4058 | } |
| 4059 | result.put(key, value); |
| 4060 | } |
| 4061 | } catch (UnsupportedLoadingOperationException e) { |
| 4062 | class="cm">// loadAll not implemented, fallback to load |
| 4063 | for (K key : keysToLoad) { |
| 4064 | misses--; class="cm">// get will count this miss |
| 4065 | result.put(key, get(key, defaultLoader)); |
| 4066 | } |
| 4067 | } |
| 4068 | } |
| 4069 | return ImmutableMap.copyOf(result); |
| 4070 | } finally { |
| 4071 | globalStatsCounter.recordHits(hits); |
| 4072 | globalStatsCounter.recordMisses(misses); |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /** |
| 4077 | * Returns the result of calling {@link CacheLoader#loadAll}, or null if {@code loader} doesn't |
nothing calls this directly
no test coverage detected