com.go.trove.util
Class UsageMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--com.go.trove.util.UsageMap
All Implemented Interfaces:
java.util.Map, java.io.Serializable

public class UsageMap
extends java.util.AbstractMap
implements java.io.Serializable

A Map that orders its keys based on how recently they have been used. Most recently used keys appear first in the Map. Keys are marked as being used whenever they are put into to the Map. To re-position a key, put it back in.

Version:
15 , 9/07/00
Author:
Brian S O'Neill
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
UsageMap()
          Creates a UsageMap in forward order, MRU first.
UsageMap(java.util.Map backingMap)
           
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 java.util.Set entrySet()
           
 java.lang.Object firstKey()
          Returns the first key in the map, the most recently used.
 java.lang.Object get(java.lang.Object key)
           
 boolean isEmpty()
           
 java.lang.Object lastKey()
          Returns the last key in the map, the least recently used.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map map)
           
 java.lang.Object remove(java.lang.Object key)
           
 void setReverseOrder(boolean reverse)
          With reverse order, keys are ordered least recently used first.
 int size()
           
 
Methods inherited from class java.util.AbstractMap
containsValue, equals, hashCode, keySet, toString, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UsageMap

public UsageMap()
Creates a UsageMap in forward order, MRU first.

UsageMap

public UsageMap(java.util.Map backingMap)
Parameters:
backingMap - map to use for storage
Method Detail

setReverseOrder

public void setReverseOrder(boolean reverse)
With reverse order, keys are ordered least recently used first. The ordering of the map entries will be consistent with the order they were put into it. Switching to and from reverse order is performed quickly and is not affected by the current size of the map.

firstKey

public java.lang.Object firstKey()
                          throws java.util.NoSuchElementException
Returns the first key in the map, the most recently used. If reverse order, then the least recently used is returned.

lastKey

public java.lang.Object lastKey()
                         throws java.util.NoSuchElementException
Returns the last key in the map, the least recently used. If reverse order, then the most recently used is returned.

size

public int size()
Overrides:
size in class java.util.AbstractMap

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class java.util.AbstractMap

containsKey

public boolean containsKey(java.lang.Object key)
Overrides:
containsKey in class java.util.AbstractMap

get

public java.lang.Object get(java.lang.Object key)
Overrides:
get in class java.util.AbstractMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Overrides:
put in class java.util.AbstractMap

remove

public java.lang.Object remove(java.lang.Object key)
Overrides:
remove in class java.util.AbstractMap

putAll

public void putAll(java.util.Map map)
Overrides:
putAll in class java.util.AbstractMap

clear

public void clear()
Overrides:
clear in class java.util.AbstractMap

entrySet

public java.util.Set entrySet()
Overrides:
entrySet in class java.util.AbstractMap