Class WeakKeyMap<K,V>
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, emptyWeakKeyMapwith the default initial capacity (16) and load factor (0.75).WeakKeyMap(int initialCapacity, float loadFactor) Constructs a new, emptyWeakKeyMapwith the given initial capacity and the given load factor. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(Object key) ReturnsTRUEif this map contains a mapping for the specified key.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.Associates the specified value with the specified key in this map.Removes the mapping for a key from this weak hash map if it is present.intsize()Returns the number of key-value mappings in this map.
-
Constructor Details
-
WeakKeyMap
public WeakKeyMap(int initialCapacity, float loadFactor) Constructs a new, emptyWeakKeyMapwith the given initial capacity and the given load factor.- Parameters:
initialCapacity- The initial capacity of theWeakKeyMaploadFactor- The load factor of theWeakKeyMap- Throws:
IllegalArgumentException- if the initial capacity is negative, or if the load factor is nonpositive.
-
WeakKeyMap
public WeakKeyMap()Constructs a new, emptyWeakKeyMapwith the default initial capacity (16) and load factor (0.75).
-
-
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, or
NULLif 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 == 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.- See Also:
-
containsKey
ReturnsTRUEif this map contains a mapping for the specified key.- Parameters:
key- The key whose presence in this map is to be tested- Returns:
TRUEif there is a mapping for key;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.- 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, or
NULLif there was no mapping for key. (ANULLreturn can also indicate that the map previously associatedNULLwith key.)
-
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 key k to value v such that
(key==null ? k==null : key == 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.
- Parameters:
key- key whose mapping is to be removed from the map- Returns:
- the previous value associated with key, or
NULLif there was no mapping for key
-