Package de.alpharogroup.collections.set
Class InsertionOrderSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- java.util.HashSet<E>
-
- java.util.LinkedHashSet<E>
-
- de.alpharogroup.collections.set.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 classInsertionOrderSetoverwrites 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 booleanadd(E o)Adds the specified object to this set.static <E> java.util.Set<E>setOf(E... elements)Factory method for create anInsertionOrderSetwith the given elements.-
Methods inherited from class java.util.HashSet
clear, clone, contains, isEmpty, iterator, remove, size
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
-
-
-
-
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 anInsertionOrderSetwith the given elements.- Type Parameters:
E- the generic type of the elements- Parameters:
elements- The given elements.- Returns:
- a new
InsertionOrderSetthat 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.
-
-