public class WeakValueHashMap<K,V> extends RefValueHashMap<K,V>
SoftValueHashMap
for a hash map with soft referenced values.
The behavior of this hashmap is that it is possible that a value is
null
because of garbage collection although
RefValueHashMap.containsKey(Object)
says that the associated key is defined.
It is able to handle null
keys and null
values.
The default constructors enable auto cleaning, which will automatically remove all dead values each time a dead value is detected, but there are also constructors accepting a boolean autoClean parameter which allow to switch this feature off.
Some invariances usually true for maps hold not here:
RefValueHashMap.containsValue(Object)
may return different results.
RefValueHashMap.containsKey(Object)
.
RefValueHashMap.keySet()
may
no longer be keys when used.
RefValueHashMap.put(Object, Object)
,
RefValueHashMap.putAll(java.util.Map)
and RefValueHashMap.get(Object)
methods, when expecting a null
return
on the latter even if a value was added before.SoftValueHashMap
Constructor and Description |
---|
WeakValueHashMap()
Constructs an empty WeakValueHashMap with the default initial
capacity (16) and the default load factor (0.75).
|
WeakValueHashMap(boolean autoClean)
Constructs an empty WeakValueHashMap with the default initial
capacity (16) and the default load factor (0.75).
|
WeakValueHashMap(boolean autoClean,
int initialCapacity)
Constructs an empty WeakValueHashMap with the specified initial
capacity and the default load factor (0.75).
|
WeakValueHashMap(boolean autoClean,
int initialCapacity,
float loadFactor)
Constructs an empty HashMap with the specified initial
capacity and load factor.
|
WeakValueHashMap(boolean autoClean,
java.util.Map<? extends K,? extends V> m)
Constructs a new HashMap with the same mappings as the
specified Map.
|
WeakValueHashMap(int initialCapacity)
Constructs an empty WeakValueHashMap with the specified initial
capacity and the default load factor (0.75).
|
WeakValueHashMap(int initialCapacity,
float loadFactor)
Constructs an empty HashMap with the specified initial
capacity and load factor.
|
WeakValueHashMap(java.util.Map<? extends K,? extends V> m)
Constructs a new HashMap with the same mappings as the
specified Map.
|
clear, containsKey, containsValue, entrySet, get, hasDeadValue, isEmpty, keySet, put, putAll, remove, removeDeadValues, size, values
public WeakValueHashMap()
public WeakValueHashMap(int initialCapacity)
initialCapacity
- the initial capacity.java.lang.IllegalArgumentException
- if the initial capacity is negative.public WeakValueHashMap(int initialCapacity, float loadFactor)
initialCapacity
- The initial capacity.loadFactor
- The load factor.java.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public WeakValueHashMap(@NotNull java.util.Map<? extends K,? extends V> m)
m
- the map whose mappings are to be placed in this map.java.lang.NullPointerException
- if the specified map is null.public WeakValueHashMap(boolean autoClean)
autoClean
- if true
call RefValueHashMap.removeDeadValues()
when finding a dead valuepublic WeakValueHashMap(boolean autoClean, int initialCapacity)
autoClean
- if true
call RefValueHashMap.removeDeadValues()
when finding a dead valueinitialCapacity
- the initial capacity.java.lang.IllegalArgumentException
- if the initial capacity is negative.public WeakValueHashMap(boolean autoClean, int initialCapacity, float loadFactor)
autoClean
- if true
call RefValueHashMap.removeDeadValues()
when finding a dead valueinitialCapacity
- The initial capacity.loadFactor
- The load factor.java.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public WeakValueHashMap(boolean autoClean, @NotNull java.util.Map<? extends K,? extends V> m)
autoClean
- if true
call RefValueHashMap.removeDeadValues()
when finding a dead valuem
- the map whose mappings are to be placed in this map.java.lang.NullPointerException
- if the specified map is null.