org.snapscript.common.IdentityCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.common;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
public class IdentityCache implements Cache {
private final Map cache;
public IdentityCache() {
this(32);
}
public IdentityCache(int capacity) {
this.cache = new IdentityHashMap();
}
@Override
public synchronized void clear() {
cache.clear();
}
@Override
public synchronized int size() {
return cache.size();
}
@Override
public synchronized Set keySet() {
return cache.keySet();
}
@Override
public synchronized V fetch(K key) {
return cache.get(key);
}
@Override
public synchronized V cache(K key, V value) {
return cache.put(key, value);
}
@Override
public synchronized V take(K key) {
return cache.remove(key);
}
@Override
public synchronized boolean contains(K key) {
return cache.containsKey(key);
}
@Override
public synchronized boolean isEmpty() {
return cache.isEmpty();
}
@Override
public synchronized String toString() {
return String.valueOf(cache);
}
}