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
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- Stephen Colebourne, Henning P. Schmiedehausen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ListInternal list to hold the sequence of objectsFields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
collection -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a new emptyListOrderedSetusing aHashSetand anArrayListinternally.protectedListOrderedSet(Set set) Constructor that wraps (not copies).protectedListOrderedSet(Set set, List list) Constructor that wraps (not copies) the Set and specifies the list to use. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection coll) booleanaddAll(Collection coll) asList()Gets an unmodifiable view of the order of the Set.voidclear()static ListOrderedSetFactory method to create an ordered set using the supplied list to retain order.static ListOrderedSetFactory method to create an ordered set.static ListOrderedSetFactory method to create an ordered set specifying the list and set to use.get(int index) intiterator()remove(int index) booleanbooleanremoveAll(Collection coll) booleanretainAll(Collection coll) Object[]toArray()Object[]toString()Uses the underlying List's toString so that order is achieved.Methods inherited from class org.apache.commons.collections.set.AbstractSetDecorator
getSetMethods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
contains, containsAll, equals, getCollection, hashCode, isEmpty, sizeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
contains, containsAll, equals, hashCode, isEmpty, size, spliterator
-
Field Details
-
setOrder
Internal list to hold the sequence of objects
-
-
Constructor Details
-
ListOrderedSet
public ListOrderedSet()Constructs a new emptyListOrderedSetusing aHashSetand anArrayListinternally.- Since:
- Commons Collections 3.1
-
ListOrderedSet
Constructor that wraps (not copies).- Parameters:
set- the set to decorate, must not be null- Throws:
IllegalArgumentException- if set is null
-
ListOrderedSet
Constructor that wraps (not copies) the Set and specifies the list to use.The set and list must both be correctly initialised to the same elements.
- Parameters:
set- the set to decorate, must not be nulllist- the list to decorate, must not be null- Throws:
IllegalArgumentException- if set or list is null
-
-
Method Details
-
decorate
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
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
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
Gets an unmodifiable view of the order of the Set.- Returns:
- an unmodifiable list view
-
clear
public void clear()- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceSet- Overrides:
clearin classAbstractCollectionDecorator
-
iterator
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceSet- Overrides:
iteratorin classAbstractCollectionDecorator
-
add
- Specified by:
addin interfaceCollection- Specified by:
addin interfaceSet- Overrides:
addin classAbstractCollectionDecorator
-
addAll
- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceSet- Overrides:
addAllin classAbstractCollectionDecorator
-
remove
- Specified by:
removein interfaceCollection- Specified by:
removein interfaceSet- Overrides:
removein classAbstractCollectionDecorator
-
removeAll
- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceSet- Overrides:
removeAllin classAbstractCollectionDecorator
-
retainAll
- Specified by:
retainAllin interfaceCollection- Specified by:
retainAllin interfaceSet- Overrides:
retainAllin classAbstractCollectionDecorator
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet- Overrides:
toArrayin classAbstractCollectionDecorator
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet- Overrides:
toArrayin classAbstractCollectionDecorator
-
get
-
indexOf
-
add
-
addAll
-
remove
-
toString
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
-