java.lang.Object | ||
↳ | org.apache.commons.collections.SequencedHashMap | |
↳ | org.apache.commons.collections.LRUMap |
This class is deprecated.
Moved to map subpackage. Due to be removed in v4.0.
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().
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Default constructor, primarily for the purpose of
de-externalization.
| |||||||||||
Create a new LRUMap with a maximum capacity of i.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Get the value for a key from the Map. | |||||||||||
Getter for property maximumSize.
| |||||||||||
Removes the key and its Object from the Map. | |||||||||||
Deserializes this map from the given stream.
| |||||||||||
Setter for property maximumSize.
| |||||||||||
Serializes this map to the given stream.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Subclasses of LRUMap may hook into this method to
provide specialized actions whenever an Object is
automatically removed from the cache.
| |||||||||||
This method is used internally by the class for
finding and removing the LRU Object.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.SequencedHashMap
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.io.Externalizable
| |||||||||||
From interface
java.util.Map
|
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.
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 .
i | Maximum capacity of the LRUMap |
---|
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.
key | Key to retrieve |
---|
Getter for property maximumSize.
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.)
key | Key of the Object to add. |
---|---|
value | Object to add |
Deserializes this map from the given stream.
in | the stream to deserialize from |
---|
Setter for property maximumSize.
maximumSize | New value of property maximumSize. |
---|
Serializes this map to the given stream.
out | the stream to serialize to |
---|
IOException |
---|
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.
key | key that was removed |
---|---|
value | value of that key (can be null) |
This method is used internally by the class for finding and removing the LRU Object.