org.codehaus.groovy.grails.web.binding
Class ListOrderedSet

java.lang.Object
  extended by org.apache.commons.collections.collection.AbstractCollectionDecorator
      extended by org.apache.commons.collections.set.AbstractSetDecorator
          extended by org.apache.commons.collections.set.AbstractSerializableSetDecorator
              extended by org.codehaus.groovy.grails.web.binding.ListOrderedSet
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.Set

public class ListOrderedSet
extends org.apache.commons.collections.set.AbstractSerializableSetDecorator
implements java.util.Set, java.util.List

Forked from Apache Commons Collections' implementation of ListOrderedSet. This one actually implements the List interface. Yes we are away of the warnings in the javadoc about problems with incompatibilities between the List and Set interfaces, however this class is designed to used internally only for data binding and not by end users.

See Also:
Serialized Form

Field Summary
protected  java.util.List 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(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()
           
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.
 java.lang.Object get(int index)
           
 int indexOf(java.lang.Object object)
           
 java.util.Iterator iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object object)
           
 boolean removeAll(java.util.Collection coll)
           
 boolean retainAll(java.util.Collection coll)
           
 java.lang.Object set(int index, java.lang.Object element)
           
 java.util.List subList(int fromIndex, int toIndex)
           
 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 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
 
Methods inherited from interface java.util.List
contains, containsAll, equals, hashCode, isEmpty, size
 

Field Detail

setOrder

protected final java.util.List setOrder
Internal list to hold the sequence of objects

Constructor Detail

ListOrderedSet

public ListOrderedSet()
Constructs a new empty ListOrderedSet using a HashSet and an ArrayList internally.

Since:
Commons Collections 3.1

ListOrderedSet

protected ListOrderedSet(java.util.Set set)
Constructor that wraps (not copies).

Parameters:
set - the set to decorate, must not be null
Throws:
java.lang.IllegalArgumentException - if set is null

ListOrderedSet

protected ListOrderedSet(java.util.Set set,
                         java.util.List 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.

Parameters:
set - the set to decorate, must not be null
list - the list to decorate, must not be null
Throws:
java.lang.IllegalArgumentException - if set or list is null
Method Detail

decorate

public static ListOrderedSet decorate(java.util.Set set)
Factory method to create an ordered set. An ArrayList is used to retain order.

Parameters:
set - the set to decorate, must not be null
Throws:
java.lang.IllegalArgumentException - if set is null

decorate

public static ListOrderedSet decorate(java.util.List list)
Factory method to create an ordered set using the supplied list to retain order. A HashSet is used for the set behaviour.

Parameters:
list - the list to decorate, must not be null
Throws:
java.lang.IllegalArgumentException - if list is null

asList

public java.util.List asList()
Gets an unmodifiable view of the order of the Set.

Returns:
an unmodifiable list view

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Specified by:
clear in interface java.util.Set
Overrides:
clear in class org.apache.commons.collections.collection.AbstractCollectionDecorator

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
Specified by:
iterator in interface java.util.Set
Overrides:
iterator in class org.apache.commons.collections.collection.AbstractCollectionDecorator

add

public boolean add(java.lang.Object object)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Specified by:
add in interface java.util.Set
Overrides:
add in class org.apache.commons.collections.collection.AbstractCollectionDecorator

addAll

public boolean addAll(java.util.Collection coll)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
Specified by:
addAll in interface java.util.Set
Overrides:
addAll in class org.apache.commons.collections.collection.AbstractCollectionDecorator

remove

public boolean remove(java.lang.Object object)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
Specified by:
remove in interface java.util.Set
Overrides:
remove in class org.apache.commons.collections.collection.AbstractCollectionDecorator

removeAll

public boolean removeAll(java.util.Collection coll)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
Specified by:
removeAll in interface java.util.Set
Overrides:
removeAll in class org.apache.commons.collections.collection.AbstractCollectionDecorator

retainAll

public boolean retainAll(java.util.Collection coll)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
Specified by:
retainAll in interface java.util.Set
Overrides:
retainAll in class org.apache.commons.collections.collection.AbstractCollectionDecorator

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class org.apache.commons.collections.collection.AbstractCollectionDecorator

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class org.apache.commons.collections.collection.AbstractCollectionDecorator

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List

indexOf

public int indexOf(java.lang.Object object)
Specified by:
indexOf in interface java.util.List

add

public void add(int index,
                java.lang.Object object)
Specified by:
add in interface java.util.List

addAll

public boolean addAll(int index,
                      java.util.Collection coll)
Specified by:
addAll in interface java.util.List

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List

toString

public java.lang.String 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:
toString in class org.apache.commons.collections.collection.AbstractCollectionDecorator

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List