org.apache.commons.collections
Class LRUMap
java.lang.Object
|
+--java.util.AbstractMap
|
+--java.util.HashMap
|
+--org.apache.commons.collections.LRUMap
- All Implemented Interfaces:
- Cloneable, Externalizable, Map, Serializable
- public class LRUMap
- extends HashMap
- implements 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.
This implementation uses a simple bubbling
algorithm, whereby every random access get() method call bubbles the item
up the list, further away from the 'drop zone'.
A synchronized version can be obtained with:
Collections.synchronizedMap( theMapToSynchronize )
WARNING the values() and entrySet() methods require optimisation
like the standard HashMap
implementations so that iteration
over this Map is efficient.
- Author:
- James Strachan
- See Also:
- Serialized Form
LRUMap
public LRUMap()
LRUMap
public LRUMap(int i)
containsKey
public boolean containsKey(Object key)
- Overrides:
containsKey
in class HashMap
containsValue
public boolean containsValue(Object value)
- Overrides:
containsValue
in class HashMap
entrySet
public Set entrySet()
- Overrides:
entrySet
in class HashMap
get
public Object get(Object key)
- Overrides:
get
in class HashMap
getMaximumSize
public int getMaximumSize()
- Getter for property maximumSize.
- Returns:
- Value of property maximumSize.
keySet
public Set keySet()
- Overrides:
keySet
in class HashMap
put
public Object put(Object key,
Object value)
- Overrides:
put
in class HashMap
readExternal
public void readExternal(ObjectInput in)
throws IOException,
ClassNotFoundException
- Specified by:
readExternal
in interface Externalizable
remove
public Object remove(Object key)
- Overrides:
remove
in class HashMap
removeLRU
public Object removeLRU()
- Removes the least recently used object from the Map.
- Returns:
- the key of the removed item
setMaximumSize
public void setMaximumSize(int maximumSize)
- Setter for property maximumSize.
- Parameters:
maximumSize
- New value of property maximumSize.
values
public Collection values()
- Overrides:
values
in class HashMap
writeExternal
public void writeExternal(ObjectOutput out)
throws IOException
- Specified by:
writeExternal
in interface Externalizable
Copyright © 2001 Apache Software Foundation. Documenation generated July 14 2001.