|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.collection.AbstractCollectionDecorator<E> org.apache.commons.collections.list.AbstractListDecorator<E> org.apache.commons.collections.list.AbstractSerializableListDecorator<E> org.apache.commons.collections.list.SetUniqueList<E>
public class SetUniqueList<E>
Decorates a List
to ensure that no duplicates are present
much like a Set
.
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.
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.
Field Summary | |
---|---|
protected Set<E> |
set
Internal Set to maintain uniqueness. |
Fields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
collection |
Constructor Summary | |
---|---|
protected |
SetUniqueList(List<E> list,
Set<E> set)
Constructor that wraps (not copies) the List and specifies the set to use. |
Method Summary | ||
---|---|---|
boolean |
add(E object)
Adds an element to the list if it is not already present. |
|
void |
add(int index,
E object)
Adds an element to a specific index in the list if it is not already present. |
|
boolean |
addAll(Collection<? extends E> coll)
Adds an element to the end of the list if it is not already present. |
|
boolean |
addAll(int index,
Collection<? extends E> coll)
Adds a collection of objects to the end of the list avoiding duplicates. |
|
Set<E> |
asSet()
Gets an unmodifiable view as a Set. |
|
void |
clear()
|
|
boolean |
contains(Object object)
|
|
boolean |
containsAll(Collection<?> coll)
|
|
static
|
decorate(List<E> list)
Factory method to create a SetList using the supplied list to retain order. |
|
Iterator<E> |
iterator()
|
|
ListIterator<E> |
listIterator()
|
|
ListIterator<E> |
listIterator(int index)
|
|
E |
remove(int index)
|
|
boolean |
remove(Object object)
|
|
boolean |
removeAll(Collection<?> coll)
|
|
boolean |
retainAll(Collection<?> coll)
|
|
E |
set(int index,
E object)
Sets the value at the specified index avoiding duplicates. |
|
List<E> |
subList(int fromIndex,
int toIndex)
|
Methods inherited from class org.apache.commons.collections.list.AbstractListDecorator |
---|
get, getList, indexOf, lastIndexOf |
Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator |
---|
equals, getCollection, hashCode, isEmpty, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
equals, hashCode, isEmpty, size, toArray, toArray |
Field Detail |
---|
protected final Set<E> set
Constructor Detail |
---|
protected SetUniqueList(List<E> list, Set<E> set)
set
- the set to decorate, must not be nulllist
- the list to decorate, must not be null
IllegalArgumentException
- if set or list is nullMethod Detail |
---|
public static <E> SetUniqueList<E> decorate(List<E> list)
HashSet
is used for the set behaviour.
list
- the list to decorate, must not be null
IllegalArgumentException
- if list is nullpublic Set<E> asSet()
public boolean add(E object)
List
interface requires that this method returns
true
always. However this class may return false
because of the Set
behaviour.
add
in interface Collection<E>
add
in interface List<E>
add
in class AbstractCollectionDecorator<E>
object
- the object to add
public void add(int index, E object)
List
interface makes the assumption that the element is
always inserted. This may not happen with this implementation.
add
in interface List<E>
add
in class AbstractListDecorator<E>
index
- the index to insert atobject
- the object to addpublic boolean addAll(Collection<? extends E> coll)
List
interface makes the assumption that the element is
always inserted. This may not happen with this implementation.
addAll
in interface Collection<E>
addAll
in interface List<E>
addAll
in class AbstractCollectionDecorator<E>
coll
- the collection to addpublic boolean addAll(int index, Collection<? extends E> coll)
List
interface makes the assumption that the elements
are always inserted. This may not happen with this implementation.
addAll
in interface List<E>
addAll
in class AbstractListDecorator<E>
index
- the index to insert atcoll
- the collection to add in iterator order
public E set(int index, E object)
set
in interface List<E>
set
in class AbstractListDecorator<E>
index
- the index to insert atobject
- the object to set
public boolean remove(Object object)
remove
in interface Collection<E>
remove
in interface List<E>
remove
in class AbstractCollectionDecorator<E>
public E remove(int index)
remove
in interface List<E>
remove
in class AbstractListDecorator<E>
public boolean removeAll(Collection<?> coll)
removeAll
in interface Collection<E>
removeAll
in interface List<E>
removeAll
in class AbstractCollectionDecorator<E>
public boolean retainAll(Collection<?> coll)
retainAll
in interface Collection<E>
retainAll
in interface List<E>
retainAll
in class AbstractCollectionDecorator<E>
public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class AbstractCollectionDecorator<E>
public boolean contains(Object object)
contains
in interface Collection<E>
contains
in interface List<E>
contains
in class AbstractCollectionDecorator<E>
public boolean containsAll(Collection<?> coll)
containsAll
in interface Collection<E>
containsAll
in interface List<E>
containsAll
in class AbstractCollectionDecorator<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface List<E>
iterator
in class AbstractCollectionDecorator<E>
public ListIterator<E> listIterator()
listIterator
in interface List<E>
listIterator
in class AbstractListDecorator<E>
public ListIterator<E> listIterator(int index)
listIterator
in interface List<E>
listIterator
in class AbstractListDecorator<E>
public List<E> subList(int fromIndex, int toIndex)
subList
in interface List<E>
subList
in class AbstractListDecorator<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |