Class SetUniqueList<E>
- java.lang.Object
 - 
- org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
 - 
- org.apache.commons.collections4.list.AbstractListDecorator<E>
 - 
- org.apache.commons.collections4.list.AbstractSerializableListDecorator<E>
 - 
- org.apache.commons.collections4.list.SetUniqueList<E>
 
 
 
 
 
- 
- All Implemented Interfaces:
 java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>
public class SetUniqueList<E> extends AbstractSerializableListDecorator<E>
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:
 - 3.0
 - See Also:
 - Serialized Form
 
 
- 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E object)Adds an element to a specific index in the list if it is not already present.booleanadd(E object)Adds an element to the list if it is not already present.booleanaddAll(int index, java.util.Collection<? extends E> coll)Adds a collection of objects a specific index in the list avoiding duplicates.booleanaddAll(java.util.Collection<? extends E> coll)Adds a collection of objects to the end of the list avoiding duplicates.java.util.Set<E>asSet()Gets an unmodifiable view as a Set.voidclear()booleancontains(java.lang.Object object)booleancontainsAll(java.util.Collection<?> coll)java.util.Iterator<E>iterator()java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)Eremove(int index)booleanremove(java.lang.Object object)booleanremoveAll(java.util.Collection<?> coll)booleanremoveIf(java.util.function.Predicate<? super E> filter)booleanretainAll(java.util.Collection<?> coll)Eset(int index, E object)Sets the value at the specified index avoiding duplicates.static <E> SetUniqueList<E>setUniqueList(java.util.List<E> list)Factory method to create a SetList using the supplied list to retain order.java.util.List<E>subList(int fromIndex, int toIndex)- 
Methods inherited from class org.apache.commons.collections4.list.AbstractListDecorator
equals, get, hashCode, indexOf, lastIndexOf 
 - 
 
 - 
 
- 
- 
Method Detail
- 
setUniqueList
public static <E> SetUniqueList<E> setUniqueList(java.util.List<E> 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.- Type Parameters:
 E- the element type- Parameters:
 list- the list to decorate, must not be null- Returns:
 - a new 
SetUniqueList - Throws:
 java.lang.NullPointerException- if list is null- Since:
 - 4.0
 
 
- 
asSet
public java.util.Set<E> asSet()
Gets an unmodifiable view as a Set.- Returns:
 - an unmodifiable set view
 
 
- 
add
public boolean add(E 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<E>- Specified by:
 addin interfacejava.util.List<E>- Overrides:
 addin classAbstractCollectionDecorator<E>- Parameters:
 object- the object to add- Returns:
 - true if object was added
 
 
- 
add
public void add(int index, E 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<E>- Overrides:
 addin classAbstractListDecorator<E>- Parameters:
 index- the index to insert atobject- the object to add
 
- 
addAll
public boolean addAll(java.util.Collection<? extends E> coll)
Adds a collection of objects to the end of 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.Collection<E>- Specified by:
 addAllin interfacejava.util.List<E>- Overrides:
 addAllin classAbstractCollectionDecorator<E>- Parameters:
 coll- the collection to add in iterator order- Returns:
 - true if this collection changed
 
 
- 
addAll
public boolean addAll(int index, java.util.Collection<? extends E> 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<E>- Overrides:
 addAllin classAbstractListDecorator<E>- Parameters:
 index- the index to insert atcoll- the collection to add in iterator order- Returns:
 - true if this collection changed
 
 
- 
set
public E set(int index, E 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<E>- Overrides:
 setin classAbstractListDecorator<E>- 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<E>- Specified by:
 removein interfacejava.util.List<E>- Overrides:
 removein classAbstractCollectionDecorator<E>
 
- 
remove
public E remove(int index)
- Specified by:
 removein interfacejava.util.List<E>- Overrides:
 removein classAbstractListDecorator<E>
 
- 
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
 removeIfin interfacejava.util.Collection<E>- Overrides:
 removeIfin classAbstractCollectionDecorator<E>- Since:
 - 4.4
 
 
- 
removeAll
public boolean removeAll(java.util.Collection<?> coll)
- Specified by:
 removeAllin interfacejava.util.Collection<E>- Specified by:
 removeAllin interfacejava.util.List<E>- Overrides:
 removeAllin classAbstractCollectionDecorator<E>
 
- 
retainAll
public boolean retainAll(java.util.Collection<?> coll)
This implementation iterates over the elements of this list, checking each element in turn to see if it's contained in
coll. If it's not contained, it's removed from this list. As a consequence, it is advised to use a collection type forcollthat provides a fast (e.g. O(1)) implementation ofCollection.contains(Object).- Specified by:
 retainAllin interfacejava.util.Collection<E>- Specified by:
 retainAllin interfacejava.util.List<E>- Overrides:
 retainAllin classAbstractCollectionDecorator<E>
 
- 
clear
public void clear()
- Specified by:
 clearin interfacejava.util.Collection<E>- Specified by:
 clearin interfacejava.util.List<E>- Overrides:
 clearin classAbstractCollectionDecorator<E>
 
- 
contains
public boolean contains(java.lang.Object object)
- Specified by:
 containsin interfacejava.util.Collection<E>- Specified by:
 containsin interfacejava.util.List<E>- Overrides:
 containsin classAbstractCollectionDecorator<E>
 
- 
containsAll
public boolean containsAll(java.util.Collection<?> coll)
- Specified by:
 containsAllin interfacejava.util.Collection<E>- Specified by:
 containsAllin interfacejava.util.List<E>- Overrides:
 containsAllin classAbstractCollectionDecorator<E>
 
- 
iterator
public java.util.Iterator<E> iterator()
 
- 
listIterator
public java.util.ListIterator<E> listIterator()
- Specified by:
 listIteratorin interfacejava.util.List<E>- Overrides:
 listIteratorin classAbstractListDecorator<E>
 
- 
listIterator
public java.util.ListIterator<E> listIterator(int index)
- Specified by:
 listIteratorin interfacejava.util.List<E>- Overrides:
 listIteratorin classAbstractListDecorator<E>
 
- 
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
NOTE: from 4.0, an unmodifiable list will be returned, as changes to the subList can invalidate the parent list.
- Specified by:
 subListin interfacejava.util.List<E>- Overrides:
 subListin classAbstractListDecorator<E>
 
 - 
 
 -