com.accelad.math.doubledouble.CacheMap Maven / Gradle / Ivy
The newest version!
package com.accelad.math.doubledouble;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
class CacheMap {
private final Map map = new ConcurrentHashMap<>();
private final int sizeLimit;
CacheMap(int sizeLimit) {
this.sizeLimit = sizeLimit;
}
V get(K key, Supplier supplier) {
if (map.size() > sizeLimit) {
map.clear();
}
return map.computeIfAbsent(key, k -> supplier.get());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy