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 incompatible with a
set.
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides org. |
| private final List | setOrder
Internal list to hold the sequence of objects |
| Access | Constructor and Description |
|---|---|
| public | |
| protected | ListOrderedSet(final Set<E>
the set to decorate, must not be null set)Constructor that wraps (not copies). |
| protected | ListOrderedSet(final Set<E>
the set to decorate, must not be null set, final List<E> the list to decorate, must not be null list)Constructor that wraps (not copies) the Set and specifies the list to use. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(final E
element to be added to this set object)Overrides org. Implements java. |
| public void | add(final int
the index at which the element is to be inserted index, final E the element to be inserted object)Inserts the specified element at the specified position if it is not yet contained in this ordered set (optional operation). |
| public boolean | addAll(final Collection<? extends E>
collection containing elements to be added to this set coll)Overrides org. Implements java. |
| public boolean | Returns: true if this ordered set changed as a result of the callthe position to insert the elements index, final Collection<? extends E> the collection containing the elements to be inserted coll)Inserts all elements in the specified collection not yet contained in the ordered set at the specified position (optional operation). |
| public List | |
| public void | clear()
Overrides org. Implements java. |
| public E | |
| public int | |
| public OrderedIterator | iterator()
Overrides org. Implements java. |
| public static < the element type E> ListOrderedSet | Returns: a new ordered setthe set to decorate, must be empty and not null set, final List<E> the list to decorate, must be empty and not null list)Factory method to create an ordered set specifying the list and set to use. |
| public static < the element type E> ListOrderedSet | Returns: a new ordered setthe set to decorate, must not be null set)Factory method to create an ordered set. |
| public static < the element type E> ListOrderedSet | Returns: a new ordered setthe list to decorate, must not be null list)Factory method to create an ordered set using the supplied list to retain order. |
| public boolean | remove(final Object
object to be removed from this set, if present object)Overrides org. Implements java. |
| public E | Returns: the element that has been remove from the ordered setthe index of the element to be removed index)Removes the element at the specified position from the ordered set. |
| public boolean | removeAll(final Collection<?>
collection containing elements to be removed from this set coll)Overrides org. Implements java. |
| public boolean | removeIf(final Predicate<? super E>
a predicate which returns filter)true for elements to be
removedOverrides org. Overrides default java. |
| public boolean | retainAll(final Collection<?>
collection containing elements to be retained in this set coll)Overrides org. Implements java. |
| public Object[] | toArray()
Overrides org. Implements java. |
| public <T> T[] | toArray(final T[]
the array into which the elements of this set are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose. a)Overrides org. Implements java. |
| public String | Returns: a string representation of the ordered setOverrides org. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. Serialization version | |
| setOrder | back to summary |
|---|---|
| private final List<E> setOrder Internal list to hold the sequence of objects | |
| ListOrderedSet | back to summary |
|---|---|
| public ListOrderedSet() Constructs a new empty
| |
| ListOrderedSet | back to summary |
|---|---|
| protected ListOrderedSet(final Set<E> set) Constructor that wraps (not copies).
| |
| ListOrderedSet | back to summary |
|---|---|
| protected ListOrderedSet(final Set<E> set, final List<E> list) 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.
| |
| add | back to summary |
|---|---|
| public boolean add(final E object) Overrides org. Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| add | back to summary |
|---|---|
| public void add(final int index, final E object) Inserts the specified element at the specified position if it is not yet contained in this ordered set (optional operation). Shifts the element currently at this position and any subsequent elements to the right.
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(final Collection<? extends E> coll) Overrides org. Implements java. Doc from java. Adds all of the elements in the specified collection to this set if
they're not already present (optional operation). If the specified
collection is also a set, the
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(final int index, final Collection<? extends E> coll) Inserts all elements in the specified collection not yet contained in the ordered set at the specified position (optional operation). Shifts the element currently at the position and all subsequent elements to the right.
| |
| asList | back to summary |
|---|---|
| public List Gets an unmodifiable view of the order of the Set.
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides org. Implements java. Doc from java. Removes all of the elements from this set (optional operation). The set will be empty after this call returns.
| |
| get | back to summary |
|---|---|
| public E get(final int index) Returns the element at the specified position in this ordered set.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(final Object object) Returns the index of the first occurrence of the specified element in ordered set.
| |
| iterator | back to summary |
|---|---|
| public OrderedIterator Overrides org. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
| |
| listOrderedSet | back to summary |
|---|---|
| public static <E> ListOrderedSet Factory method to create an ordered set specifying the list and set to use. The list and set must both be empty.
| |
| listOrderedSet | back to summary |
|---|---|
| public static <E> ListOrderedSet Factory method to create an ordered set.
An
| |
| listOrderedSet | back to summary |
|---|---|
| public static <E> ListOrderedSet Factory method to create an ordered set using the supplied list to retain order.
A Note If the list contains duplicates, the duplicates are removed, altering the specified list.
| |
| remove | back to summary |
|---|---|
| public boolean remove(final Object object) Overrides org. Implements java. Doc from java. Removes the specified element from this set if it is present
(optional operation). More formally, removes an element | |
| remove | back to summary |
|---|---|
| public E remove(final int index) Removes the element at the specified position from the ordered set. Shifts any subsequent elements to the left.
| |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(final Collection<?> coll) Overrides org. Implements java. Doc from java. Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.
| |
| removeIf | back to summary |
|---|---|
| public boolean removeIf(final Predicate<? super E> filter) Overrides org. Overrides default java. Doc from java. Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller. | |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(final Collection<?> coll) Overrides org. Implements java. Doc from java. Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.
This implementation iterates over the elements of this set, checking
each element in turn to see if it's contained in
| |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Overrides org. Implements java. Doc from java. Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array. This method acts as bridge between array-based and collection-based APIs. | |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(final T[] a) Overrides org. Implements java. Doc from java. Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set. If this set fits in the specified array with room to spare
(i.e., the array has more elements than this set), the element in
the array immediately following the end of the set is set to
If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. Like the Suppose
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. 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. | |
| Modifier and Type | Field and Description |
|---|---|
| private E | last
Last object retrieved |
| private final Collection | set
Object we iterate on |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | hasPrevious()
Implements org. |
| public E | next()
Overrides org. Implements java. |
| public E | previous()
Implements org. |
| public void | remove()
Overrides org. Overrides default java. |
| last | back to summary |
|---|---|
| private E last Last object retrieved | |
| set | back to summary |
|---|---|
| private final Collection<E> set Object we iterate on | |
| OrderedSetIterator | back to summary |
|---|---|
| private OrderedSetIterator(final ListIterator<E> iterator, final Collection<E> set) | |
| hasPrevious | back to summary |
|---|---|
| public boolean hasPrevious() Implements org. Doc from org. Checks to see if there is a previous element that can be iterated to.
| |
| next | back to summary |
|---|---|
| public E next() Overrides org. Implements java. Doc from java. Returns the next element in the iteration.
| |
| previous | back to summary |
|---|---|
| public E previous() Implements org. Doc from org. Gets the previous element from the container.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides org. Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |