Package net.solarnetwork.util
Class WeakValueConcurrentHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
net.solarnetwork.util.WeakValueConcurrentHashMap<K,V>
- All Implemented Interfaces:
ConcurrentMap<K,,V> Map<K,V>
A
ConcurrentMap implementation with weak-referenced values.
The values stored in this map are only weakly-referenced. If a value is garbage collected, then the associated key will remain in this map, but methods that query for the value based on its key will return null.
- Version:
- 1.0
- Author:
- matt
-
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> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, empty map with the default initial table size (16).WeakValueConcurrentHashMap(int initialCapacity) Creates a new, empty map with an initial table size accommodating the specified number of elements without the need to dynamically resize.WeakValueConcurrentHashMap(int initialCapacity, float loadFactor) Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity) and initial table density (loadFactor).WeakValueConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity), table density (loadFactor), and number of concurrently updating threads (concurrencyLevel).WeakValueConcurrentHashMap(Map<? extends K, ? extends V> m) Creates a new map with the same mappings as the given map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanisEmpty()keySet()voidputIfAbsent(K key, V value) booleanbooleanintsize()Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.ConcurrentMap
forEach, getOrDefault, merge, replaceAll
-
Constructor Details
-
WeakValueConcurrentHashMap
public WeakValueConcurrentHashMap()Creates a new, empty map with the default initial table size (16). -
WeakValueConcurrentHashMap
public WeakValueConcurrentHashMap(int initialCapacity) Creates a new, empty map with an initial table size accommodating the specified number of elements without the need to dynamically resize.- Parameters:
initialCapacity- The implementation performs internal sizing to accommodate this many elements.- Throws:
IllegalArgumentException- if the initial capacity of elements is negative
-
WeakValueConcurrentHashMap
Creates a new map with the same mappings as the given map.- Parameters:
m- the map
-
WeakValueConcurrentHashMap
public WeakValueConcurrentHashMap(int initialCapacity, float loadFactor) Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity) and initial table density (loadFactor).- Parameters:
initialCapacity- the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor.loadFactor- the load factor (table density) for establishing the initial table size- Throws:
IllegalArgumentException- if the initial capacity of elements is negative or the load factor is nonpositive- Since:
- 1.6
-
WeakValueConcurrentHashMap
public WeakValueConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity), table density (loadFactor), and number of concurrently updating threads (concurrencyLevel).- Parameters:
initialCapacity- the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor.loadFactor- the load factor (table density) for establishing the initial table sizeconcurrencyLevel- the estimated number of concurrently updating threads. The implementation may use this value as a sizing hint.- Throws:
IllegalArgumentException- if the initial capacity is negative or the load factor or concurrencyLevel are nonpositive
-
-
Method Details
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V>
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V>
-
get
-
put
-
putAll
-
remove
-
clear
public void clear() -
putIfAbsent
- Specified by:
putIfAbsentin interfaceConcurrentMap<K,V> - Specified by:
putIfAbsentin interfaceMap<K,V>
-
remove
-
replace
-
replace
-
entrySet
-
size
public int size() -
isEmpty
public boolean isEmpty() -
keySet
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceConcurrentMap<K,V> - Specified by:
computeIfAbsentin interfaceMap<K,V>
-
computeIfPresent
- Specified by:
computeIfPresentin interfaceConcurrentMap<K,V> - Specified by:
computeIfPresentin interfaceMap<K,V>
-
compute
-