Class SetUniqueList<E>
- Type Parameters:
- E- the type of the elements in the list.
- All Implemented Interfaces:
- Serializable,- Iterable<E>,- Collection<E>,- List<E>
List to ensure that no duplicates are present much
 like a Set.
 
 The List interface 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 ListOrderedSet
 class 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:
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedSetUniqueList(List<E> list, Set<E> set) Constructor that wraps (not copies) the List and specifies the set to use.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds an element to a specific index in the list if it is not already present.booleanAdds an element to the list if it is not already present.booleanaddAll(int index, Collection<? extends E> coll) Adds a collection of objects a specific index in the list avoiding duplicates.booleanaddAll(Collection<? extends E> coll) Adds a collection of objects to the end of the list avoiding duplicates.asSet()Gets an unmodifiable view as a Set.voidclear()booleanbooleancontainsAll(Collection<?> coll) createSetBasedOnList(Set<E> set, List<E> list) iterator()listIterator(int index) remove(int index) booleanbooleanremoveAll(Collection<?> coll) booleanbooleanretainAll(Collection<?> coll) Sets the value at the specified index avoiding duplicates.static <E> SetUniqueList<E> setUniqueList(List<E> list) Factory method to create a SetList using the supplied list to retain order.subList(int fromIndex, int toIndex) Methods inherited from class org.apache.commons.collections4.list.AbstractListDecoratordecorated, equals, get, hashCode, indexOf, lastIndexOfMethods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecoratorisEmpty, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, streamMethods inherited from interface java.util.ListisEmpty, replaceAll, size, sort, spliterator, toArray, toArray
- 
Constructor Details- 
SetUniqueListConstructor that wraps (not copies) the List and specifies the set to use.The set and list must both be correctly initialized to the same elements. - Parameters:
- list- the list to decorate, must not be null
- set- the set to decorate, must not be null
- Throws:
- NullPointerException- if set or list is null
 
 
- 
- 
Method Details- 
setUniqueListFactory 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 behavior.- Type Parameters:
- E- the element type
- Parameters:
- list- the list to decorate, must not be null
- Returns:
- a new SetUniqueList
- Throws:
- NullPointerException- if list is null
- Since:
- 4.0
 
- 
addAdds 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 theSetbehavior.- Specified by:
- addin interface- Collection<E>
- Specified by:
- addin interface- List<E>
- Overrides:
- addin class- AbstractCollectionDecorator<E>
- Parameters:
- object- the object to add
- Returns:
- true if object was added
 
- 
addAdds 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.
- 
addAllAdds 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 interface- Collection<E>
- Specified by:
- addAllin interface- List<E>
- Overrides:
- addAllin class- AbstractCollectionDecorator<E>
- Parameters:
- coll- the collection to add in iterator order
- Returns:
- true if this collection changed
 
- 
addAllAdds 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.
- 
asSet
- 
clear- Specified by:
- clearin interface- Collection<E>
- Specified by:
- clearin interface- List<E>
- Overrides:
- clearin class- AbstractCollectionDecorator<E>
 
- 
contains
- 
containsAll- Specified by:
- containsAllin interface- Collection<E>
- Specified by:
- containsAllin interface- List<E>
- Overrides:
- containsAllin class- AbstractCollectionDecorator<E>
 
- 
createSetBasedOnList
- 
iterator
- 
listIterator- Specified by:
- listIteratorin interface- List<E>
- Overrides:
- listIteratorin class- AbstractListDecorator<E>
 
- 
listIterator- Specified by:
- listIteratorin interface- List<E>
- Overrides:
- listIteratorin class- AbstractListDecorator<E>
 
- 
remove
- 
remove
- 
removeAll- Specified by:
- removeAllin interface- Collection<E>
- Specified by:
- removeAllin interface- List<E>
- Overrides:
- removeAllin class- AbstractCollectionDecorator<E>
 
- 
removeIf- Specified by:
- removeIfin interface- Collection<E>
- Overrides:
- removeIfin class- AbstractCollectionDecorator<E>
- Since:
- 4.4
 
- 
retainAllThis 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 (for example O(1)) implementation ofCollection.contains(Object).- Specified by:
- retainAllin interface- Collection<E>
- Specified by:
- retainAllin interface- List<E>
- Overrides:
- retainAllin class- AbstractCollectionDecorator<E>
 
- 
setSets 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. 
- 
subList
 
-