|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.util.WeakIdentityCache<K,V>
public class WeakIdentityCache<K,V>
This class is not unsimiliar to the Map interface. It provides methods for
fast storing and retrieving object with a key, based on hashes and key/value
pairs. However there are some important distinctions from a normal HashMap.
Keys are not compared using object-equality but using reference-equality.
This means you can only use the original object to retrieve any values from
this cache. It also means the equals() method of your key is never used.
This allows system identy hashes to be used instead of normal hashes, which
means the potentially slow hashCode() method of your objects (eg. Buffer
objects) are never used.
Finally, the key itself is stored through a WeakReference. Once the key
object becomes weakly referable, this reference will be added to the internal
ReferenceQueue of this cache. This queue is polled everytime when any of the
methods of this are invoked. After the reference is polled the key/value pair
is removed from the map, and both key and value can be collected. (In case of
the value, if no other references to it exist)
This is an implementation from scratch, but some of the concepts came from
other implementations, most notably WeakIdenityHashMap from the jBoss
project.
NOTE: this implementation is not synchronized.
Constructor Summary | |
---|---|
WeakIdentityCache()
Create a new WeakIdenityCache (see main javadoc entry for this class) |
Method Summary | |
---|---|
void |
clear()
Clear the cache of all entries it has. |
void |
expunge()
Removes all key/value pairs from keys who've become weakly reachable from this cache. |
V |
get(K key)
Returns value for this key. |
V |
put(K key,
V value)
Put a value in this cache with key. |
V |
remove(K key)
Removes the value for this key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WeakIdentityCache()
Method Detail |
---|
public V get(K key)
public V put(K key, V value)
public V remove(K key)
public void clear()
public void expunge()
ReferenceQueue.poll()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |