Class ListOrderedSet
- All Implemented Interfaces:
Serializable,Iterable,Collection,Set
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:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Constructs a new emptyListOrderedSetusing aHashSetand anArrayListinternally. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.booleanDeprecated.booleanaddAll(int index, Collection coll) Deprecated.booleanaddAll(Collection coll) Deprecated.asList()Deprecated.Gets an unmodifiable view of the order of the Set.voidclear()Deprecated.static ListOrderedSetDeprecated.Factory method to create an ordered set using the supplied list to retain order.static ListOrderedSetDeprecated.Factory method to create an ordered set.static ListOrderedSetDeprecated.Factory method to create an ordered set specifying the list and set to use.get(int index) Deprecated.intDeprecated.iterator()Deprecated.remove(int index) Deprecated.booleanDeprecated.booleanremoveAll(Collection coll) Deprecated.booleanretainAll(Collection coll) Deprecated.Object[]toArray()Deprecated.Object[]Deprecated.toString()Deprecated.Uses the underlying List's toString so that order is achieved.Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
contains, containsAll, equals, hashCode, isEmpty, sizeMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
contains, containsAll, equals, hashCode, isEmpty, size, spliterator
-
Constructor Details
-
ListOrderedSet
public ListOrderedSet()Deprecated.Constructs a new emptyListOrderedSetusing aHashSetand anArrayListinternally.- Since:
- Commons Collections 3.1
-
-
Method Details
-
decorate
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 nulllist- the list to decorate, must be empty and not null- Throws:
IllegalArgumentException- if set or list is nullIllegalArgumentException- if either the set or list is not empty- Since:
- Commons Collections 3.1
-
decorate
Deprecated.Factory method to create an ordered set.An
ArrayListis used to retain order.- Parameters:
set- the set to decorate, must not be null- Throws:
IllegalArgumentException- if set is null
-
decorate
Deprecated.Factory method to create an ordered set using the supplied list to retain order.A
HashSetis 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:
IllegalArgumentException- if list is null
-
asList
Deprecated.Gets an unmodifiable view of the order of the Set.- Returns:
- an unmodifiable list view
-
clear
public void clear()Deprecated.- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceSet- Overrides:
clearin classAbstractCollectionDecorator
-
iterator
Deprecated.- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceSet- Overrides:
iteratorin classAbstractCollectionDecorator
-
add
Deprecated.- Specified by:
addin interfaceCollection- Specified by:
addin interfaceSet- Overrides:
addin classAbstractCollectionDecorator
-
addAll
Deprecated.- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceSet- Overrides:
addAllin classAbstractCollectionDecorator
-
remove
Deprecated.- Specified by:
removein interfaceCollection- Specified by:
removein interfaceSet- Overrides:
removein classAbstractCollectionDecorator
-
removeAll
Deprecated.- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceSet- Overrides:
removeAllin classAbstractCollectionDecorator
-
retainAll
Deprecated.- Specified by:
retainAllin interfaceCollection- Specified by:
retainAllin interfaceSet- Overrides:
retainAllin classAbstractCollectionDecorator
-
toArray
Deprecated.- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet- Overrides:
toArrayin classAbstractCollectionDecorator
-
toArray
Deprecated.- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet- Overrides:
toArrayin classAbstractCollectionDecorator
-
get
Deprecated. -
indexOf
Deprecated. -
add
Deprecated. -
addAll
Deprecated. -
remove
Deprecated. -
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:
toStringin classAbstractCollectionDecorator
-