Class SoftCache

  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by com.jniwrapper.util.SoftCache
All Implemented Interfaces:, java.lang.Cloneable, java.util.Map

public class SoftCache
extends java.util.HashMap

SoftCache is a Map that provides caching and retrieving of objects via SoftReference. Entries put in the cache are cleared when the value objects become unreachable.

See Also:
Serialized Form

Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
Constructor Summary
SoftCache(int initialCapacity)
Method Summary
 java.lang.Object get(java.lang.Object key)
          Looks for the key in the cache.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the passed key with the value via SoftReference.
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
equals, hashCode

Constructor Detail


public SoftCache(int initialCapacity)


public SoftCache()
Method Detail


public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the passed key with the value via SoftReference.

Specified by:
put in interface java.util.Map
put in class java.util.HashMap
key - a key with which the specified value is to be associated.
value - a value to be associated with the key.
previously associated value or null if there was no value associated, or if it became unreachable. A null value can also be returned, if it was previously associated with the key.


public java.lang.Object get(java.lang.Object key)
Looks for the key in the cache.

Specified by:
get in interface java.util.Map
get in class java.util.HashMap
key - a key for which the value should be returned.
a cached object or null if the entry for the passed key is missing, or if the value become unreachable, or if the null value was associated with the key.