Class ListOrderedSet

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.Set

    @Deprecated(since="2021-04-30")
    public class ListOrderedSet
    extends AbstractSerializableSetDecorator
    implements java.util.Set
    Deprecated.
    Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.
    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 incompatable with a set.

    This class is Serializable from Commons Collections 3.1.

    Since:
    Commons Collections 3.0
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ListOrderedSet()
      Deprecated.
      Constructs a new empty ListOrderedSet using a HashSet and an ArrayList internally.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void add​(int index, java.lang.Object object)
      Deprecated.
       
      boolean add​(java.lang.Object object)
      Deprecated.
       
      boolean addAll​(int index, java.util.Collection coll)
      Deprecated.
       
      boolean addAll​(java.util.Collection coll)
      Deprecated.
       
      java.util.List asList()
      Deprecated.
      Gets an unmodifiable view of the order of the Set.
      void clear()
      Deprecated.
       
      static ListOrderedSet decorate​(java.util.List list)
      Deprecated.
      Factory method to create an ordered set using the supplied list to retain order.
      static ListOrderedSet decorate​(java.util.Set set)
      Deprecated.
      Factory method to create an ordered set.
      static ListOrderedSet decorate​(java.util.Set set, java.util.List list)
      Deprecated.
      Factory method to create an ordered set specifying the list and set to use.
      java.lang.Object get​(int index)
      Deprecated.
       
      int indexOf​(java.lang.Object object)
      Deprecated.
       
      java.util.Iterator iterator()
      Deprecated.
       
      java.lang.Object remove​(int index)
      Deprecated.
       
      boolean remove​(java.lang.Object object)
      Deprecated.
       
      boolean removeAll​(java.util.Collection coll)
      Deprecated.
       
      boolean retainAll​(java.util.Collection coll)
      Deprecated.
       
      java.lang.Object[] toArray()
      Deprecated.
       
      java.lang.Object[] toArray​(java.lang.Object[] a)
      Deprecated.
       
      java.lang.String toString()
      Deprecated.
      Uses the underlying List's toString so that order is achieved.
      • Methods inherited from class java.lang.Object

        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

        contains, containsAll, equals, hashCode, isEmpty, size, spliterator
    • Constructor Detail

      • ListOrderedSet

        public ListOrderedSet()
        Deprecated.
        Constructs a new empty ListOrderedSet using a HashSet and an ArrayList internally.
        Since:
        Commons Collections 3.1
    • Method Detail

      • decorate

        public static ListOrderedSet decorate​(java.util.Set set,
                                              java.util.List list)
        Deprecated.
        Factory method to create an ordered set specifying the list and set to use.

        The list and set must both be empty.

        Parameters:
        set - the set to decorate, must be empty and not null
        list - the list to decorate, must be empty and not null
        Throws:
        java.lang.IllegalArgumentException - if set or list is null
        java.lang.IllegalArgumentException - if either the set or list is not empty
        Since:
        Commons Collections 3.1
      • decorate

        public static ListOrderedSet decorate​(java.util.Set set)
        Deprecated.
        Factory method to create an ordered set.

        An ArrayList is used to retain order.

        Parameters:
        set - the set to decorate, must not be null
        Throws:
        java.lang.IllegalArgumentException - if set is null
      • decorate

        public static ListOrderedSet decorate​(java.util.List list)
        Deprecated.
        Factory method to create an ordered set using the supplied list to retain order.

        A HashSet is used for the set behaviour.

        NOTE: If the list contains duplicates, the duplicates are removed, altering the specified list.

        Parameters:
        list - the list to decorate, must not be null
        Throws:
        java.lang.IllegalArgumentException - if list is null
      • asList

        public java.util.List asList()
        Deprecated.
        Gets an unmodifiable view of the order of the Set.
        Returns:
        an unmodifiable list view
      • clear

        public void clear()
        Deprecated.
        Specified by:
        clear in interface java.util.Collection
        Specified by:
        clear in interface java.util.Set
        Overrides:
        clear in class AbstractCollectionDecorator
      • iterator

        public java.util.Iterator iterator()
        Deprecated.
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Specified by:
        iterator in interface java.util.Set
        Overrides:
        iterator in class AbstractCollectionDecorator
      • add

        public boolean add​(java.lang.Object object)
        Deprecated.
        Specified by:
        add in interface java.util.Collection
        Specified by:
        add in interface java.util.Set
        Overrides:
        add in class AbstractCollectionDecorator
      • addAll

        public boolean addAll​(java.util.Collection coll)
        Deprecated.
        Specified by:
        addAll in interface java.util.Collection
        Specified by:
        addAll in interface java.util.Set
        Overrides:
        addAll in class AbstractCollectionDecorator
      • remove

        public boolean remove​(java.lang.Object object)
        Deprecated.
        Specified by:
        remove in interface java.util.Collection
        Specified by:
        remove in interface java.util.Set
        Overrides:
        remove in class AbstractCollectionDecorator
      • removeAll

        public boolean removeAll​(java.util.Collection coll)
        Deprecated.
        Specified by:
        removeAll in interface java.util.Collection
        Specified by:
        removeAll in interface java.util.Set
        Overrides:
        removeAll in class AbstractCollectionDecorator
      • retainAll

        public boolean retainAll​(java.util.Collection coll)
        Deprecated.
        Specified by:
        retainAll in interface java.util.Collection
        Specified by:
        retainAll in interface java.util.Set
        Overrides:
        retainAll in class AbstractCollectionDecorator
      • toArray

        public java.lang.Object[] toArray()
        Deprecated.
        Specified by:
        toArray in interface java.util.Collection
        Specified by:
        toArray in interface java.util.Set
        Overrides:
        toArray in class AbstractCollectionDecorator
      • toArray

        public java.lang.Object[] toArray​(java.lang.Object[] a)
        Deprecated.
        Specified by:
        toArray in interface java.util.Collection
        Specified by:
        toArray in interface java.util.Set
        Overrides:
        toArray in class AbstractCollectionDecorator
      • get

        public java.lang.Object get​(int index)
        Deprecated.
      • indexOf

        public int indexOf​(java.lang.Object object)
        Deprecated.
      • add

        public void add​(int index,
                        java.lang.Object object)
        Deprecated.
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection coll)
        Deprecated.
      • remove

        public java.lang.Object remove​(int index)
        Deprecated.
      • toString

        public java.lang.String toString()
        Deprecated.
        Uses the underlying List's toString so that order is achieved. This means that the decorated Set's toString is not used, so any custom toStrings will be ignored.
        Overrides:
        toString in class AbstractCollectionDecorator