org.apache.commons.collections.set
public class ListOrderedSet extends AbstractSerializableSetDecorator implements 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: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
Field Summary | |
---|---|
protected List | setOrder Internal list to hold the sequence of objects |
Constructor Summary | |
---|---|
ListOrderedSet()
Constructs a new empty ListOrderedSet using
a HashSet and an ArrayList internally.
| |
protected | ListOrderedSet(Set set)
Constructor that wraps (not copies).
|
protected | ListOrderedSet(Set set, List list)
Constructor that wraps (not copies) the Set and specifies the list to use.
|
Method Summary | |
---|---|
boolean | add(Object object) |
void | add(int index, Object object) |
boolean | addAll(Collection coll) |
boolean | addAll(int index, Collection coll) |
List | asList()
Gets an unmodifiable view of the order of the Set.
|
void | clear() |
static ListOrderedSet | decorate(Set set, List list)
Factory method to create an ordered set specifying the list and set to use.
|
static ListOrderedSet | decorate(Set set)
Factory method to create an ordered set.
|
static ListOrderedSet | decorate(List list)
Factory method to create an ordered set using the supplied list to retain order.
|
Object | get(int index) |
int | indexOf(Object object) |
Iterator | iterator() |
boolean | remove(Object object) |
Object | remove(int index) |
boolean | removeAll(Collection coll) |
boolean | retainAll(Collection coll) |
Object[] | toArray() |
Object[] | toArray(Object[] a) |
String | toString()
Uses the underlying List's toString so that order is achieved.
|
ListOrderedSet
using
a HashSet
and an ArrayList
internally.
Since: Commons Collections 3.1
Parameters: set the set to decorate, must not be null
Throws: IllegalArgumentException if set is null
The set and list must both be correctly initialised to the same elements.
Parameters: set the set to decorate, must not be null list the list to decorate, must not be null
Throws: IllegalArgumentException if set or list is null
Returns: an unmodifiable list view
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: IllegalArgumentException if set or list is null IllegalArgumentException if either the set or list is not empty
Since: Commons Collections 3.1
An ArrayList
is used to retain order.
Parameters: set the set to decorate, must not be null
Throws: IllegalArgumentException if set is null
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: IllegalArgumentException if list is null