|
DODS 7.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.enhydra.dods.util.SequencedHashMap
org.enhydra.dods.util.LRUMap
public class LRUMap
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 Summary | |
---|---|
LRUMap()
Default constructor, primarily for the purpose of de-externalization. |
|
LRUMap(int maxSize)
Creates a new LRUMap with a maximum capacity of maxSize and with a default capacity (16) and load factor (0.75). |
|
LRUMap(int initialCapacity,
float loadFactor)
Create a new LRUMap with a default maximum capacity (0) and with the capacity initialCapacity and load factor loadFactor. |
|
LRUMap(int initialCapacity,
float loadFactor,
int maxSize)
Create a new LRUMap with a maximum capacity of maxSize and with the capacity initialCapacity and load factor loadFactor. |
|
LRUMap(java.util.Map m)
Create a new LRUMap with the same mappings as the specified map m. |
|
LRUMap(java.util.Map m,
int maxSize)
Create a new LRUMap with the same mappings as the specified map m. |
Method Summary | |
---|---|
boolean |
containsKey(java.lang.Object key)
Returns true if this LRUMap contains a mapping for the specified key. |
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this LRUMap, or null if the map contains no mapping for this key. |
int |
getMaximumSize()
Getter for property maximumSize. |
protected void |
processRemovedLRU(java.lang.Object key,
java.lang.Object value)
Subclasses of LRUMap may hook into this method to provide specialized actions whenever an Object is automatically removed from the cache. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this LRUMap. |
void |
putAll(java.util.Map t)
Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as per Map.putAll(Map) ). |
void |
readExternal(java.io.ObjectInput in)
Deserializes this map from the given stream. |
protected void |
removeLRU()
This method is used internally by the class for finding and removing the LRU Object. |
void |
setMaximumSize(int maxSize)
Setter for property maximumSize. |
void |
writeExternal(java.io.ObjectOutput out)
Serializes this map to the given stream. |
Methods inherited from class org.enhydra.dods.util.SequencedHashMap |
---|
clear, clone, containsValue, entrySet, equals, get, getFirst, getFirstKey, getFirstValue, getLast, getLastKey, getLastValue, getValue, hashCode, indexOf, isEmpty, iterator, keySet, lastIndexOf, remove, remove, sequence, size, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LRUMap()
public LRUMap(int maxSize)
maxSize
- Maximum capacity of the LRUMap.public LRUMap(int initialCapacity, float loadFactor)
initialCapacity
- The initial capacity.loadFactor
- The load factor.public LRUMap(int initialCapacity, float loadFactor, int maxSize)
initialCapacity
- The initial capacity.loadFactor
- The load factor.maxSize
- Maximum capacity of the LRUMap.public LRUMap(java.util.Map m)
m
- The map whose mappings are to be placed in this LRUMap.public LRUMap(java.util.Map m, int maxSize)
m
- The map whose mappings are to be placed in this LRUMap.maxSize
- Maximum capacity of the LRUMap.Method Detail |
---|
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in class SequencedHashMap
key
- The key whose presence in this LRUMap is to be tested.
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class SequencedHashMap
key
- Key to retrieve.
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
(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 with which the specified value is to be associated.value
- Value to be associated with the specified key.
public void putAll(java.util.Map t)
Map.putAll(Map)
). The order
in which the entries are added is determined by the iterator returned
from Map.entrySet()
for the specified map.
putAll
in interface java.util.Map
putAll
in class SequencedHashMap
t
- the mappings that should be added to this map.
java.lang.NullPointerException
- if t
is null
.protected void removeLRU()
protected void processRemovedLRU(java.lang.Object key, java.lang.Object value)
key
- Key that was removed.value
- Value of that key (can be null).public 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 from
java.io.IOException
- if the stream raises it
java.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 to
java.io.IOException
- if the stream raises itpublic int getMaximumSize()
public void setMaximumSize(int maxSize)
maxSize
- New value of property maximumSize.
|
DODS 7.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |