internal.sdmx.desktop.plugin.Caches Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdplus-sdmx-desktop-plugin Show documentation
Show all versions of jdplus-sdmx-desktop-plugin Show documentation
${project.parent.artifactId} - ${project.artifactId}
The newest version!
package internal.sdmx.desktop.plugin;
import jdplus.toolkit.base.tsp.util.ShortLivedCache;
import jdplus.toolkit.base.tsp.util.ShortLivedCachingLoader;
import java.time.Duration;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
public final class Caches {
private Caches() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
public static ConcurrentMap asConcurrentMap(ShortLivedCache cache) {
return new ConcurrentMap() {
@Override
public V putIfAbsent(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object key, Object value) {
throw new UnsupportedOperationException();
}
@Override
public boolean replace(K key, V oldValue, V newValue) {
throw new UnsupportedOperationException();
}
@Override
public V replace(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException();
}
@Override
public boolean containsKey(Object key) {
throw new UnsupportedOperationException();
}
@Override
public boolean containsValue(Object value) {
throw new UnsupportedOperationException();
}
@Override
public V get(Object key) {
return cache.get((K) key);
}
@Override
public V put(K key, V value) {
cache.put(key, value);
return null;
}
@Override
public V remove(Object key) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public Set keySet() {
throw new UnsupportedOperationException();
}
@Override
public Collection values() {
throw new UnsupportedOperationException();
}
@Override
public Set> entrySet() {
throw new UnsupportedOperationException();
}
};
}
public static ConcurrentMap ttlCacheAsMap(Duration duration) {
return asConcurrentMap(ShortLivedCachingLoader.get().ofTtl(duration));
}
}