soot.jimple.infoflow.collect.WeakConcurrentHashSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soot-infoflow Show documentation
Show all versions of soot-infoflow Show documentation
Soot extending data flow tracking components for Java
package soot.jimple.infoflow.collect;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.concurrent.ConcurrentMap;
import com.google.common.collect.MapMaker;
/**
* HashSet with weak keys
*
* @author Steven Arzt
*
* @param
*/
public class WeakConcurrentHashSet extends AbstractSet {
protected ConcurrentMap delegate;
/**
* Creates a new, empty ConcurrentHashSet.
*/
public WeakConcurrentHashSet() {
delegate = new MapMaker().weakKeys().concurrencyLevel
(Runtime.getRuntime().availableProcessors()).makeMap();
}
@Override
public int size() {
return delegate.size();
}
@Override
public boolean contains(Object o) {
return delegate.containsKey(o);
}
@Override
public Iterator iterator() {
return delegate.keySet().iterator();
}
@Override
public boolean add(E o) {
return delegate.put(o, o)==null;
}
@Override
public boolean remove(Object o) {
return delegate.remove(o)!=null;
}
@Override
public void clear() {
delegate.entrySet().clear();
}
@Override
public int hashCode() {
return delegate.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof ConcurrentHashSet && delegate.equals(obj);
}
@Override
public String toString() {
return delegate.keySet().toString();
}
}