org.antlr.misc
Class OrderedHashSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet
              extended by org.antlr.misc.OrderedHashSet
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.Set

public class OrderedHashSet
extends java.util.HashSet

A HashMap that remembers the order that the elements were added. You can alter the ith element with set(i,value) too :) Unique list. I need the replace/set-element-i functionality so I'm subclassing OrderedHashSet.

See Also:
Serialized Form

Field Summary
protected  java.util.List elements
          Track the elements as they are added to the set
 
Constructor Summary
OrderedHashSet()
           
 
Method Summary
 boolean add(java.lang.Object value)
          Add a value to list; keep in hashtable for consistency also; Key is object itself.
 void clear()
           
 java.util.List elements()
          Return the List holding list of table elements.
 java.lang.Object get(int i)
           
 boolean remove(java.lang.Object o)
           
 java.lang.Object set(int i, java.lang.Object value)
          Replace an existing value with a new value; updates the element list and the hash table, but not the key as that has not changed.
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.HashSet
clone, contains, isEmpty, iterator
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Field Detail

elements

protected java.util.List elements
Track the elements as they are added to the set

Constructor Detail

OrderedHashSet

public OrderedHashSet()
Method Detail

get

public java.lang.Object get(int i)

set

public java.lang.Object set(int i,
                            java.lang.Object value)
Replace an existing value with a new value; updates the element list and the hash table, but not the key as that has not changed.


add

public boolean add(java.lang.Object value)
Add a value to list; keep in hashtable for consistency also; Key is object itself. Good for say asking if a certain string is in a list of strings.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.HashSet

remove

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

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set
Overrides:
clear in class java.util.HashSet

elements

public java.util.List elements()
Return the List holding list of table elements. Note that you are NOT getting a copy so don't write to the list.


size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Overrides:
size in class java.util.HashSet

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection