use of java.util.stream.Collectors in project caffeine by ben-manes.
the class LoadingCacheProxy method getAll.
/** Returns the entries, loading if necessary, and optionally updates their access expiry time. */
@SuppressWarnings("PMD.AvoidCatchingNPE")
private Map<K, V> getAll(Set<? extends K> keys, boolean updateAccessTime) {
requireNotClosed();
boolean statsEnabled = statistics.isEnabled();
long start = statsEnabled ? ticker.read() : 0L;
try {
Map<K, Expirable<V>> entries = getAndFilterExpiredEntries(keys, updateAccessTime);
if (entries.size() != keys.size()) {
List<K> keysToLoad = keys.stream().filter(key -> !entries.containsKey(key)).collect(Collectors.<K>toList());
entries.putAll(cache.getAll(keysToLoad));
}
Map<K, V> result = copyMap(entries);
if (statsEnabled) {
statistics.recordGetTime(ticker.read() - start);
}
return result;
} catch (NullPointerException | IllegalStateException | ClassCastException | CacheException e) {
throw e;
} catch (RuntimeException e) {
throw new CacheException(e);
} finally {
dispatcher.awaitSynchronous();
}
}
Aggregations