av.util
Class RefValueMap<K,V>
java.lang.Object
av.util.RefValueMap<K,V>
- Type Parameters:
K - Type of keysV - Type of values
- All Implemented Interfaces:
- Serializable, Cloneable, Iterable<V>
- Direct Known Subclasses:
- SoftValueMap, WeakValueMap
public abstract class RefValueMap<K,V>
- extends Object
- implements Iterable<V>, Cloneable, Serializable
This is the abstract base class for mem sensitive maps those do not prevent
the values from being garbage collected.
As WeakHashMap is implemented with weak keys,
it will not prevent the key from being discarded by the garbage collector. A
WeakHashMap is useful in many cases but it doesn't cover
the case that keys are constants like ( i.e. primitives and interned strings ),
while the values should be garbage collectable while no strong references to
them were held anymore. In these particular cases using a
WeakHashMap is either unexpectable or has no advantage at
all -- Boxed up primitives may be too soon discarded while interned strings
are almost never garbage collected. This class and its subclasses are here to
fill this vacancy.
This class and its subclasses are implemented with a synchronized
HashMap in the back.
- Author:
- Compl
- See Also:
WeakValueMap,
SoftValueMap,
Serialized Form
RefValueMap
public RefValueMap(int initialCapacity,
float loadFactor)
RefValueMap
public RefValueMap(int initialCapacity)
RefValueMap
public RefValueMap()
createReference
protected abstract Reference<V> createReference(V v)
hashCode
public int hashCode()
- Overrides:
hashCode in class Object
equals
public boolean equals(Object o)
- Overrides:
equals in class Object
clone
public RefValueMap<K,V> clone()
throws CloneNotSupportedException
- Overrides:
clone in class Object
- Throws:
CloneNotSupportedException
clear
public void clear()
put
public V put(K key,
V value)
putAll
public void putAll(Map<? extends K,? extends V> m)
remove
public V remove(Object key)
get
public V get(Object key)
iterator
public Iterator<V> iterator()
- Get an iterator over values stored in this map, if a value has been
cleared by java gc, it will not appear in the returned iteration.
- Specified by:
iterator in interface Iterable<V>
containsKey
public boolean containsKey(Object key)
- Note even this return
true for a given key,
null value may still be returned by calling
get(Object) or remove(Object) or
put(Object, Object) with it.
- Parameters:
key -
- Returns:
- if this map contains key
keySet
public Set<K> keySet()
- Note keys in the returned set may still get you
null
values when you invoke get(Object) or remove(Object) or
put(Object, Object) passing them.
- Returns:
- key set of this map
Copyright© 2006 Ableverse Platform. All rights reserved.