Package com.globalmentor.collections
Class PurgeOnWriteWeakValueHashMap<K,V>
- java.lang.Object
-
- com.globalmentor.collections.AbstractPurgeOnWriteReferenceValueMap<K,V,PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V>>
-
- com.globalmentor.collections.PurgeOnWriteWeakValueHashMap<K,V>
-
- Type Parameters:
K
- The type of key.V
- The type of value.
- All Implemented Interfaces:
java.util.Map<K,V>
public class PurgeOnWriteWeakValueHashMap<K,V> extends AbstractPurgeOnWriteReferenceValueMap<K,V,PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V>>
A map that uses weak 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
Nested Classes Modifier and Type Class Description static class
PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V>
A weak 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
Constructors Modifier Constructor Description PurgeOnWriteWeakValueHashMap()
Default constructor with a default initial capacity and load factor.PurgeOnWriteWeakValueHashMap(int initialCapacity)
Empty map constructor with the specified initial capacity and a default load factor.PurgeOnWriteWeakValueHashMap(int initialCapacity, float loadFactor)
Empty map constructor with the specified initial capacity and load factor.protected
PurgeOnWriteWeakValueHashMap(java.util.Map<K,PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V>> map)
Decorated map constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V>
createReference(K key, V value, java.lang.ref.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
-
-
-
-
Constructor Detail
-
PurgeOnWriteWeakValueHashMap
public PurgeOnWriteWeakValueHashMap(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:
java.lang.IllegalArgumentException
- if the initial capacity is negative or the load factor is nonpositive.
-
PurgeOnWriteWeakValueHashMap
public PurgeOnWriteWeakValueHashMap(int initialCapacity)
Empty map constructor with the specified initial capacity and a default load factor.- Parameters:
initialCapacity
- The initial capacity.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity is negative or the load factor is nonpositive.
-
PurgeOnWriteWeakValueHashMap
public PurgeOnWriteWeakValueHashMap()
Default constructor with a default initial capacity and load factor.
-
PurgeOnWriteWeakValueHashMap
protected PurgeOnWriteWeakValueHashMap(java.util.Map<K,PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V>> map)
Decorated map constructor.- Parameters:
map
- The map to decorate.- Throws:
java.lang.NullPointerException
- If the map is null.
-
-
Method Detail
-
createReference
protected PurgeOnWriteWeakValueHashMap.WeakValueReference<K,V> createReference(K key, V value, java.lang.ref.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,PurgeOnWriteWeakValueHashMap.WeakValueReference<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.
-
-