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