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

soot.jimple.infoflow.collect.WeakConcurrentHashSet Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
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();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy