com.go.trove.util
Class UsageSet

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractSet
              |
              +--com.go.trove.util.MapBackedSet
                    |
                    +--com.go.trove.util.UsageSet
All Implemented Interfaces:
java.util.Collection, java.io.Serializable, java.util.Set

public class UsageSet
extends MapBackedSet

A Set that orders its elements based on how recently they have been used. Most recently used elements appear first in the Set. Elements are marked as being used whenever they are added to the Set. To re-position an element, re-add it.

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

Fields inherited from class com.go.trove.util.MapBackedSet
mMap
 
Constructor Summary
UsageSet()
          Creates a UsageSet in forward order, MRU first.
UsageSet(java.util.Map backingMap)
           
 
Method Summary
 java.lang.Object first()
          Returns the first element in the set, the most recently used.
 java.lang.Object last()
          Returns the last element in the set, the least recently used.
 void setReverseOrder(boolean reverse)
          With reverse order, elements are ordered least recently used first.
 
Methods inherited from class com.go.trove.util.MapBackedSet
add, clear, contains, isEmpty, iterator, remove, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, retainAll, toArray, toArray
 

Constructor Detail

UsageSet

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

UsageSet

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

setReverseOrder

public void setReverseOrder(boolean reverse)
With reverse order, elements are ordered least recently used first. The ordering of the elements will be consistent with the order they were added in. Switching to and from reverse order is performed quickly and is not affected by the current size of the set.

first

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

last

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