public class LRUMap extends SequencedHashMap implements java.io.Externalizable
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().
Constructor and Description |
---|
LRUMap()
Deprecated.
Default constructor, primarily for the purpose of
de-externalization.
|
LRUMap(int i)
Deprecated.
Create a new LRUMap with a maximum capacity of i.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
get(java.lang.Object key)
Deprecated.
Get the value for a key from the Map.
|
int |
getMaximumSize()
Deprecated.
Getter for property maximumSize.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Deprecated.
Removes the key and its Object from the Map.
|
void |
readExternal(java.io.ObjectInput in)
Deprecated.
Deserializes this map from the given stream.
|
void |
setMaximumSize(int maximumSize)
Deprecated.
Setter for property maximumSize.
|
void |
writeExternal(java.io.ObjectOutput out)
Deprecated.
Serializes this map to the given stream.
|
clear, clone, containsKey, containsValue, entrySet, equals, get, getFirst, getFirstKey, getFirstValue, getLast, getLastKey, getLastValue, getValue, hashCode, indexOf, isEmpty, iterator, keySet, lastIndexOf, putAll, remove, remove, sequence, size, toString, values
public LRUMap()
public LRUMap(int i)
i
- Maximum capacity of the LRUMappublic java.lang.Object get(java.lang.Object key)
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.
get
in interface java.util.Map
get
in class SequencedHashMap
key
- Key to retrievepublic java.lang.Object put(java.lang.Object key, java.lang.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. In that case, the removeLRU() method is called. See javadoc for removeLRU() for more details.)
put
in interface java.util.Map
put
in class SequencedHashMap
key
- Key of the Object to add.value
- Object to addpublic void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
SequencedHashMap
readExternal
in interface java.io.Externalizable
readExternal
in class SequencedHashMap
in
- the stream to deserialize fromjava.io.IOException
- if the stream raises itjava.lang.ClassNotFoundException
- if the stream raises itpublic void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
SequencedHashMap
writeExternal
in interface java.io.Externalizable
writeExternal
in class SequencedHashMap
out
- the stream to serialize tojava.io.IOException
- if the stream raises itpublic int getMaximumSize()
public void setMaximumSize(int maximumSize)
maximumSize
- New value of property maximumSize."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"