| org.apache.commons.collections.list.AbstractListDecorator org.apache.commons.collections.list.AbstractSerializableListDecorator org.apache.commons.collections.list.SetUniqueList
SetUniqueList | public class SetUniqueList extends AbstractSerializableListDecorator (Code) | | Decorates a 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
org.apache.commons.collections.set.ListOrderedSet 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 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Matthew Hawthorne author: Stephen Colebourne author: Tom Dunham |
Field Summary | |
final protected Set | set Internal Set to maintain uniqueness. |
Constructor Summary | |
protected | SetUniqueList(List list, Set set) Constructor that wraps (not copies) the List and specifies the set to use. |
Method Summary | |
public boolean | add(Object object) Adds an element to the list if it is not already present.
(Violation)
The List interface requires that this method returns
true always. | public void | add(int index, Object object) 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. | public boolean | addAll(Collection coll) 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. | public boolean | addAll(int index, Collection 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 List interface makes the assumption that the elements
are always inserted. | public Set | asSet() Gets an unmodifiable view as a Set. | public void | clear() | public boolean | contains(Object object) | public boolean | containsAll(Collection coll) | public static SetUniqueList | decorate(List list) Factory method to create a SetList using the supplied list to retain order. | public Iterator | iterator() | public ListIterator | listIterator() | public ListIterator | listIterator(int index) | public boolean | remove(Object object) | public Object | remove(int index) | public boolean | removeAll(Collection coll) | public boolean | retainAll(Collection coll) | public Object | set(int index, Object object) Sets the value at the specified index avoiding duplicates. | public List | subList(int fromIndex, int toIndex) |
set | final protected Set set(Code) | | Internal Set to maintain uniqueness.
|
SetUniqueList | protected SetUniqueList(List list, Set set)(Code) | | Constructor that wraps (not copies) the List and specifies the set to use.
The set and list must both be correctly initialised to the same elements.
Parameters: set - the set to decorate, must not be null Parameters: list - the list to decorate, must not be null throws: IllegalArgumentException - if set or list is null |
add | public boolean add(Object object)(Code) | | Adds an element to the list if it is not already present.
(Violation)
The List interface requires that this method returns
true always. However this class may return false
because of the Set behaviour.
Parameters: object - the object to add true if object was added |
add | public void add(int index, Object object)(Code) | | 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.
Parameters: index - the index to insert at Parameters: object - the object to add |
addAll | public boolean addAll(Collection coll)(Code) | | 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.
Parameters: coll - the collection to add |
addAll | public boolean addAll(int index, Collection coll)(Code) | | 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 List interface makes the assumption that the elements
are always inserted. This may not happen with this implementation.
Parameters: index - the index to insert at Parameters: coll - the collection to add in iterator order true if this collection changed |
asSet | public Set asSet()(Code) | | Gets an unmodifiable view as a Set.
an unmodifiable set view |
clear | public void clear()(Code) | | |
decorate | public static SetUniqueList decorate(List list)(Code) | | 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: IllegalArgumentException - if list is null |
set | public Object set(int index, Object object)(Code) | | 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.
Parameters: index - the index to insert at Parameters: object - the object to set the previous object |
subList | public List subList(int fromIndex, int toIndex)(Code) | | |
|
|