Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.collections
Class LRUMap

    java.lang.Object
      org.apache.commons.collections.SequencedHashMap
          org.apache.commons.collections.LRUMap

All Implemented Interfaces:
  java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.util.Map

Deprecated. Moved to map subpackage. Due to be removed in v4.0.

    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
Version:
  $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
Author:
  James Strachan, Morgan Delagrange
See Also:
  Serialized Form

Constructor Summary
`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.

Method Summary
`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.
`protected void` | `processRemovedLRU(java.lang.Object key, java.lang.Object value)` Deprecated. 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)` Deprecated. Removes the key and its Object from the Map.
`void` | `readExternal(java.io.ObjectInput in)` Deprecated. Deserializes this map from the given stream.
`protected void` | `removeLRU()` Deprecated. This method is used internally by the class for finding and removing the LRU Object.
`void` | `setMaximumSize(int maximumSize)` Deprecated. Setter for property maximumSize.
`void` | `writeExternal(java.io.ObjectOutput out)` Deprecated. Serializes this map to the given stream.

Methods inherited from class org.apache.commons.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`

Constructor Detail

### LRUMap

    public LRUMap()

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

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

  Parameters:
    `i` - Maximum capacity of the LRUMap

Method Detail

### get

    public java.lang.Object get(java.lang.Object key)

  Deprecated.

  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`
  Parameters:
    `key` - Key to retrieve
  Returns:
    Returns the value. Returns null if the key has a null value or if the key has no value.

### put

    public java.lang.Object put(java.lang.Object key,
                                java.lang.Object value)

  Deprecated.

  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`
  Parameters:
    `key` - Key of the Object to add.
    `value` - Object to add
  Returns:
    Former value of the key

### removeLRU

    protected void removeLRU()

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

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

  Parameters:
    `key` - key that was removed
    `value` - value of that key (can be null)

### readExternal

    public void readExternal(java.io.ObjectInput in)
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException

  Deprecated.
  Description copied from class: `SequencedHashMap`
  Deserializes this map from the given stream.

  Specified by:
    `readExternal` in interface `java.io.Externalizable`
  Overrides:
    `readExternal` in class `SequencedHashMap`
  Parameters:
    `in` - the stream to deserialize from
  Throws:
    `java.io.IOException` - if the stream raises it
    `java.lang.ClassNotFoundException` - if the stream raises it

### writeExternal

    public void writeExternal(java.io.ObjectOutput out)
                       throws java.io.IOException

  Deprecated.
  Description copied from class: `SequencedHashMap`
  Serializes this map to the given stream.

  Specified by:
    `writeExternal` in interface `java.io.Externalizable`
  Overrides:
    `writeExternal` in class `SequencedHashMap`
  Parameters:
    `out` - the stream to serialize to
  Throws:
    `java.io.IOException` - if the stream raises it

### getMaximumSize

    public int getMaximumSize()

  Deprecated.
  Getter for property maximumSize.

  Returns:
    Value of property maximumSize.

### setMaximumSize

    public void setMaximumSize(int maximumSize)

  Deprecated.
  Setter for property maximumSize.

  Parameters:
    `maximumSize` - New value of property maximumSize.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2008 The Apache Software Foundation. All Rights Reserved.