(Iterable<? extends K> keys)
| 4044 | } |
| 4045 | |
| 4046 | ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException { |
| 4047 | int hits = 0; |
| 4048 | int misses = 0; |
| 4049 | Map<K, V> result = Maps.newLinkedHashMap(); |
| 4050 | Set<K> keysToLoad = Sets.newLinkedHashSet(); |
| 4051 | for (K key : keys) { |
| 4052 | V value = get(key); |
| 4053 | if (!result.containsKey(key)) { |
| 4054 | result.put(key, value); |
| 4055 | if (value == null) { |
| 4056 | misses++; |
| 4057 | keysToLoad.add(key); |
| 4058 | } else { |
| 4059 | hits++; |
| 4060 | } |
| 4061 | } |
| 4062 | } |
| 4063 | try { |
| 4064 | if (!keysToLoad.isEmpty()) { |
| 4065 | try { |
| 4066 | Map<K, V> newEntries = loadAll(keysToLoad, defaultLoader); |
| 4067 | for (K key : keysToLoad) { |
| 4068 | V value = newEntries.get(key); |
| 4069 | if (value == null) { |
| 4070 | throw new InvalidCacheLoadException("loadAll failed to return a value for " + key); |
| 4071 | } |
| 4072 | result.put(key, value); |
| 4073 | } |
| 4074 | } catch (UnsupportedLoadingOperationException e) { |
| 4075 | // loadAll not implemented, fallback to load |
| 4076 | for (K key : keysToLoad) { |
| 4077 | misses--; // get will count this miss |
| 4078 | result.put(key, get(key, defaultLoader)); |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | return ImmutableMap.copyOf(result); |
| 4083 | } finally { |
| 4084 | globalStatsCounter.recordHits(hits); |
| 4085 | globalStatsCounter.recordMisses(misses); |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | /** |
| 4090 | * Returns the result of calling {@link CacheLoader#loadAll}, or null if {@code loader} doesn't |
nothing calls this directly
no test coverage detected