Package org.apache.lucene.util
Class WeakIdentityMap<K,V>
- java.lang.Object
-
- org.apache.lucene.util.WeakIdentityMap<K,V>
-
public final class WeakIdentityMap<K,V> extends Object
Implements a combination ofWeakHashMapandIdentityHashMap. Useful for caches that need to key off of a==comparison instead of a.equals.This class is not a general-purpose
Mapimplementation! It intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required.This implementation was forked from Apache CXF but modified to not implement the
Mapinterface and without any set views on it, as those are error-prone and inefficient, if not implemented carefully. The map only containsIteratorimplementations on the values and not-GCed keys. Lucene's implementation also supportsnullkeys, but those are never weak!- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)Vget(Object key)booleanisEmpty()Iterator<K>keyIterator()Returns an iterator over all weak keys of this map.static <K,V>
WeakIdentityMap<K,V>newConcurrentHashMap()Creates a newWeakIdentityMapbased on aConcurrentHashMap.static <K,V>
WeakIdentityMap<K,V>newHashMap()Creates a newWeakIdentityMapbased on a non-synchronizedHashMap.Vput(K key, V value)Vremove(Object key)intsize()Iterator<V>valueIterator()Returns an iterator over all values of this map.
-
-
-
Method Detail
-
newHashMap
public static final <K,V> WeakIdentityMap<K,V> newHashMap()
Creates a newWeakIdentityMapbased on a non-synchronizedHashMap.
-
newConcurrentHashMap
public static final <K,V> WeakIdentityMap<K,V> newConcurrentHashMap()
Creates a newWeakIdentityMapbased on aConcurrentHashMap.
-
clear
public void clear()
-
containsKey
public boolean containsKey(Object key)
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
keyIterator
public Iterator<K> keyIterator()
Returns an iterator over all weak keys of this map. Keys already garbage collected will not be returned. This Iterator does not support removals.
-
-