Class InsertionOrderSet<E>

  • Type Parameters:
    E - the generic type of elements maintained by this set
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>
    Direct Known Subclasses:
    IndexableSet

    public class InsertionOrderSet<E>
    extends java.util.LinkedHashSet<E>
    The class InsertionOrderSet overwrites the add-method from the LinkedHashSet. That inserts the value to the right order it was inserted in the Map. Note that the difference in the LinkedHashMap is the order does not change if we put the same key with a new value. In this class the order changes when we put a new value with the same key.
    See Also:
    LinkedHashSet, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      InsertionOrderSet()
      Constructs an empty insertion-ordered InsertionOrderSet instance with a default capacity (16) and load factor (0.75).
      InsertionOrderSet​(int initialCapacity)
      Constructs an empty insertion-ordered InsertionOrderSet instance with the specified initial capacity and a default load factor (0.75).
      InsertionOrderSet​(int initialCapacity, float loadFactor)
      Constructs an empty insertion-ordered InsertionOrderMap instance with the specified initial capacity and load factor.
      InsertionOrderSet​(java.util.Collection<? extends E> c)
      Constructs a new insertion order hash set with the same elements as the specified collection.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E o)
      Adds the specified object to this set.
      static <E> java.util.Set<E> setOf​(E... elements)
      Factory method for create an InsertionOrderSet with the given elements.
      • Methods inherited from class java.util.LinkedHashSet

        spliterator
      • Methods inherited from class java.util.HashSet

        clear, clone, contains, isEmpty, iterator, remove, size
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, retainAll, toArray, toArray, toString
      • 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, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
    • Constructor Detail

      • InsertionOrderSet

        public InsertionOrderSet()
        Constructs an empty insertion-ordered InsertionOrderSet instance with a default capacity (16) and load factor (0.75).
      • InsertionOrderSet

        public InsertionOrderSet​(java.util.Collection<? extends E> c)
        Constructs a new insertion order hash set with the same elements as the specified collection. The insertion order hash set is created with an initial capacity sufficient to hold the elements in the specified collection and the default load factor (0.75).
        Parameters:
        c - the collection whose elements are to be placed into this set.
        Throws:
        java.lang.NullPointerException - if the specified collection is null.
      • InsertionOrderSet

        public InsertionOrderSet​(int initialCapacity)
        Constructs an empty insertion-ordered InsertionOrderSet instance with the specified initial capacity and a default load factor (0.75).
        Parameters:
        initialCapacity - the initial capacity.
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is negative.
      • InsertionOrderSet

        public InsertionOrderSet​(int initialCapacity,
                                 float loadFactor)
        Constructs an empty insertion-ordered InsertionOrderMap instance with the specified initial capacity and load factor.
        Parameters:
        initialCapacity - the initial capacity.
        loadFactor - the load factor.
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive.
    • Method Detail

      • setOf

        public static <E> java.util.Set<E> setOf​(E... elements)
        Factory method for create an InsertionOrderSet with the given elements.
        Type Parameters:
        E - the generic type of the elements
        Parameters:
        elements - The given elements.
        Returns:
        a new InsertionOrderSet that contains the given elements.
      • add

        public boolean add​(E o)
        Adds the specified object to this set. If the set previously contained a the same object, the old object is removed and then insert again. That inserts the object to the right order it was inserted in the Set. Note that the difference in the LinkedHashSet is the order does not change if we try to add the same object. In this class the order changes when we add a object that allready exists.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.HashSet<E>
        Parameters:
        o - The object to add.
        Returns:
        true if the set did not already contain the specified element.