|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.morph.util.ListOrderedSet
public class ListOrderedSet
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.
Note: this class was copied from Commons Collections.
| Field Summary | |
|---|---|
protected java.util.Collection |
collection
The collection being decorated |
protected java.util.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(java.util.Set set)
Constructor that wraps (not copies). |
protected |
ListOrderedSet(java.util.Set set,
java.util.List list)
Constructor that wraps (not copies) the Set and specifies the list to use. |
| Method Summary | |
|---|---|
void |
add(int index,
java.lang.Object object)
|
boolean |
add(java.lang.Object object)
|
boolean |
addAll(java.util.Collection coll)
|
boolean |
addAll(int index,
java.util.Collection coll)
|
java.util.List |
asList()
Gets an unmodifiable view of the order of the Set. |
void |
clear()
|
boolean |
contains(java.lang.Object o)
|
boolean |
containsAll(java.util.Collection c)
|
static ListOrderedSet |
decorate(java.util.List list)
Factory method to create an ordered set using the supplied list to retain order. |
static ListOrderedSet |
decorate(java.util.Set set)
Factory method to create an ordered set. |
static ListOrderedSet |
decorate(java.util.Set set,
java.util.List list)
Factory method to create an ordered set specifying the list and set to use. |
java.lang.Object |
get(int index)
|
int |
indexOf(java.lang.Object object)
|
boolean |
isEmpty()
|
java.util.Iterator |
iterator()
|
java.lang.Object |
remove(int index)
|
boolean |
remove(java.lang.Object object)
|
boolean |
removeAll(java.util.Collection coll)
|
boolean |
retainAll(java.util.Collection coll)
|
int |
size()
|
java.lang.Object[] |
toArray()
|
java.lang.Object[] |
toArray(java.lang.Object[] a)
|
java.lang.String |
toString()
Uses the underlying List's toString so that order is achieved. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
equals, hashCode |
| Field Detail |
|---|
protected java.util.Collection collection
protected final java.util.List setOrder
| Constructor Detail |
|---|
public ListOrderedSet()
ListOrderedSet using
a HashSet and an ArrayList internally.
protected ListOrderedSet(java.util.Set set)
set - the set to decorate, must not be null
java.lang.IllegalArgumentException - if set is null
protected ListOrderedSet(java.util.Set set,
java.util.List 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
java.lang.IllegalArgumentException - if set or list is null| Method Detail |
|---|
public static ListOrderedSet decorate(java.util.Set set,
java.util.List list)
The list and set must both be empty.
set - the set to decorate, must be empty and not nulllist - the list to decorate, must be empty and not null
java.lang.IllegalArgumentException - if set or list is null
java.lang.IllegalArgumentException - if either the set or list is not emptypublic static ListOrderedSet decorate(java.util.Set set)
An ArrayList is used to retain order.
set - the set to decorate, must not be null
java.lang.IllegalArgumentException - if set is nullpublic static ListOrderedSet decorate(java.util.List list)
A HashSet is used for the set behaviour.
NOTE: If the list contains duplicates, the duplicates are removed, altering the specified list.
list - the list to decorate, must not be null
java.lang.IllegalArgumentException - if list is nullpublic java.util.List asList()
public void clear()
clear in interface java.util.Collectionclear in interface java.util.Setpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Setpublic boolean add(java.lang.Object object)
add in interface java.util.Collectionadd in interface java.util.Setpublic boolean addAll(java.util.Collection coll)
addAll in interface java.util.CollectionaddAll in interface java.util.Setpublic boolean remove(java.lang.Object object)
remove in interface java.util.Collectionremove in interface java.util.Setpublic boolean removeAll(java.util.Collection coll)
removeAll in interface java.util.CollectionremoveAll in interface java.util.Setpublic boolean retainAll(java.util.Collection coll)
retainAll in interface java.util.CollectionretainAll in interface java.util.Setpublic java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.Setpublic java.lang.Object[] toArray(java.lang.Object[] a)
toArray in interface java.util.CollectiontoArray in interface java.util.Setpublic java.lang.Object get(int index)
public int indexOf(java.lang.Object object)
public void add(int index,
java.lang.Object object)
public boolean addAll(int index,
java.util.Collection coll)
public java.lang.Object remove(int index)
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in interface java.util.Setpublic boolean containsAll(java.util.Collection c)
containsAll in interface java.util.CollectioncontainsAll in interface java.util.Setpublic boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in interface java.util.Setpublic int size()
size in interface java.util.Collectionsize in interface java.util.Set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||