org.snapscript.common.LeastRecentlyUsedSet 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.AbstractSet;
import java.util.Iterator;
public class LeastRecentlyUsedSet extends AbstractSet {
private final LeastRecentlyUsedMap cache;
public LeastRecentlyUsedSet() {
this(1000);
}
public LeastRecentlyUsedSet(int capacity) {
this.cache = new LeastRecentlyUsedMap(capacity);
}
@Override
public boolean contains(Object value) {
return cache.containsKey(value);
}
@Override
public boolean remove(Object value) {
return cache.remove(value) != null;
}
@Override
public boolean add(T value) {
return cache.put(value, value) != null;
}
@Override
public Iterator iterator() {
return cache.keySet().iterator();
}
@Override
public void clear() {
cache.clear();
}
@Override
public int size() {
return cache.size();
}
}