nl.hsac.fitnesse.fixture.util.selenium.caching.ObjectCacheMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hsac-fitnesse-fixtures Show documentation
Show all versions of hsac-fitnesse-fixtures Show documentation
Fixtures to assist in testing via FitNesse
package nl.hsac.fitnesse.fixture.util.selenium.caching;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
/**
* Maintains a map of ObjectCache instances.
*/
public class ObjectCacheMap {
private final Map> valuesCache = new HashMap<>();
private final Function> cacheCreationFunction;
public ObjectCacheMap(Function function) {
cacheCreationFunction = x -> new ObjectCache<>(() -> function.apply(x));
}
public V getValue(K key) {
return getObjectCache(key).getValue();
}
public void putAll(Map newValues, long timestamp) {
newValues.forEach((k,v) -> getObjectCache(k).setValue(v, timestamp));
}
public ObjectCache getObjectCache(K key) {
return valuesCache.computeIfAbsent(key, cacheCreationFunction);
}
public Map> getValuesCache() {
return valuesCache;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy