Module org.eclipse.persistence.core
Class IdentityWeakHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.eclipse.persistence.internal.helper.IdentityWeakHashMap<K,V>
-
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,V>
public class IdentityWeakHashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected intcountprotected floatloadFactorprotected ReferenceQueuereferenceQueueThis is used by the garbage collector.protected intthreshold
-
Constructor Summary
Constructors Constructor Description IdentityWeakHashMap()Constructs a newIdentityWeakHashMapwith a default initial capacity of32and a loadfactor of0.75.IdentityWeakHashMap(int initialCapacity)Constructs a newIdentityWeakHashMapwith the given initial capacity and a default loadFactor of0.75.IdentityWeakHashMap(int initialCapacity, float loadFactor)Constructs a newIdentityWeakHashMapwith the given initial capacity and the given loadFactor.IdentityWeakHashMap(Map m)Constructs a newIdentityWeakHashMapwith the same mappings as the given map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcleanUp()voidclear()Removes all of the mappings from thisIdentityWeakHashMap.Objectclone()Returns a shallow copy of thisIdentityWeakHashMap(the elements are not cloned).booleancontainsKey(Object key)Returnstrueif thisIdentityWeakHashMapcontains a mapping for the given key.booleancontainsValue(Object obj)Returnstrueif thisIdentityWeakHashMapcontains the given object.SetentrySet()Returns a collection view of the mappings contained in thisIdentityWeakHashMap.Vget(Object key)Returns the value to which the given key is mapped in thisIdentityWeakHashMap.booleanisEmpty()SetkeySet()Returns a set view of the keys contained in thisIdentityWeakHashMap.Vput(K key, V obj)Associate the given object with the given key in thisIdentityWeakHashMap, replacing any existing mapping.voidputAll(Map<? extends K,? extends V> m)Copies all of the mappings from the given map to thisIdentityWeakHashMap, replacing any existing mappings.Vremove(Object key)Removes the mapping (key and its corresponding value) from thisIdentityWeakHashMap, if present.protected booleanremoveEntry(Map.Entry o, boolean userModification)intsize()Collectionvalues()Returns a collection view of the values contained in thisIdentityWeakHashMap.-
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
count
protected transient int count
-
threshold
protected int threshold
-
loadFactor
protected float loadFactor
-
referenceQueue
protected ReferenceQueue referenceQueue
This is used by the garbage collector. Every weak reference that is garbage collected will be enqueued on this. Then only this queue needs to be checked to remove empty references.
-
-
Constructor Detail
-
IdentityWeakHashMap
public IdentityWeakHashMap(int initialCapacity, float loadFactor)Constructs a newIdentityWeakHashMapwith the given initial capacity and the given loadFactor.- Parameters:
initialCapacity- the initial capacity of thisIdentityWeakHashMap.loadFactor- the loadFactor of theIdentityWeakHashMap.- Throws:
IllegalArgumentException- if the initial capacity is less than zero, or if the loadFactor is nonpositive.
-
IdentityWeakHashMap
public IdentityWeakHashMap(int initialCapacity)
Constructs a newIdentityWeakHashMapwith the given initial capacity and a default loadFactor of0.75.- Parameters:
initialCapacity- the initial capacity of theIdentityWeakHashMap.- Throws:
IllegalArgumentException- if the initial capacity is less than zero.
-
IdentityWeakHashMap
public IdentityWeakHashMap()
Constructs a newIdentityWeakHashMapwith a default initial capacity of32and a loadfactor of0.75.
-
IdentityWeakHashMap
public IdentityWeakHashMap(Map m)
Constructs a newIdentityWeakHashMapwith the same mappings as the given map. TheIdentityWeakHashMapis created with a capacity sufficient to hold the elements of the given map.- Parameters:
m- the map whose mappings are to be placed in theIdentityWeakHashMap.
-
-
Method Detail
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
containsValue
public boolean containsValue(Object obj)
Returnstrueif thisIdentityWeakHashMapcontains the given object. Equality is tested by the equals() method.- Specified by:
containsValuein interfaceMap<K,V>- Overrides:
containsValuein classAbstractMap<K,V>- Parameters:
obj- the object to find.- Returns:
trueif thisIdentityWeakHashMapcontains obj.- Throws:
NullPointerException- if obj isnull.
-
containsKey
public boolean containsKey(Object key)
Returnstrueif thisIdentityWeakHashMapcontains a mapping for the given key. Equality is tested by reference.- Specified by:
containsKeyin interfaceMap<K,V>- Overrides:
containsKeyin classAbstractMap<K,V>- Parameters:
key- object to be used as a key into thisIdentityWeakHashMap.- Returns:
trueif thisIdentityWeakHashMapcontains a mapping for key.
-
get
public V get(Object key)
Returns the value to which the given key is mapped in thisIdentityWeakHashMap. Returnsnullif thisIdentityWeakHashMapcontains no mapping for this key.
-
put
public V put(K key, V obj)
Associate the given object with the given key in thisIdentityWeakHashMap, replacing any existing mapping.- Specified by:
putin interfaceMap<K,V>- Overrides:
putin classAbstractMap<K,V>- Parameters:
key- key to map to given object.obj- object to be associated with key.- Returns:
- the previous object for key or
nullif thisIdentityWeakHashMapdid not have one. - Throws:
NullPointerException- if obj isnull.
-
remove
public V remove(Object key)
Removes the mapping (key and its corresponding value) from thisIdentityWeakHashMap, if present.
-
removeEntry
protected boolean removeEntry(Map.Entry o, boolean userModification)
-
putAll
public void putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the given map to thisIdentityWeakHashMap, replacing any existing mappings.- Specified by:
putAllin interfaceMap<K,V>- Overrides:
putAllin classAbstractMap<K,V>- Parameters:
m- mappings to be stored in thisIdentityWeakHashMap.- Throws:
NullPointerException- if m is null.
-
clear
public void clear()
Removes all of the mappings from thisIdentityWeakHashMap.
-
cleanUp
protected void cleanUp()
-
clone
public Object clone()
Returns a shallow copy of thisIdentityWeakHashMap(the elements are not cloned).- Overrides:
clonein classAbstractMap<K,V>- Returns:
- a shallow copy of this
IdentityWeakHashMap.
-
keySet
public Set keySet()
Returns a set view of the keys contained in thisIdentityWeakHashMap. The set is backed by the map, so changes to the map are reflected in the set, and vice versa. The set supports element removal, which removes the corresponding mapping from this map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.
-
values
public Collection values()
Returns a collection view of the values contained in thisIdentityWeakHashMap. The collection is backed by the map, so changes to the map are reflected in the collection, and vice versa. The collection supports element removal, which removes the corresponding mapping from this map, via theIterator.remove,Collection.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.
-
entrySet
public Set entrySet()
Returns a collection view of the mappings contained in thisIdentityWeakHashMap. Each element in the returned collection is aMap.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice versa. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Collection.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.
-
-