- All Implemented Interfaces:
Map<K,V>
-
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
ConstructorsConstructorDescriptionConstructs a new, emptyWeakIdentityHashMapwith the default initial capacity (16) and load factor (0.75).WeakIdentityHashMap(int initialCapacity) Constructs a new, emptyWeakIdentityHashMapwith the given initial capacity and the default load factor (0.75).WeakIdentityHashMap(int initialCapacity, float loadFactor) Constructs a new, emptyWeakIdentityHashMapwith the given initial capacity and the given load factor.WeakIdentityHashMap(Map<? extends K, ? extends V> m) Constructs a newWeakIdentityHashMapwith the same mappings as the specified map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all of the mappings 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 the specified value.entrySet()Returns aSetview of the mappings contained in this map.voidforEach(BiConsumer<? super K, ? super V> action) Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.booleanisEmpty()Returnstrueif this map contains no key-value mappings.keySet()Returns aSetview of the keys contained in this map.Associates the specified value with the specified key in this map.voidCopies all of the mappings from the specified map to this map.Removes the mapping for a key from this weak hash map if it is present.voidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) intsize()Returns the number of key-value mappings in this map.values()Returns aCollectionview of the values contained in this map.Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace
-
Constructor Details
-
WeakIdentityHashMap
public WeakIdentityHashMap(int initialCapacity, float loadFactor) Constructs a new, emptyWeakIdentityHashMapwith the given initial capacity and the given load factor.- Parameters:
initialCapacity- The initial capacity of theWeakIdentityHashMaploadFactor- The load factor of theWeakIdentityHashMap- Throws:
IllegalArgumentException- if the initial capacity is negative, or if the load factor is nonpositive.
-
WeakIdentityHashMap
public WeakIdentityHashMap(int initialCapacity) Constructs a new, emptyWeakIdentityHashMapwith the given initial capacity and the default load factor (0.75).- Parameters:
initialCapacity- The initial capacity of theWeakIdentityHashMap- Throws:
IllegalArgumentException- if the initial capacity is negative
-
WeakIdentityHashMap
public WeakIdentityHashMap()Constructs a new, emptyWeakIdentityHashMapwith the default initial capacity (16) and load factor (0.75). -
WeakIdentityHashMap
Constructs a newWeakIdentityHashMapwith the same mappings as the specified map. TheWeakIdentityHashMapis created with the default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified map.- Parameters:
m- the map whose mappings are to be placed in this map- Throws:
NullPointerException- if the specified map is null- Since:
- 1.3
-
-
Method Details
-
size
public int size()Returns the number of key-value mappings in this map. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced. -
isEmpty
public boolean isEmpty()Returnstrueif this map contains no key-value mappings. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced. -
get
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch that(key==null ? k==null : key.equals(k)), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)A return value of
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases. -
containsKey
Returnstrueif this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V> - Parameters:
key- The key whose presence in this map is to be tested- Returns:
trueif there is a mapping forkey;falseotherwise
-
put
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.- 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:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey.)
-
putAll
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.- Specified by:
putAllin interfaceMap<K,V> - Overrides:
putAllin classAbstractMap<K,V> - Parameters:
m- mappings to be stored in this map.- Throws:
NullPointerException- if the specified map is null.
-
remove
Removes the mapping for a key from this weak hash map if it is present. More formally, if this map contains a mapping from keykto valuevsuch that(key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key. A return value ofnulldoes not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key tonull.The map will not contain a mapping for the specified key once the call returns.
-
clear
public void clear()Removes all of the mappings from this map. The map will be empty after this call returns. -
containsValue
Returnstrueif this map maps one or more keys to the specified 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 the specified value
-
keySet
Returns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations. -
values
Returns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Collection.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations. -
entrySet
Returns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation, or through thesetValueoperation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations. -
forEach
-
replaceAll
- Specified by:
replaceAllin interfaceMap<K,V>
-