Package org.arakhne.afc.references
Class AbstractReferencedValueMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.arakhne.afc.references.AbstractReferencedValueMap<K,V>
-
- Type Parameters:
K
- is the type of the keys.V
- is the type of the values.
- All Implemented Interfaces:
Map<K,V>
- Direct Known Subclasses:
AbstractPhantomValueMap
,AbstractSoftValueMap
,AbstractWeakValueMap
public abstract class AbstractReferencedValueMap<K,V> extends AbstractMap<K,V>
A Map implementation with weak/soft values. An entry in a AbstractReferencedValueMap will automatically be removed when its value is no longer in ordinary use ornull
.This abstract implementation does not decide if the map is based on a tree or on a hashtable; it does not impose soft or weak references.
- 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 Modifier and Type Class Description protected static class
AbstractReferencedValueMap.PhantomReferencedValue<VKT,VVT>
Value stored in aAbstractReferencedValueMap
inside aPhantomReference
.protected static interface
AbstractReferencedValueMap.ReferencableValue<K,V>
This interface provides information about the pairs inside a map with weak/soft reference values.protected static class
AbstractReferencedValueMap.SoftReferencedValue<VKT,VVT>
Value stored in aAbstractReferencedValueMap
inside aSoftReference
.protected static class
AbstractReferencedValueMap.WeakReferencedValue<VKT,VVT>
Value stored in aAbstractReferencedValueMap
inside aWeakReference
.-
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 Map<K,AbstractReferencedValueMap.ReferencableValue<K,V>>
map
Internal map.protected static Object
NULL_VALUE
Defines the NULL object inside a WeakValueMap.
-
Constructor Summary
Constructors Constructor Description AbstractReferencedValueMap(Map<K,AbstractReferencedValueMap.ReferencableValue<K,V>> map)
Constructs an empty Map.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object obj)
void
expurge()
Clean the references that was released.protected void
expurgeNow()
Clean the references that was marked as released inside the queue.void
expurgeQueuedReferences()
Clean the references that was marked as released inside the queue.(package private) static <T> T[]
finishToArray(T[] array, Iterator<?> it)
Reallocates the array being used within toArray when the iterator returned more elements than expected, and finishes filling it from the iterator.int
hashCode()
boolean
isDeeplyExpurge()
Replies if this map expurge all the released references even if they are not enqueued by the virtual machine.protected AbstractReferencedValueMap.ReferencableValue<K,V>
makeValue(K key, V value)
Create a storage object that permits to put the specified elements inside this map.protected abstract AbstractReferencedValueMap.ReferencableValue<K,V>
makeValue(K key, V value, ReferenceQueue<V> refQueue)
Create a storage object that permits to put the specified elements inside this map.protected static <VALUET> VALUET
maskNull(VALUET value)
Mask the null values given by the used of this map.V
put(K key, V value)
boolean
setDeeplyExpurge(boolean deeplyExpurge)
Set if this map expurge all the released references even if they are not enqueued by the virtual machine.protected static <VALUET> VALUET
unmaskNull(VALUET value)
Unmask the null values given by the used of this map.-
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
-
-
-
-
Field Detail
-
NULL_VALUE
protected static final Object NULL_VALUE
Defines the NULL object inside a WeakValueMap.- See Also:
maskNull(Object)
-
map
protected final Map<K,AbstractReferencedValueMap.ReferencableValue<K,V>> map
Internal map.
-
-
Constructor Detail
-
AbstractReferencedValueMap
public AbstractReferencedValueMap(Map<K,AbstractReferencedValueMap.ReferencableValue<K,V>> map)
Constructs an empty Map.- Parameters:
map
- is the map instance to use to store the entries.- Throws:
IllegalArgumentException
- if the initial capacity is negative or the load factor is nonpositive
-
-
Method Detail
-
maskNull
@Pure protected static <VALUET> VALUET maskNull(VALUET value)
Mask the null values given by the used of this map.This method replaces the
null
value by the internal representationNULL_VALUE
.- Type Parameters:
VALUET
- is the type of the value.- Parameters:
value
- is the value given by the user of this map.- Returns:
- the internal representation of the value.
- See Also:
unmaskNull(Object)
-
unmaskNull
@Pure protected static <VALUET> VALUET unmaskNull(VALUET value)
Unmask the null values given by the used of this map.This method replaces the internal representation
NULL_VALUE
of null values by its user representationnull
.- Type Parameters:
VALUET
- is the type of the value.- Parameters:
value
- is the value given by the user of this map.- Returns:
- the internal representation of the value.
- See Also:
maskNull(Object)
-
finishToArray
static <T> T[] finishToArray(T[] array, Iterator<?> it)
Reallocates the array being used within toArray when the iterator returned more elements than expected, and finishes filling it from the iterator.- Type Parameters:
T
- the type of the elements in the array.- Parameters:
array
- the array, replete with previously stored elementsit
- the in-progress iterator over this collection- Returns:
- array containing the elements in the given array, plus any further elements returned by the iterator, trimmed to size
-
expurgeNow
protected final void expurgeNow()
Clean the references that was marked as released inside the queue.
-
isDeeplyExpurge
@Pure public final boolean isDeeplyExpurge()
Replies if this map expurge all the released references even if they are not enqueued by the virtual machine.- Returns:
true
is the values are deeply expurged when they are released from the moemory, otherwisefalse
.
-
setDeeplyExpurge
public final boolean setDeeplyExpurge(boolean deeplyExpurge)
Set if this map expurge all the released references even if they are not enqueued by the virtual machine.- Parameters:
deeplyExpurge
- must betrue
to expurge all the released values, otherwisefalse
to expurge only the enqueued values.- Returns:
- the old value of this flag
-
expurgeQueuedReferences
public final void expurgeQueuedReferences()
Clean the references that was marked as released inside the queue.
-
expurge
public final void expurge()
Clean the references that was released.
-
makeValue
protected abstract AbstractReferencedValueMap.ReferencableValue<K,V> makeValue(K key, V value, ReferenceQueue<V> refQueue)
Create a storage object that permits to put the specified elements inside this map.- Parameters:
key
- is the key associated to the valuevalue
- is the valuerefQueue
- is the reference queue to use- Returns:
- the new storage object
-
makeValue
protected final AbstractReferencedValueMap.ReferencableValue<K,V> makeValue(K key, V value)
Create a storage object that permits to put the specified elements inside this map.- Parameters:
key
- is the key associated to the valuevalue
- is the value- Returns:
- the new storage object
-
equals
@Pure public final boolean equals(Object obj)
-
-