All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.hsac.fitnesse.fixture.util.selenium.caching.ObjectCacheMap Maven / Gradle / Ivy

There is a newer version: 5.3.17
Show newest version
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