Class OrderedHashSet<T>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>

    public class OrderedHashSet<T>
    extends java.util.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:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<T> elements
      Track the elements as they are added to the set
    • Constructor Summary

      Constructors 
      Constructor Description
      OrderedHashSet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T value)
      Add a value to list; keep in hashtable for consistency also; Key is object itself.
      void clear()  
      java.util.List<T> elements()
      Return the List holding list of table elements.
      T get​(int i)  
      java.util.Iterator<T> iterator()  
      boolean remove​(java.lang.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()  
      java.lang.Object[] toArray()  
      java.lang.String toString()  
      • Methods inherited from class java.util.LinkedHashSet

        spliterator
      • 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.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray
    • Field Detail

      • elements

        protected java.util.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​(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 java.util.Collection<T>
        Specified by:
        add in interface java.util.Set<T>
        Overrides:
        add in class java.util.HashSet<T>
      • remove

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

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
        Specified by:
        clear in interface java.util.Set<T>
        Overrides:
        clear in class java.util.HashSet<T>
      • elements

        public java.util.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 java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.Set<T>
        Overrides:
        iterator in class java.util.HashSet<T>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
        Overrides:
        toArray in class java.util.AbstractCollection<T>
      • size

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

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