Package com.globalmentor.collections
Class PurgeOnWriteSoftValueHashMap<K,V>
java.lang.Object
com.globalmentor.collections.AbstractPurgeOnWriteReferenceValueMap<K,V,PurgeOnWriteSoftValueHashMap.SoftValueReference<K,V>>
com.globalmentor.collections.PurgeOnWriteSoftValueHashMap<K,V>
- Type Parameters:
K
- The type of key.V
- The type of value.
- All Implemented Interfaces:
Map<K,
V>
public class PurgeOnWriteSoftValueHashMap<K,V>
extends AbstractPurgeOnWriteReferenceValueMap<K,V,PurgeOnWriteSoftValueHashMap.SoftValueReference<K,V>>
A map that uses soft references to store map values. Values are only purged when map write operations occur.
null
values are not supported.- Author:
- Garret Wilson
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A soft reference that keeps track of the key with which a value was associated.Nested classes/interfaces inherited from class com.globalmentor.collections.AbstractPurgeOnWriteReferenceValueMap
AbstractPurgeOnWriteReferenceValueMap.Keyed<K>
-
Constructor Summary
ModifierConstructorDescriptionDefault constructor with a default initial capacity and load factor.PurgeOnWriteSoftValueHashMap
(int initialCapacity) Empty map constructor with the specified initial capacity and a default load factor.PurgeOnWriteSoftValueHashMap
(int initialCapacity, float loadFactor) Empty map constructor with the specified initial capacity and load factor.protected
Decorated map constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected PurgeOnWriteSoftValueHashMap.SoftValueReference<K,
V> createReference
(K key, V value, ReferenceQueue<V> referenceQueue) Creates the appropriate reference for associating the given value with the given key.Methods inherited from class com.globalmentor.collections.AbstractPurgeOnWriteReferenceValueMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, purge, purgeExcept, put, putAll, remove, size, values
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
PurgeOnWriteSoftValueHashMap
public PurgeOnWriteSoftValueHashMap(int initialCapacity, float loadFactor) Empty map constructor with the specified initial capacity and load factor.- Parameters:
initialCapacity
- The initial capacity.loadFactor
- The load factor.- Throws:
IllegalArgumentException
- if the initial capacity is negative or the load factor is nonpositive.
-
PurgeOnWriteSoftValueHashMap
public PurgeOnWriteSoftValueHashMap(int initialCapacity) Empty map constructor with the specified initial capacity and a default load factor.- Parameters:
initialCapacity
- The initial capacity.- Throws:
IllegalArgumentException
- if the initial capacity is negative or the load factor is nonpositive.
-
PurgeOnWriteSoftValueHashMap
public PurgeOnWriteSoftValueHashMap()Default constructor with a default initial capacity and load factor. -
PurgeOnWriteSoftValueHashMap
protected PurgeOnWriteSoftValueHashMap(Map<K, PurgeOnWriteSoftValueHashMap.SoftValueReference<K, V>> map) Decorated map constructor.- Parameters:
map
- The map to decorate.- Throws:
NullPointerException
- If the map isnull
.
-
-
Method Details
-
createReference
protected PurgeOnWriteSoftValueHashMap.SoftValueReference<K,V> createReference(K key, V value, ReferenceQueue<V> referenceQueue) Creates the appropriate reference for associating the given value with the given key. The reference will be registered with the given queue.- Specified by:
createReference
in classAbstractPurgeOnWriteReferenceValueMap<K,
V, PurgeOnWriteSoftValueHashMap.SoftValueReference<K, V>> - Parameters:
key
- The key with which the value is being associated.value
- The value to be stored.referenceQueue
- The queue with which the reference will be registered.- Returns:
- A reference to the given value that also indicates the key being used.
-