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:
Serializable,Iterable,Collection,List
@Deprecated(since="2021-04-30") public class SetUniqueList extends AbstractSerializableListDecorator
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.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 Deprecated Methods Modifier and Type Method Description voidadd(int index, Object object)Deprecated.Adds an element to a specific index in the list if it is not already present.booleanadd(Object object)Deprecated.Adds an element to the list if it is not already present.booleanaddAll(int index, Collection coll)Deprecated.Adds a collection of objects a specific index in the list avoiding duplicates.booleanaddAll(Collection coll)Deprecated.Adds an element to the end of the list if it is not already present.SetasSet()Deprecated.Gets an unmodifiable view as a Set.voidclear()Deprecated.booleancontains(Object object)Deprecated.booleancontainsAll(Collection coll)Deprecated.static SetUniqueListdecorate(List list)Deprecated.Factory method to create a SetList using the supplied list to retain order.Iteratoriterator()Deprecated.ListIteratorlistIterator()Deprecated.ListIteratorlistIterator(int index)Deprecated.Objectremove(int index)Deprecated.booleanremove(Object object)Deprecated.booleanremoveAll(Collection coll)Deprecated.booleanretainAll(Collection coll)Deprecated.Objectset(int index, Object object)Deprecated.Sets the value at the specified index avoiding duplicates.ListsubList(int fromIndex, int toIndex)Deprecated.-
Methods inherited from class org.apache.commons.collections.list.AbstractListDecorator
get, indexOf, lastIndexOf
-
Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
equals, hashCode, isEmpty, size, toArray, toArray, toString
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, isEmpty, replaceAll, size, sort, spliterator, toArray, toArray
-
-
-
-
Method Detail
-
decorate
public static SetUniqueList decorate(List list)
Deprecated.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:
IllegalArgumentException- if list is null
-
asSet
public Set asSet()
Deprecated.Gets an unmodifiable view as a Set.- Returns:
- an unmodifiable set view
-
add
public boolean add(Object object)
Deprecated.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 interfaceCollection- Specified by:
addin interfaceList- Overrides:
addin classAbstractCollectionDecorator- Parameters:
object- the object to add- Returns:
- true if object was added
-
add
public void add(int index, Object object)Deprecated.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 interfaceList- Overrides:
addin classAbstractListDecorator- Parameters:
index- the index to insert atobject- the object to add
-
addAll
public boolean addAll(Collection coll)
Deprecated.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 interfaceCollection- Specified by:
addAllin interfaceList- Overrides:
addAllin classAbstractCollectionDecorator- Parameters:
coll- the collection to add
-
addAll
public boolean addAll(int index, Collection coll)Deprecated.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 interfaceList- 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 Object set(int index, Object object)
Deprecated.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 interfaceList- Overrides:
setin classAbstractListDecorator- Parameters:
index- the index to insert atobject- the object to set- Returns:
- the previous object
-
remove
public boolean remove(Object object)
Deprecated.- Specified by:
removein interfaceCollection- Specified by:
removein interfaceList- Overrides:
removein classAbstractCollectionDecorator
-
remove
public Object remove(int index)
Deprecated.- Specified by:
removein interfaceList- Overrides:
removein classAbstractListDecorator
-
removeAll
public boolean removeAll(Collection coll)
Deprecated.- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceList- Overrides:
removeAllin classAbstractCollectionDecorator
-
retainAll
public boolean retainAll(Collection coll)
Deprecated.- Specified by:
retainAllin interfaceCollection- Specified by:
retainAllin interfaceList- Overrides:
retainAllin classAbstractCollectionDecorator
-
clear
public void clear()
Deprecated.- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceList- Overrides:
clearin classAbstractCollectionDecorator
-
contains
public boolean contains(Object object)
Deprecated.- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceList- Overrides:
containsin classAbstractCollectionDecorator
-
containsAll
public boolean containsAll(Collection coll)
Deprecated.- Specified by:
containsAllin interfaceCollection- Specified by:
containsAllin interfaceList- Overrides:
containsAllin classAbstractCollectionDecorator
-
iterator
public Iterator iterator()
Deprecated.- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceList- Overrides:
iteratorin classAbstractCollectionDecorator
-
listIterator
public ListIterator listIterator()
Deprecated.- Specified by:
listIteratorin interfaceList- Overrides:
listIteratorin classAbstractListDecorator
-
listIterator
public ListIterator listIterator(int index)
Deprecated.- Specified by:
listIteratorin interfaceList- Overrides:
listIteratorin classAbstractListDecorator
-
subList
public List subList(int fromIndex, int toIndex)
Deprecated.- Specified by:
subListin interfaceList- Overrides:
subListin classAbstractListDecorator
-
-