| java.lang.Object org.apache.commons.collections.SequencedHashMap org.apache.commons.collections.LRUMap
LRUMap | public class LRUMap extends SequencedHashMap implements Externalizable(Code) | |
An implementation of a Map which has a maximum size and uses a Least Recently Used
algorithm to remove items from the Map when the maximum size is reached and new items are added.
A synchronized version can be obtained with:
Collections.synchronizedMap( theMapToSynchronize )
If it will be accessed by multiple threads, you _must_ synchronize access
to this Map. Even concurrent get(Object) operations produce indeterminate
behaviour.
Unlike the Collections 1.0 version, this version of LRUMap does use a true
LRU algorithm. The keys for all gets and puts are moved to the front of
the list. LRUMap is now a subclass of SequencedHashMap, and the "LRU"
key is now equivalent to LRUMap.getFirst().
since: Commons Collections 1.0 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: James Strachan author: Morgan Delagrange |
Constructor Summary | |
public | LRUMap() Default constructor, primarily for the purpose of
de-externalization. | public | LRUMap(int i) Create a new LRUMap with a maximum capacity of i.
Once i capacity is achieved, subsequent gets
and puts will push keys out of the map. |
Method Summary | |
public Object | get(Object key) Get the value for a key from the Map. | public int | getMaximumSize() Getter for property maximumSize. | protected void | processRemovedLRU(Object key, Object value) Subclasses of LRUMap may hook into this method to
provide specialized actions whenever an Object is
automatically removed from the cache. | public Object | put(Object key, Object value) Removes the key and its Object from the Map.
(Note: this may result in the "Least Recently Used"
object being removed from the Map. | public void | readExternal(ObjectInput in) | protected void | removeLRU() This method is used internally by the class for
finding and removing the LRU Object. | public void | setMaximumSize(int maximumSize) Setter for property maximumSize. | public void | writeExternal(ObjectOutput out) |
LRUMap | public LRUMap()(Code) | | Default constructor, primarily for the purpose of
de-externalization. This constructors sets a default
LRU limit of 100 keys, but this value may be overridden
internally as a result of de-externalization.
|
LRUMap | public LRUMap(int i)(Code) | | Create a new LRUMap with a maximum capacity of i.
Once i capacity is achieved, subsequent gets
and puts will push keys out of the map. See .
Parameters: i - Maximum capacity of the LRUMap |
get | public Object get(Object key)(Code) | | Get the value for a key from the Map. The key
will be promoted to the Most Recently Used position.
Note that get(Object) operations will modify
the underlying Collection. Calling get(Object)
inside of an iteration over keys, values, etc. is
currently unsupported.
Parameters: key - Key to retrieve Returns the value. Returns null if the key has anull value or if the key has no value. |
getMaximumSize | public int getMaximumSize()(Code) | | Getter for property maximumSize.
Value of property maximumSize. |
processRemovedLRU | protected void processRemovedLRU(Object key, Object value)(Code) | | Subclasses of LRUMap may hook into this method to
provide specialized actions whenever an Object is
automatically removed from the cache. By default,
this method does nothing.
Parameters: key - key that was removed Parameters: value - value of that key (can be null) |
put | public Object put(Object key, Object value)(Code) | | Removes the key and its Object from the Map.
(Note: this may result in the "Least Recently Used"
object being removed from the Map. In that case,
the removeLRU() method is called. See javadoc for
removeLRU() for more details.)
Parameters: key - Key of the Object to add. Parameters: value - Object to add Former value of the key |
removeLRU | protected void removeLRU()(Code) | | This method is used internally by the class for
finding and removing the LRU Object.
|
setMaximumSize | public void setMaximumSize(int maximumSize)(Code) | | Setter for property maximumSize.
Parameters: maximumSize - New value of property maximumSize. |
|
|