net.sourceforge.jaulp.collections
Class InsertionOrderSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet<E>
              extended by java.util.LinkedHashSet<E>
                  extended by net.sourceforge.jaulp.collections.InsertionOrderSet<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

public class InsertionOrderSet<E>
extends java.util.LinkedHashSet<E>

This class overwrites the put-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.

Version:
1.0
Author:
Asterios Raptis
See Also:
LinkedHashSet, Serialized Form

Constructor Summary
InsertionOrderSet()
          Constructs an empty insertion-ordered InsertionOrderSet instance with a default capacity (16) and load factor (0.75).
InsertionOrderSet(java.util.Collection<? extends E> c)
          Constructs a new insertion order hash set with the same elements as the specified collection.
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.
 
Method Summary
 boolean add(E o)
          Adds the specified object to this set.
 
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.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

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.


Copyright © 2010. All Rights Reserved.