Class SetUniqueList
- java.lang.Object
 - 
- org.apache.commons.collections.collection.AbstractCollectionDecorator
 - 
- org.apache.commons.collections.list.AbstractListDecorator
 - 
- org.apache.commons.collections.list.AbstractSerializableListDecorator
 - 
- org.apache.commons.collections.list.SetUniqueList
 
 
 
 
 
- 
- All Implemented Interfaces:
 java.io.Serializable,java.lang.Iterable,java.util.Collection,java.util.List
public class SetUniqueList extends AbstractSerializableListDecorator
Decorates aListto ensure that no duplicates are present much like aSet.The
Listinterface makes certain assumptions/requirements. This implementation breaks these in certain ways, but this is merely the result of rejecting duplicates. Each violation is explained in the method, but it should not affect you. Bear in mind that Sets require immutable objects to function correctly.The
ListOrderedSetclass provides an alternative approach, by wrapping an existing Set and retaining insertion order in the iterator.This class is Serializable from Commons Collections 3.1.
- Since:
 - Commons Collections 3.0
 - See Also:
 - Serialized Form
 
 
- 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, java.lang.Object object)Adds an element to a specific index in the list if it is not already present.booleanadd(java.lang.Object object)Adds an element to the list if it is not already present.booleanaddAll(int index, java.util.Collection coll)Adds a collection of objects a specific index in the list avoiding duplicates.booleanaddAll(java.util.Collection coll)Adds an element to the end of the list if it is not already present.java.util.SetasSet()Gets an unmodifiable view as a Set.voidclear()booleancontains(java.lang.Object object)booleancontainsAll(java.util.Collection coll)static SetUniqueListdecorate(java.util.List list)Factory method to create a SetList using the supplied list to retain order.java.util.Iteratoriterator()java.util.ListIteratorlistIterator()java.util.ListIteratorlistIterator(int index)java.lang.Objectremove(int index)booleanremove(java.lang.Object object)booleanremoveAll(java.util.Collection coll)booleanretainAll(java.util.Collection coll)java.lang.Objectset(int index, java.lang.Object object)Sets the value at the specified index avoiding duplicates.java.util.ListsubList(int fromIndex, int toIndex)- 
Methods inherited from class org.apache.commons.collections.list.AbstractListDecorator
get, indexOf, lastIndexOf 
 - 
 
 - 
 
- 
- 
Method Detail
- 
decorate
public static SetUniqueList decorate(java.util.List list)
Factory method to create a SetList using the supplied list to retain order.If the list contains duplicates, these are removed (first indexed one kept). A
HashSetis used for the set behaviour.- Parameters:
 list- the list to decorate, must not be null- Throws:
 java.lang.IllegalArgumentException- if list is null
 
- 
asSet
public java.util.Set asSet()
Gets an unmodifiable view as a Set.- Returns:
 - an unmodifiable set view
 
 
- 
add
public boolean add(java.lang.Object object)
Adds an element to the list if it is not already present.(Violation) The
Listinterface requires that this method returnstruealways. However this class may returnfalsebecause of theSetbehaviour.- Specified by:
 addin interfacejava.util.Collection- Specified by:
 addin interfacejava.util.List- Overrides:
 addin classAbstractCollectionDecorator- Parameters:
 object- the object to add- Returns:
 - true if object was added
 
 
- 
add
public void add(int index, java.lang.Object object)Adds an element to a specific index in the list if it is not already present.(Violation) The
Listinterface makes the assumption that the element is always inserted. This may not happen with this implementation.- Specified by:
 addin interfacejava.util.List- Overrides:
 addin classAbstractListDecorator- Parameters:
 index- the index to insert atobject- the object to add
 
- 
addAll
public boolean addAll(java.util.Collection coll)
Adds an element to the end of the list if it is not already present.(Violation) The
Listinterface makes the assumption that the element is always inserted. This may not happen with this implementation.- Specified by:
 addAllin interfacejava.util.Collection- Specified by:
 addAllin interfacejava.util.List- Overrides:
 addAllin classAbstractCollectionDecorator- Parameters:
 coll- the collection to add
 
- 
addAll
public boolean addAll(int index, java.util.Collection coll)Adds a collection of objects a specific index in the list avoiding duplicates.Only elements that are not already in this list will be added, and duplicates from the specified collection will be ignored.
(Violation) The
Listinterface makes the assumption that the elements are always inserted. This may not happen with this implementation.- Specified by:
 addAllin interfacejava.util.List- Overrides:
 addAllin classAbstractListDecorator- Parameters:
 index- the index to insert atcoll- the collection to add in iterator order- Returns:
 - true if this collection changed
 
 
- 
set
public java.lang.Object set(int index, java.lang.Object object)Sets the value at the specified index avoiding duplicates.The object is set into the specified index. Afterwards, any previous duplicate is removed If the object is not already in the list then a normal set occurs. If it is present, then the old version is removed.
- Specified by:
 setin interfacejava.util.List- Overrides:
 setin classAbstractListDecorator- Parameters:
 index- the index to insert atobject- the object to set- Returns:
 - the previous object
 
 
- 
remove
public boolean remove(java.lang.Object object)
- Specified by:
 removein interfacejava.util.Collection- Specified by:
 removein interfacejava.util.List- Overrides:
 removein classAbstractCollectionDecorator
 
- 
remove
public java.lang.Object remove(int index)
- Specified by:
 removein interfacejava.util.List- Overrides:
 removein classAbstractListDecorator
 
- 
removeAll
public boolean removeAll(java.util.Collection coll)
- Specified by:
 removeAllin interfacejava.util.Collection- Specified by:
 removeAllin interfacejava.util.List- Overrides:
 removeAllin classAbstractCollectionDecorator
 
- 
retainAll
public boolean retainAll(java.util.Collection coll)
- Specified by:
 retainAllin interfacejava.util.Collection- Specified by:
 retainAllin interfacejava.util.List- Overrides:
 retainAllin classAbstractCollectionDecorator
 
- 
clear
public void clear()
- Specified by:
 clearin interfacejava.util.Collection- Specified by:
 clearin interfacejava.util.List- Overrides:
 clearin classAbstractCollectionDecorator
 
- 
contains
public boolean contains(java.lang.Object object)
- Specified by:
 containsin interfacejava.util.Collection- Specified by:
 containsin interfacejava.util.List- Overrides:
 containsin classAbstractCollectionDecorator
 
- 
containsAll
public boolean containsAll(java.util.Collection coll)
- Specified by:
 containsAllin interfacejava.util.Collection- Specified by:
 containsAllin interfacejava.util.List- Overrides:
 containsAllin classAbstractCollectionDecorator
 
- 
iterator
public java.util.Iterator iterator()
- Specified by:
 iteratorin interfacejava.util.Collection- Specified by:
 iteratorin interfacejava.lang.Iterable- Specified by:
 iteratorin interfacejava.util.List- Overrides:
 iteratorin classAbstractCollectionDecorator
 
- 
listIterator
public java.util.ListIterator listIterator()
- Specified by:
 listIteratorin interfacejava.util.List- Overrides:
 listIteratorin classAbstractListDecorator
 
- 
listIterator
public java.util.ListIterator listIterator(int index)
- Specified by:
 listIteratorin interfacejava.util.List- Overrides:
 listIteratorin classAbstractListDecorator
 
- 
subList
public java.util.List subList(int fromIndex, int toIndex)- Specified by:
 subListin interfacejava.util.List- Overrides:
 subListin classAbstractListDecorator
 
 - 
 
 -