Top Description Fields Constructors Methods
org.antlr.misc

public Class OrderedHashSet<T>

extends LinkedHashSet<T>
Class Inheritance
Imports
java.util.ArrayList, .Iterator, .LinkedHashSet, .List

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.

Field Summary

Modifier and TypeField and Description
protected List<T>
elements

Track the elements as they are added to the set

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
add(T
element to be added to this set
value
)

Overrides java.util.HashSet.add.

Implements java.util.Collection.add, java.util.Set.add.

Add a value to list; keep in hashtable for consistency also; Key is object itself.
public void
clear()

Overrides java.util.HashSet.clear.

Implements java.util.Collection.clear, java.util.Set.clear.

Removes all of the elements from this set (optional operation).
public List<T>
elements()

Return the List holding list of table elements.

public T
get(int i)

public Iterator<T>
iterator()

Overrides java.util.HashSet.iterator.

Implements java.util.Collection.iterator, java.util.Set.iterator.

Returns an iterator over the elements in this set.
public boolean
remove(Object
object to be removed from this set, if present
o
)

Overrides java.util.HashSet.remove.

Implements java.util.Collection.remove, java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation).
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.

public int
size()

Overrides java.util.HashSet.size.

Implements java.util.Collection.size, java.util.Set.size.

Returns the number of elements in this set (its cardinality).
public Object[]
toArray()

Overrides java.util.HashSet.toArray.

Implements java.util.Collection.toArray, java.util.Set.toArray.

Returns an array containing all of the elements in this set.
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.
Inherited from java.util.LinkedHashSet:
addFirstaddLastgetFirstgetLastnewLinkedHashSetremoveFirstremoveLastreversedspliterator

Field Detail

elementsback to summary
protected List<T> elements

Track the elements as they are added to the set

Constructor Detail

OrderedHashSetback to summary
public OrderedHashSet()

Method Detail

addback to summary
public boolean add(T value)

Overrides java.util.HashSet.add.

Implements java.util.Collection.add, java.util.Set.add.

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.

Parameters
value:T

Doc from java.util.Set.add.

element to be added to this set

Returns:boolean

Doc from java.util.Set.add.

true if this set did not already contain the specified element

Annotations
@Override
clearback to summary
public void clear()

Overrides java.util.HashSet.clear.

Implements java.util.Collection.clear, java.util.Set.clear.

Doc from java.util.Set.clear.

Removes all of the elements from this set (optional operation). The set will be empty after this call returns.

Annotations
@Override
elementsback to summary
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.

getback to summary
public T get(int i)
iteratorback to summary
public Iterator<T> iterator()

Overrides java.util.HashSet.iterator.

Implements java.util.Collection.iterator, java.util.Set.iterator.

Doc from java.util.Set.iterator.

Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).

Returns:Iterator<T>

an iterator over the elements in this set

Annotations
@Override
removeback to summary
public boolean remove(Object o)

Overrides java.util.HashSet.remove.

Implements java.util.Collection.remove, java.util.Set.remove.

Doc from java.util.Set.remove.

Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)

Parameters
o:Object

object to be removed from this set, if present

Returns:boolean

true if this set contained the specified element

Annotations
@Override
setback to summary
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.

sizeback to summary
public int size()

Overrides java.util.HashSet.size.

Implements java.util.Collection.size, java.util.Set.size.

Doc from java.util.Set.size.

Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this set (its cardinality)

Annotations
@Override
toArrayback to summary
public Object[] toArray()

Overrides java.util.HashSet.toArray.

Implements java.util.Collection.toArray, java.util.Set.toArray.

Doc from java.util.Set.toArray.

Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Returns:Object[]

an array containing all the elements in this set

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Doc from java.util.AbstractCollection.toString.

Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this collection

Annotations
@Override