(Iterable<? extends K> keys)
| 4080 | } |
| 4081 | |
| 4082 | ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { |
| 4083 | int hits = 0; |
| 4084 | int misses = 0; |
| 4085 | |
| 4086 | Map<K, V> result = Maps.newLinkedHashMap(); |
| 4087 | Set<K> keysToLoad = Sets.newLinkedHashSet(); |
| 4088 | for (K key : keys) { |
| 4089 | V value = get(key); |
| 4090 | if (!result.containsKey(key)) { |
| 4091 | result.put(key, value); |
| 4092 | if (value == null) { |
| 4093 | misses++; |
| 4094 | keysToLoad.add(key); |
| 4095 | } else { |
| 4096 | hits++; |
| 4097 | } |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | try { |
| 4102 | if (!keysToLoad.isEmpty()) { |
| 4103 | try { |
| 4104 | Map<K, V> newEntries = loadAll(keysToLoad, defaultLoader); |
| 4105 | for (K key : keysToLoad) { |
| 4106 | V value = newEntries.get(key); |
| 4107 | if (value == null) { |
| 4108 | throw new InvalidCacheLoadException("loadAll failed to return a value for " + key); |
| 4109 | } |
| 4110 | result.put(key, value); |
| 4111 | } |
| 4112 | } catch (UnsupportedLoadingOperationException e) { |
| 4113 | // loadAll not implemented, fallback to load |
| 4114 | for (K key : keysToLoad) { |
| 4115 | misses--; // get will count this miss |
| 4116 | result.put(key, get(key, defaultLoader)); |
| 4117 | } |
| 4118 | } |
| 4119 | } |
| 4120 | return ImmutableMap.copyOf(result); |
| 4121 | } finally { |
| 4122 | globalStatsCounter.recordHits(hits); |
| 4123 | globalStatsCounter.recordMisses(misses); |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | /** |
| 4128 | * Returns the result of calling {@link CacheLoader#loadAll}, or null if {@code loader} doesn't |
nothing calls this directly
no test coverage detected