Package javassist.scopedpool
Class SoftValueHashMap<K,V>
java.lang.Object
javassist.scopedpool.SoftValueHashMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
This Map will remove entries when the value in the map has been cleaned from
garbage collection
- Version:
$Revision: 1.4 $
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map
<K, SoftValueHashMap.SoftValueRef<K, V>> private ReferenceQueue
<V> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, emptyWeakHashMap
with the default initial capacity and the default load factor, which is0.75
.SoftValueHashMap
(int initialCapacity) Constructs a new, emptyWeakHashMap
with the given initial capacity and the default load factor, which is0.75
.SoftValueHashMap
(int initialCapacity, float loadFactor) Constructs a new, emptyWeakHashMap
with the given initial capacity and the given load factor.SoftValueHashMap
(Map<K, V> t) Constructs a newWeakHashMap
with the same mappings as the specifiedMap
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all mappings from this map.boolean
containsKey
(Object key) Returnstrue
if this map contains a mapping for the specified key.boolean
containsValue
(Object arg0) entrySet()
Returns a set of the mappings contained in this hash table.Returns the value to which this map maps the specifiedkey
.boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.keySet()
private void
Updates this map so that the givenkey
maps to the givenvalue
.void
Removes the mapping for the givenkey
from this map, if present.int
size()
Returns the number of key-value mappings in this map.private V
values()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
hash
-
queue
-
-
Constructor Details
-
SoftValueHashMap
public SoftValueHashMap(int initialCapacity, float loadFactor) Constructs a new, emptyWeakHashMap
with the given initial capacity and the given load factor.- Parameters:
initialCapacity
- The initial capacity of theWeakHashMap
loadFactor
- The load factor of theWeakHashMap
- Throws:
IllegalArgumentException
- If the initial capacity is less than zero, or if the load factor is nonpositive
-
SoftValueHashMap
public SoftValueHashMap(int initialCapacity) Constructs a new, emptyWeakHashMap
with the given initial capacity and the default load factor, which is0.75
.- Parameters:
initialCapacity
- The initial capacity of theWeakHashMap
- Throws:
IllegalArgumentException
- If the initial capacity is less than zero
-
SoftValueHashMap
public SoftValueHashMap()Constructs a new, emptyWeakHashMap
with the default initial capacity and the default load factor, which is0.75
. -
SoftValueHashMap
Constructs a newWeakHashMap
with the same mappings as the specifiedMap
. TheWeakHashMap
is created with an initial capacity of twice the number of mappings in the specified map or 11 (whichever is greater), and a default load factor, which is0.75
.- Parameters:
t
- the map whose mappings are to be placed in this map.
-
-
Method Details
-
entrySet
Returns a set of the mappings contained in this hash table. -
processQueue
private void processQueue() -
size
public int size()Returns the number of key-value mappings in this map. Note: In contrast with most implementations of theMap
interface, the time required by this operation is linear in the size of the map. -
isEmpty
public boolean isEmpty()Returnstrue
if this map contains no key-value mappings. -
containsKey
Returnstrue
if this map contains a mapping for the specified key.- Specified by:
containsKey
in interfaceMap<K,
V> - Parameters:
key
- The key whose presence in this map is to be tested.
-
get
Returns the value to which this map maps the specifiedkey
. If this map does not contain a value for this key, then returnnull
. -
put
Updates this map so that the givenkey
maps to the givenvalue
. If the map previously contained a mapping forkey
then that mapping is replaced and the previous value is returned. -
remove
Removes the mapping for the givenkey
from this map, if present. -
clear
public void clear()Removes all mappings from this map. -
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
keySet
-
putAll
-
values
-
valueOrNull
-