com.go.trove.util
Class Cache

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--com.go.trove.util.SoftHashMap
              |
              +--com.go.trove.util.Cache
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map

public class Cache
extends SoftHashMap

Cache is a SoftHashMap that is guaranteed to have the most recently used entries available. Calling "get" or "put" updates the internal MRU list, but calling "containsKey" or "containsValue" will not.

Like its base class, Cache is not thread-safe and must be wrapped with Collections.synchronizedMap to be made thread-safe.

Version:
24 , 01/05/30
Author:
Brian S O'Neill

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
Cache(Cache cache)
          Piggyback this Cache onto another one in order for the map of recently used entries to be shared.
Cache(int maxRecent)
          Construct a Cache with an amount of recently used entries that are guaranteed to always be in the Cache.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key from this map if present.
 
Methods inherited from class com.go.trove.util.SoftHashMap
clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, size, toString, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
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

Cache

public Cache(int maxRecent)
Construct a Cache with an amount of recently used entries that are guaranteed to always be in the Cache.
Parameters:
maxRecent - maximum amount of recently used entries guaranteed to be in the Cache.
Throws:
java.lang.IllegalArgumentException - if maxRecent is less than or equal to zero.

Cache

public Cache(Cache cache)
Piggyback this Cache onto another one in order for the map of recently used entries to be shared. If this Cache is more active than the one it attaches to, then more of its most recently used entries will be guaranteed to be in the Cache, possibly bumping out entries from the other Cache.
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Description copied from class: SoftHashMap
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.
Overrides:
get in class SoftHashMap
Following copied from class: com.go.trove.util.SoftHashMap
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from class: SoftHashMap
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.
Overrides:
put in class SoftHashMap
Following copied from class: com.go.trove.util.SoftHashMap
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the HashMap previously associated null with the specified key.

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from class: SoftHashMap
Removes the mapping for this key from this map if present.
Overrides:
remove in class SoftHashMap
Following copied from class: com.go.trove.util.SoftHashMap
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.

clear

public void clear()
Description copied from class: SoftHashMap
Removes all mappings from this map.
Overrides:
clear in class SoftHashMap