Ableverse™
Platform 6.0

av.util
Class RefValueMap<K,V>

java.lang.Object
  extended by av.util.RefValueMap<K,V>
Type Parameters:
K - Type of keys
V - 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

Nested Class Summary
protected  class RefValueMap.Itr
           
 
Constructor Summary
RefValueMap()
           
RefValueMap(int initialCapacity)
           
RefValueMap(int initialCapacity, float loadFactor)
           
 
Method Summary
 void clear()
           
 RefValueMap<K,V> clone()
           
 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.
protected abstract  Reference<V> createReference(V v)
           
 boolean equals(Object o)
           
 V get(Object key)
           
 int hashCode()
           
 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.
 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.
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> m)
           
 V remove(Object key)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RefValueMap

public RefValueMap(int initialCapacity,
                   float loadFactor)

RefValueMap

public RefValueMap(int initialCapacity)

RefValueMap

public RefValueMap()
Method Detail

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

Ableverse™
Platform 6.0

Copyright© 2006 Ableverse Platform. All rights reserved.