Class PhantomValueHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.arakhne.afc.references.AbstractReferencedValueMap<K,V>
-
- org.arakhne.afc.references.AbstractPhantomValueMap<K,V>
-
- org.arakhne.afc.references.PhantomValueHashMap<K,V>
-
- Type Parameters:
K
- is the type of the keys.V
- is the type of the values.
- All Implemented Interfaces:
Map<K,V>
public class PhantomValueHashMap<K,V> extends AbstractPhantomValueMap<K,V>
A Map implementation withphantom values
. An entry in a PhantomValueHashMap will automatically be removed when its value is no longer in ordinary use or null.This class was inspirated from
WeakHashMap
and uses aHashMap
as its internal data structure.This class has a special flag which permits to control the way how the released references are expurged:
AbstractReferencedValueMap.isDeeplyExpurge()
,AbstractReferencedValueMap.setDeeplyExpurge(boolean)
. If this flag istrue
, all the released references will be immediately removed from the map even if they are not enqueued by the virtual machine (seeAbstractReferencedValueMap.expurge()
. If this flag isfalse
, only the enqueued references will be removed from the map (seeAbstractReferencedValueMap.expurgeQueuedReferences()
.If this map does not use a "deep expurge" of the released references, it could contains
null
values that corresponds to values that are released by the garbage collector. If a "deep expurge" is used, all the values released by the garbage collector will be removed from the map."Deep expurge" consumes much more time that "No deep expurge". This is the reason why this feature is not activated by default.
The "deep expurge" feature was added to fix the uncoherent behavior of the garbage collector which seems to not always enqueued the released values (sometimes the queue is empty even if a value was released).
- Since:
- 5.8
- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- references
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.arakhne.afc.references.AbstractReferencedValueMap
AbstractReferencedValueMap.PhantomReferencedValue<VKT,VVT>, AbstractReferencedValueMap.ReferencableValue<K,V>, AbstractReferencedValueMap.SoftReferencedValue<VKT,VVT>, AbstractReferencedValueMap.WeakReferencedValue<VKT,VVT>
-
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 inherited from class org.arakhne.afc.references.AbstractReferencedValueMap
map, NULL_VALUE
-
-
Constructor Summary
Constructors Constructor Description PhantomValueHashMap()
Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).PhantomValueHashMap(int initialCapacity)
Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).PhantomValueHashMap(int initialCapacity, float loadFactor)
Constructs an empty HashMap with the specified initial capacity and load factor.PhantomValueHashMap(Map<? extends K,? extends V> map)
Constructs a new HashMap with the same mappings as the specified Map.
-
Method Summary
-
Methods inherited from class org.arakhne.afc.references.AbstractPhantomValueMap
makeValue
-
Methods inherited from class org.arakhne.afc.references.AbstractReferencedValueMap
entrySet, equals, expurge, expurgeNow, expurgeQueuedReferences, finishToArray, hashCode, isDeeplyExpurge, makeValue, maskNull, put, setDeeplyExpurge, unmaskNull
-
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, get, isEmpty, keySet, putAll, remove, size, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
PhantomValueHashMap
public PhantomValueHashMap(int initialCapacity, float loadFactor)
Constructs an empty HashMap with the specified initial capacity and load factor.- Parameters:
initialCapacity
- the initial capacityloadFactor
- the load factor- Throws:
IllegalArgumentException
- if the initial capacity is negative or the load factor is nonpositive
-
PhantomValueHashMap
public PhantomValueHashMap(int initialCapacity)
Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).- Parameters:
initialCapacity
- the initial capacity.- Throws:
IllegalArgumentException
- if the initial capacity is negative.
-
PhantomValueHashMap
public PhantomValueHashMap()
Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).
-
PhantomValueHashMap
public PhantomValueHashMap(Map<? extends K,? extends V> map)
Constructs a new HashMap with the same mappings as the specified Map. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified Map.- Parameters:
map
- the map whose mappings are to be placed in this map- Throws:
NullPointerException
- if the specified map is null
-
-