Class WeakKeyMap<K,V>
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, emptyWeakKeyMap
with the default initial capacity (16) and load factor (0.75).WeakKeyMap
(int initialCapacity, float loadFactor) Constructs a new, emptyWeakKeyMap
with the given initial capacity and the given load factor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(Object key) ReturnsTRUE
if this map contains a mapping for the specified key.Returns the value to which the specified key is mapped, orNULL
if this map contains no mapping for the key.boolean
isEmpty()
ReturnsTRUE
if 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.int
size()
Returns the number of key-value mappings in this map.
-
Constructor Details
-
WeakKeyMap
public WeakKeyMap(int initialCapacity, float loadFactor) Constructs a new, emptyWeakKeyMap
with the given initial capacity and the given load factor.- Parameters:
initialCapacity
- The initial capacity of theWeakKeyMap
loadFactor
- 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, emptyWeakKeyMap
with 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()ReturnsTRUE
if 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
NULL
if this map contains no mapping for the key.More formally, if this map contains a mapping from a key
k
to a valuev
such 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
NULL
does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key toNULL
. ThecontainsKey
operation may be used to distinguish these two cases.- See Also:
-
containsKey
ReturnsTRUE
if this map contains a mapping for the specified key.- Parameters:
key
- The key whose presence in this map is to be tested- Returns:
TRUE
if there is a mapping for key;FALSE
otherwise
-
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
NULL
if there was no mapping for key. (ANULL
return can also indicate that the map previously associatedNULL
with 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
NULL
if the map contained no mapping for the key. A return value ofNULL
does 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
NULL
if there was no mapping for key
-