|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
org.ow2.bonita.util.WeakValueMap<K,V>
K
- Key typeV
- Value typepublic class WeakValueMap<K,V>
A map implementation with weak values.
An entry in a WeakValueMap will automatically be removed when its value is no longer in ordinary use. More precisely, the presence of a mapping for a given value will not prevent the value from being discarded by the garbage collector, that is, made finalizable, finalized, and then reclaimed. When a value has been discarded its entry is effectively removed from the map, so this class behaves somewhat differently than other Map implementations.
Both null
values and the null
key are
supported.
This class is intended primarily for use with value objects whose equals methods test for object identity using the == operator.
The behavior of the WeakValueMap class depends in part upon the actions of the garbage collector, so several familiar (though not required) Map invariants do not hold for this class. Because the garbage collector may discard values at any time, a WeakValueMap may behave as though an unknown thread is silently removing entries. In particular, even if you synchronize on a WeakValueMap instance and invoke none of its mutator methods, it is possible for the size method to return smaller values over time, for the isEmpty method to return false and then true, for the containsValue method to return true and later false for a given value, for the get method to return a value for a given key but later return null, for the put method to return null and the remove method to return false for a key that previously appeared to be in the map, and for successive examinations of the key set, the value set, and the entry set to yield successively smaller numbers of elements.
Each value object in a WeakValueMap is stored indirectly as the referent of a weak reference. Therefore a value will automatically be removed only after the weak references to it, both inside and outside of the map, have been cleared by the garbage collector.
This class implementation has been highly inspired on the SoftHashMap implementation by Dr. Heinz Kabutz.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
WeakValueMap(java.lang.Class<? extends java.util.Map> mapType)
Create a WeakValue map instance backed by a Map of the given type. |
Method Summary | |
---|---|
void |
clear()
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
|
V |
get(java.lang.Object key)
|
V |
put(K key,
V value)
Here we put the key, value pair into the Map using a WeakValue object. |
V |
remove(java.lang.Object key)
|
int |
size()
|
Methods inherited from class java.util.AbstractMap |
---|
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public WeakValueMap(java.lang.Class<? extends java.util.Map> mapType)
Create a WeakValue map instance backed by a Map of the given type.
mapType
- the type of the real map to useMethod Detail |
---|
public V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
get
in class java.util.AbstractMap<K,V>
public V put(K key, V value)
put
in interface java.util.Map<K,V>
put
in class java.util.AbstractMap<K,V>
public V remove(java.lang.Object key)
remove
in interface java.util.Map<K,V>
remove
in class java.util.AbstractMap<K,V>
public void clear()
clear
in interface java.util.Map<K,V>
clear
in class java.util.AbstractMap<K,V>
public int size()
size
in interface java.util.Map<K,V>
size
in class java.util.AbstractMap<K,V>
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
entrySet
in class java.util.AbstractMap<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |