Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.axis.collections
Class LRUMap  view LRUMap download LRUMap.java

java.lang.Object
  extended byorg.apache.axis.collections.SequencedHashMap
      extended byorg.apache.axis.collections.LRUMap
All Implemented Interfaces:
java.lang.Cloneable, java.io.Externalizable, java.util.Map, java.io.Serializable

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().

Since:
Commons Collections 1.0

Nested Class Summary
 
Nested classes inherited from class org.apache.axis.collections.SequencedHashMap
 
Field Summary
private  int maximumSize
           
private static long serialVersionUID
           
 
Fields inherited from class org.apache.axis.collections.SequencedHashMap
 
Constructor Summary
LRUMap()
          Default constructor, primarily for the purpose of de-externalization.
LRUMap(int i)
          Create a new LRUMap with a maximum capacity of i.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Get the value for a key from the Map.
 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)
          Removes the key and its Object from the Map.
 void readExternal(java.io.ObjectInput in)
          This method restores an object's state by reading in the instance data for the object from the passed in stream.
protected  void removeLRU()
          This method is used internally by the class for finding and removing the LRU Object.
 void setMaximumSize(int maximumSize)
          Setter for property maximumSize.
 void writeExternal(java.io.ObjectOutput out)
          This method is responsible for writing the instance data of an object to the passed in stream.
 
Methods inherited from class org.apache.axis.collections.SequencedHashMap
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
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

maximumSize

private int maximumSize

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

LRUMap

public LRUMap()
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)
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 .

Method Detail

get

public 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.

Specified by:
get in interface java.util.Map
Overrides:
get in class SequencedHashMap

put

public 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.)

Specified by:
put in interface java.util.Map
Overrides:
put in class SequencedHashMap

removeLRU

protected void removeLRU()
This method is used internally by the class for finding and removing the LRU Object.


processRemovedLRU

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. By default, this method does nothing.


readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Description copied from interface: java.io.Externalizable
This method restores an object's state by reading in the instance data for the object from the passed in stream. Note that this stream is not a subclass of InputStream, but rather is a class that implements the ObjectInput interface. That interface provides a mechanism for reading in Java data types from a stream.

Note that this method must be compatible with writeExternal. It must read back the exact same types that were written by that method in the exact order they were written.

If this method needs to read back an object instance, then the class for that object must be found and loaded. If that operation fails, then this method throws a ClassNotFoundException

Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class SequencedHashMap

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Description copied from interface: java.io.Externalizable
This method is responsible for writing the instance data of an object to the passed in stream. Note that this stream is not a subclass of OutputStream, but rather is a class that implements the ObjectOutput interface. That interface provides a number of methods for writing Java data values to a stream.

Not that the implementation of this method must be coordinated with the implementation of readExternal.

Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class SequencedHashMap

getMaximumSize

public int getMaximumSize()
Getter for property maximumSize.


setMaximumSize

public void setMaximumSize(int maximumSize)
Setter for property maximumSize.