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
@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 aList
to ensure that no duplicates are present much like aSet
.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:
- 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 void
add(int index, java.lang.Object object)
Deprecated.Adds an element to a specific index in the list if it is not already present.boolean
add(java.lang.Object object)
Deprecated.Adds an element to the list if it is not already present.boolean
addAll(int index, java.util.Collection coll)
Deprecated.Adds a collection of objects a specific index in the list avoiding duplicates.boolean
addAll(java.util.Collection coll)
Deprecated.Adds an element to the end of the list if it is not already present.java.util.Set
asSet()
Deprecated.Gets an unmodifiable view as a Set.void
clear()
Deprecated.boolean
contains(java.lang.Object object)
Deprecated.boolean
containsAll(java.util.Collection coll)
Deprecated.static SetUniqueList
decorate(java.util.List list)
Deprecated.Factory method to create a SetList using the supplied list to retain order.java.util.Iterator
iterator()
Deprecated.java.util.ListIterator
listIterator()
Deprecated.java.util.ListIterator
listIterator(int index)
Deprecated.java.lang.Object
remove(int index)
Deprecated.boolean
remove(java.lang.Object object)
Deprecated.boolean
removeAll(java.util.Collection coll)
Deprecated.boolean
retainAll(java.util.Collection coll)
Deprecated.java.lang.Object
set(int index, java.lang.Object object)
Deprecated.Sets the value at the specified index avoiding duplicates.java.util.List
subList(int fromIndex, int toIndex)
Deprecated.-
Methods inherited from class org.apache.commons.collections.list.AbstractListDecorator
get, indexOf, lastIndexOf
-
-
-
-
Method Detail
-
decorate
public static SetUniqueList decorate(java.util.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
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
-
asSet
public java.util.Set asSet()
Deprecated.Gets an unmodifiable view as a Set.- Returns:
- an unmodifiable set view
-
add
public boolean add(java.lang.Object object)
Deprecated.Adds an element to the list if it is not already present.(Violation) The
List
interface requires that this method returnstrue
always. However this class may returnfalse
because of theSet
behaviour.- Specified by:
add
in interfacejava.util.Collection
- Specified by:
add
in interfacejava.util.List
- Overrides:
add
in classAbstractCollectionDecorator
- Parameters:
object
- the object to add- Returns:
- true if object was added
-
add
public void add(int index, java.lang.Object object)
Deprecated.Adds an element to a specific index in the list if it is not already present.(Violation) The
List
interface makes the assumption that the element is always inserted. This may not happen with this implementation.- Specified by:
add
in interfacejava.util.List
- Overrides:
add
in classAbstractListDecorator
- Parameters:
index
- the index to insert atobject
- the object to add
-
addAll
public boolean addAll(java.util.Collection coll)
Deprecated.Adds an element to the end of the list if it is not already present.(Violation) The
List
interface makes the assumption that the element is always inserted. This may not happen with this implementation.- Specified by:
addAll
in interfacejava.util.Collection
- Specified by:
addAll
in interfacejava.util.List
- Overrides:
addAll
in classAbstractCollectionDecorator
- Parameters:
coll
- the collection to add
-
addAll
public boolean addAll(int index, java.util.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
List
interface makes the assumption that the elements are always inserted. This may not happen with this implementation.- Specified by:
addAll
in interfacejava.util.List
- Overrides:
addAll
in 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)
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:
set
in interfacejava.util.List
- Overrides:
set
in classAbstractListDecorator
- Parameters:
index
- the index to insert atobject
- the object to set- Returns:
- the previous object
-
remove
public boolean remove(java.lang.Object object)
Deprecated.- Specified by:
remove
in interfacejava.util.Collection
- Specified by:
remove
in interfacejava.util.List
- Overrides:
remove
in classAbstractCollectionDecorator
-
remove
public java.lang.Object remove(int index)
Deprecated.- Specified by:
remove
in interfacejava.util.List
- Overrides:
remove
in classAbstractListDecorator
-
removeAll
public boolean removeAll(java.util.Collection coll)
Deprecated.- Specified by:
removeAll
in interfacejava.util.Collection
- Specified by:
removeAll
in interfacejava.util.List
- Overrides:
removeAll
in classAbstractCollectionDecorator
-
retainAll
public boolean retainAll(java.util.Collection coll)
Deprecated.- Specified by:
retainAll
in interfacejava.util.Collection
- Specified by:
retainAll
in interfacejava.util.List
- Overrides:
retainAll
in classAbstractCollectionDecorator
-
clear
public void clear()
Deprecated.- Specified by:
clear
in interfacejava.util.Collection
- Specified by:
clear
in interfacejava.util.List
- Overrides:
clear
in classAbstractCollectionDecorator
-
contains
public boolean contains(java.lang.Object object)
Deprecated.- Specified by:
contains
in interfacejava.util.Collection
- Specified by:
contains
in interfacejava.util.List
- Overrides:
contains
in classAbstractCollectionDecorator
-
containsAll
public boolean containsAll(java.util.Collection coll)
Deprecated.- Specified by:
containsAll
in interfacejava.util.Collection
- Specified by:
containsAll
in interfacejava.util.List
- Overrides:
containsAll
in classAbstractCollectionDecorator
-
iterator
public java.util.Iterator iterator()
Deprecated.- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
- Specified by:
iterator
in interfacejava.util.List
- Overrides:
iterator
in classAbstractCollectionDecorator
-
listIterator
public java.util.ListIterator listIterator()
Deprecated.- Specified by:
listIterator
in interfacejava.util.List
- Overrides:
listIterator
in classAbstractListDecorator
-
listIterator
public java.util.ListIterator listIterator(int index)
Deprecated.- Specified by:
listIterator
in interfacejava.util.List
- Overrides:
listIterator
in classAbstractListDecorator
-
subList
public java.util.List subList(int fromIndex, int toIndex)
Deprecated.- Specified by:
subList
in interfacejava.util.List
- Overrides:
subList
in classAbstractListDecorator
-
-