Class ListOrderedSet<E>

Type Parameters:
E - the type of the elements in this set
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Set<E>

Decorates another Set to ensure that the order of addition is retained and used by the iterator.

If an object is added to the set for a second time, it will remain in the original position in the iteration. The order can be observed from the set via the iterator or toArray methods.

The ListOrderedSet also has various useful direct methods. These include many from List, such as get(int), remove(int) and indexOf(int). An unmodifiable List view of the set can be obtained via asList().

This class cannot implement the List interface directly as various interface methods (notably equals/hashCode) are incompatible with a set.

This class is Serializable from Commons Collections 3.1.

Since:
3.0
See Also:
  • Constructor Details

    • ListOrderedSet

      public ListOrderedSet()
      Constructs a new empty ListOrderedSet using a HashSet and an ArrayList internally.
      Since:
      3.1
    • ListOrderedSet

      protected ListOrderedSet(Set<E> set)
      Constructor that wraps (not copies).
      Parameters:
      set - the set to decorate, must not be null
      Throws:
      NullPointerException - if set is null
    • ListOrderedSet

      protected ListOrderedSet(Set<E> set, List<E> list)
      Constructor that wraps (not copies) the Set and specifies the list to use.

      The set and list must both be correctly initialized to the same elements.

      Parameters:
      set - the set to decorate, must not be null
      list - the list to decorate, must not be null
      Throws:
      NullPointerException - if set or list is null
  • Method Details