com.tensegrity.generic.util
Class StableHashSet

java.lang.Object
  extended bycom.tensegrity.generic.util.StableHashSet
All Implemented Interfaces:
java.util.Collection, java.util.Set

public final class StableHashSet
extends java.lang.Object
implements java.util.Set

This version of a HashSet keeps the order of its elements. This is different from the original Java 1.3 HashSet that imposes no order on its elements.

The order of the values in the StableHashSet is stable and does not change throughout the lifetime of the set.

The class also allows to remove a value from the order and bring it to front or to the back of the order in linear time. Methods for reordering are reorderToBack(Object) and reorderToFront(Object).

Version:
$Id: StableHashSet.java,v 1.13 2005/11/25 11:04:00 MichaelKegel Exp $
Author:
S.Rutz

Constructor Summary
StableHashSet()
          Constructs a new empty StableHashSet.
StableHashSet(java.util.Collection collection)
          Constructs a empty StableHashSet filled with the item from the passed Collection.
StableHashSet(int initialCapacity)
          Constructs a new empty StableHashSet with the given initial capacity.
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 boolean reorderToBack(java.lang.Object key)
          Brings the object with the associated key to the end of the internal order.
 boolean reorderToFront(java.lang.Object key)
          Brings the object with the associated key to the beginning of the internal order.
 boolean retainAll(java.util.Collection c)
           
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

StableHashSet

public StableHashSet()
Constructs a new empty StableHashSet.


StableHashSet

public StableHashSet(int initialCapacity)
Constructs a new empty StableHashSet with the given initial capacity.

Parameters:
initialCapacity - the initial capacity of this StableHashSet instance.

StableHashSet

public StableHashSet(java.util.Collection collection)
Constructs a empty StableHashSet filled with the item from the passed Collection.

Parameters:
collection - initial items.
Method Detail

reorderToFront

public boolean reorderToFront(java.lang.Object key)
Brings the object with the associated key to the beginning of the internal order.

Parameters:
key - the key that identifies the element to reorder.
Returns:
true if the object was found and thus reordered. True is also returned if the object was at the beginning of the order.

reorderToBack

public boolean reorderToBack(java.lang.Object key)
Brings the object with the associated key to the end of the internal order.

Parameters:
key - the key that identifies the element to reorder.
Returns:
true if the object was found and reordered. True is also returned if the object was at the end of the order.

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Set

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Set

clear

public void clear()
Specified by:
clear in interface java.util.Set

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Set

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Set

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Set

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.util.Set

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Set

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Set

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Set

size

public int size()
Specified by:
size in interface java.util.Set

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Set


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.