soot.jimple.infoflow.collect.ConcurrentIdentityHashMap 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.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class ConcurrentIdentityHashMap implements ConcurrentMap {
private final ConcurrentMap, V> innerMap;
public ConcurrentIdentityHashMap() {
this.innerMap = new ConcurrentHashMap, V>();
}
@Override
public int size() {
return innerMap.size();
}
@Override
public boolean isEmpty() {
return innerMap.isEmpty();
}
@SuppressWarnings("unchecked")
@Override
public boolean containsKey(Object key) {
return innerMap.containsKey(new IdentityWrapper((K) key));
}
@Override
public boolean containsValue(Object value) {
return innerMap.containsValue(value);
}
@SuppressWarnings("unchecked")
@Override
public V get(Object key) {
return innerMap.get(new IdentityWrapper((K) key));
}
@Override
public V put(K key, V value) {
return innerMap.put(new IdentityWrapper(key), value);
}
@SuppressWarnings("unchecked")
@Override
public V remove(Object key) {
return innerMap.remove(new IdentityWrapper((K) key));
}
@Override
public void putAll(Map extends K, ? extends V> m) {
for (Entry extends K, ? extends V> entry : m.entrySet())
put(entry.getKey(), entry.getValue());
}
@Override
public void clear() {
innerMap.clear();
}
@Override
public Set keySet() {
Set set = Collections.newSetFromMap(new IdentityHashMap());
for (IdentityWrapper k : innerMap.keySet())
set.add(k.getContents());
return set;
}
@Override
public Collection values() {
return innerMap.values();
}
public class MapEntry implements Entry {
private final K key;
private final V value;
public MapEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
throw new RuntimeException("Unsupported operation");
}
@Override
public boolean equals(Object other) {
if (other == null)
return false;
if (this.getClass() != other.getClass())
return false;
@SuppressWarnings("unchecked")
MapEntry me = (MapEntry) other;
return (this.key == me.key && this.value.equals(me.value));
}
@Override
public int hashCode() {
return System.identityHashCode(key) + value.hashCode();
}
}
@Override
public Set> entrySet() {
Set> set = new HashSet>();
for (Entry, V> entry : innerMap.entrySet())
set.add(new MapEntry(entry.getKey().getContents(), entry.getValue()));
return set;
}
@Override
public String toString() {
return innerMap.toString();
}
@Override
public V putIfAbsent(K key, V value) {
return innerMap.putIfAbsent(new IdentityWrapper(key), value);
}
@Override
public boolean remove(Object key, Object value) {
return innerMap.remove(new IdentityWrapper<>(key), value);
}
@Override
public boolean replace(K key, V oldValue, V newValue) {
return innerMap.replace(new IdentityWrapper(key), oldValue, newValue);
}
@Override
public V replace(K key, V value) {
return innerMap.replace(new IdentityWrapper(key), value);
}
}