org.antlr.misc
Class OrderedHashSet<T>

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

public class OrderedHashSet<T>
extends LinkedHashSet

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  List<T> elements
          Track the elements as they are added to the set
 
Constructor Summary
OrderedHashSet()
           
 
Method Summary
 boolean add(Object value)
          Add a value to list; keep in hashtable for consistency also; Key is object itself.
 void clear()
           
 List<T> elements()
          Return the List holding list of table elements.
 T get(int i)
           
 Iterator<T> iterator()
           
 boolean remove(Object o)
           
 T set(int i, T 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()
           
 Object[] toArray()
           
 String toString()
           
 
Methods inherited from class java.util.HashSet
clone, contains, isEmpty
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray
 

Field Detail

elements

protected List<T> elements
Track the elements as they are added to the set

Constructor Detail

OrderedHashSet

public OrderedHashSet()
Method Detail

get

public T get(int i)

set

public T set(int i,
             T 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(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 Collection
Specified by:
add in interface Set
Overrides:
add in class HashSet

remove

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

clear

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

elements

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


iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface Set
Overrides:
iterator in class HashSet

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface Set
Overrides:
toArray in class AbstractCollection

size

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

toString

public String toString()
Overrides:
toString in class AbstractCollection


Copyright © 2011. All Rights Reserved.