Package org.geotools.util
Class WeakValueHashMap<K,V>
Object
AbstractMap<K,V>
WeakValueHashMap<K,V>
- Type Parameters:
K- The class of key elements.V- The class of value elements.
- All Implemented Interfaces:
Map<K,V>
A hashtable-based
Map implementation with weak values. An entry in a WeakValueHashMap will
automatically be removed when its value is no longer in ordinary use. This class is similar to the standard
WeakHashMap class provided in J2SE, except that weak references are hold on values instead of keys.
The WeakValueHashMap class is thread-safe.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionCreates aWeakValueHashMap.WeakValueHashMap(int initialSize) Creates aWeakValueHashMapof the requested size and default load factor.WeakValueHashMap(Map<K, V> map) Creates a newWeakValueHashMappopulated with the contents of the provied map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all of the elements from this map.booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value) Returnstrueif this map maps one or more keys to this value.entrySet()Returns a set view of the mappings contained in this map.Returns the value to which this map maps the specified key.Associates the specified value with the specified key in this map.Removes the mapping for this key from this map if present.intsize()Returns the number of key-value mappings in this map.Methods inherited from class AbstractMap
clone, equals, hashCode, isEmpty, keySet, putAll, toString, valuesMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
WeakValueHashMap
public WeakValueHashMap()Creates aWeakValueHashMap. -
WeakValueHashMap
public WeakValueHashMap(int initialSize) Creates aWeakValueHashMapof the requested size and default load factor.- Parameters:
initialSize- The initial size.
-
WeakValueHashMap
Creates a newWeakValueHashMappopulated with the contents of the provied map.- Parameters:
map- Initial contents of theWeakValueHashMap.
-
-
Method Details
-
size
public int size()Returns the number of key-value mappings in this map. -
containsValue
Returnstrueif this map maps one or more keys to this value.- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V> - Parameters:
value- value whose presence in this map is to be tested.- Returns:
trueif this map maps one or more keys to this value.
-
containsKey
Returnstrueif this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V> - Parameters:
key- key whose presence in this map is to be tested.- Returns:
trueif this map contains a mapping for the specified key.- Throws:
NullPointerException- If key isnull.
-
get
Returns the value to which this map maps the specified key. Returnsnullif the map contains no mapping for this key.- Specified by:
getin interfaceMap<K,V> - Overrides:
getin classAbstractMap<K,V> - Parameters:
key- Key whose associated value is to be returned.- Returns:
- The value to which this map maps the specified key.
- Throws:
NullPointerException- if the key isnull.
-
put
Associates the specified value with the specified key in this map. The value is associated using aWeakReference.- Specified by:
putin interfaceMap<K,V> - Overrides:
putin classAbstractMap<K,V> - Parameters:
key- key with which the specified value is to be associated.value- value to be associated with the specified key.- Returns:
- previous value associated with specified key, or
nullif there was no mapping for key. - Throws:
NullPointerException- if the key or the value isnull.
-
remove
Removes the mapping for this key from this map if present. -
clear
public void clear()Removes all of the elements from this map. -
entrySet
Returns a set view of the mappings contained in this map. Each element in this set is aMap.Entry. The current implementation thrownUnsupportedOperationException.
-