Class OrderedHashSet<T>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, SequencedCollection<T>, SequencedSet<T>, Set<T>

public class OrderedHashSet<T> extends LinkedHashSet<T>
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:
  • Field Details

    • elements

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

    • OrderedHashSet

      public OrderedHashSet()
  • Method Details

    • 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(T 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<T>
      Specified by:
      add in interface Set<T>
      Overrides:
      add in class HashSet<T>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface Set<T>
      Overrides:
      remove in class HashSet<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface Set<T>
      Overrides:
      clear in class HashSet<T>
    • 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 Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>
      Overrides:
      iterator in class HashSet<T>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
      Overrides:
      toArray in class HashSet<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface Set<T>
      Overrides:
      size in class HashSet<T>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<T>