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 int
count
protected org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry<K,V>[]
entries
protected float
loadFactor
protected ReferenceQueue
referenceQueue
This is used by the garbage collector.protected int
threshold
-
Constructor Summary
Constructors Constructor Description IdentityWeakHashMap()
Constructs a newIdentityWeakHashMap
with a default initial capacity of32
and a loadfactor of0.75
.IdentityWeakHashMap(int initialCapacity)
Constructs a newIdentityWeakHashMap
with the given initial capacity and a default loadFactor of0.75
.IdentityWeakHashMap(int initialCapacity, float loadFactor)
Constructs a newIdentityWeakHashMap
with the given initial capacity and the given loadFactor.IdentityWeakHashMap(Map m)
Constructs a newIdentityWeakHashMap
with the same mappings as the given map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cleanUp()
void
clear()
Removes all of the mappings from thisIdentityWeakHashMap
.Object
clone()
Returns a shallow copy of thisIdentityWeakHashMap
(the elements are not cloned).boolean
containsKey(Object key)
Returnstrue
if thisIdentityWeakHashMap
contains a mapping for the given key.boolean
containsValue(Object obj)
Returnstrue
if thisIdentityWeakHashMap
contains the given object.Set
entrySet()
Returns a collection view of the mappings contained in thisIdentityWeakHashMap
.V
get(Object key)
Returns the value to which the given key is mapped in thisIdentityWeakHashMap
.boolean
isEmpty()
Set
keySet()
Returns a set view of the keys contained in thisIdentityWeakHashMap
.V
put(K key, V obj)
Associate the given object with the given key in thisIdentityWeakHashMap
, replacing any existing mapping.void
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the given map to thisIdentityWeakHashMap
, replacing any existing mappings.V
remove(Object key)
Removes the mapping (key and its corresponding value) from thisIdentityWeakHashMap
, if present.protected boolean
removeEntry(org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry o, boolean userModification)
int
size()
Collection
values()
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
-
entries
protected transient org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry<K,V>[] entries
-
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 newIdentityWeakHashMap
with 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 newIdentityWeakHashMap
with 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 newIdentityWeakHashMap
with a default initial capacity of32
and a loadfactor of0.75
.
-
IdentityWeakHashMap
public IdentityWeakHashMap(Map m)
Constructs a newIdentityWeakHashMap
with the same mappings as the given map. TheIdentityWeakHashMap
is 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)
Returnstrue
if thisIdentityWeakHashMap
contains the given object. Equality is tested by the equals() method.- Specified by:
containsValue
in interfaceMap<K,V>
- Overrides:
containsValue
in classAbstractMap<K,V>
- Parameters:
obj
- the object to find.- Returns:
true
if thisIdentityWeakHashMap
contains obj.- Throws:
NullPointerException
- if obj isnull
.
-
containsKey
public boolean containsKey(Object key)
Returnstrue
if thisIdentityWeakHashMap
contains a mapping for the given key. Equality is tested by reference.- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classAbstractMap<K,V>
- Parameters:
key
- object to be used as a key into thisIdentityWeakHashMap
.- Returns:
true
if thisIdentityWeakHashMap
contains a mapping for key.
-
get
public V get(Object key)
Returns the value to which the given key is mapped in thisIdentityWeakHashMap
. Returnsnull
if thisIdentityWeakHashMap
contains 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:
put
in interfaceMap<K,V>
- Overrides:
put
in 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
null
if thisIdentityWeakHashMap
did 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(org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry 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:
putAll
in interfaceMap<K,V>
- Overrides:
putAll
in 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:
clone
in 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
, andclear
operations. It does not support theadd
oraddAll
operations.
-
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
, andclear
operations. It does not support theadd
oraddAll
operations.
-
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
, andclear
operations. It does not support theadd
oraddAll
operations.
-
-