|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections.collection.AbstractCollectionDecorator<E>
org.apache.commons.collections.set.AbstractSetDecorator<E>
org.apache.commons.collections.set.AbstractSerializableSetDecorator<E>
org.apache.commons.collections.set.ListOrderedSet<E>
public class ListOrderedSet<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 incompatable with a set.
This class is Serializable from Commons Collections 3.1.
Field Summary | |
---|---|
protected List<E> |
setOrder
Internal list to hold the sequence of objects |
Fields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
collection |
Constructor Summary | |
---|---|
|
ListOrderedSet()
Constructs a new empty ListOrderedSet using
a HashSet and an ArrayList internally. |
protected |
ListOrderedSet(Set<E> set)
Constructor that wraps (not copies). |
protected |
ListOrderedSet(Set<E> set,
List<E> list)
Constructor that wraps (not copies) the Set and specifies the list to use. |
Method Summary | ||
---|---|---|
boolean |
add(E object)
|
|
void |
add(int index,
E object)
|
|
boolean |
addAll(Collection<? extends E> coll)
|
|
boolean |
addAll(int index,
Collection<? extends E> coll)
|
|
List<E> |
asList()
Gets an unmodifiable view of the order of the Set. |
|
void |
clear()
|
|
static
|
decorate(List<E> list)
Factory method to create an ordered set using the supplied list to retain order. |
|
static
|
decorate(Set<E> set)
Factory method to create an ordered set. |
|
static
|
decorate(Set<E> set,
List<E> list)
Factory method to create an ordered set specifying the list and set to use. |
|
E |
get(int index)
|
|
int |
indexOf(E object)
|
|
Iterator<E> |
iterator()
|
|
E |
remove(int index)
|
|
boolean |
remove(Object object)
|
|
boolean |
removeAll(Collection<?> coll)
|
|
boolean |
retainAll(Collection<?> coll)
|
|
Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
String |
toString()
Uses the underlying List's toString so that order is achieved. |
Methods inherited from class org.apache.commons.collections.set.AbstractSetDecorator |
---|
getSet |
Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
contains, containsAll, equals, getCollection, hashCode, isEmpty, size |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
contains, containsAll, equals, hashCode, isEmpty, size |
Field Detail |
---|
protected final List<E> setOrder
Constructor Detail |
---|
public ListOrderedSet()
ListOrderedSet
using
a HashSet
and an ArrayList
internally.
protected ListOrderedSet(Set<E> set)
set
- the set to decorate, must not be null
IllegalArgumentException
- if set is nullprotected ListOrderedSet(Set<E> set, List<E> list)
The set and list must both be correctly initialised to the same elements.
set
- the set to decorate, must not be nulllist
- the list to decorate, must not be null
IllegalArgumentException
- if set or list is nullMethod Detail |
---|
public static <E> ListOrderedSet<E> decorate(Set<E> set, List<E> list)
set
- the set to decorate, must be empty and not nulllist
- the list to decorate, must be empty and not null
IllegalArgumentException
- if set or list is null
IllegalArgumentException
- if either the set or list is not emptypublic static <E> ListOrderedSet<E> decorate(Set<E> set)
An ArrayList
is used to retain order.
set
- the set to decorate, must not be null
IllegalArgumentException
- if set is nullpublic static <E> ListOrderedSet<E> decorate(List<E> list)
A HashSet
is used for the set behaviour.
list
- the list to decorate, must not be null
IllegalArgumentException
- if list is nullpublic List<E> asList()
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollectionDecorator<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Set<E>
iterator
in class AbstractCollectionDecorator<E>
public boolean add(E object)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollectionDecorator<E>
public boolean addAll(Collection<? extends E> coll)
addAll
in interface Collection<E>
addAll
in interface Set<E>
addAll
in class AbstractCollectionDecorator<E>
public boolean remove(Object object)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollectionDecorator<E>
public boolean removeAll(Collection<?> coll)
removeAll
in interface Collection<E>
removeAll
in interface Set<E>
removeAll
in class AbstractCollectionDecorator<E>
public boolean retainAll(Collection<?> coll)
retainAll
in interface Collection<E>
retainAll
in interface Set<E>
retainAll
in class AbstractCollectionDecorator<E>
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollectionDecorator<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollectionDecorator<E>
public E get(int index)
public int indexOf(E object)
public void add(int index, E object)
public boolean addAll(int index, Collection<? extends E> coll)
public E remove(int index)
public String toString()
toString
in class AbstractCollectionDecorator<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |