|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractSet | +--javaslam.util.ListSet
A set implemented by a list, or equivalently, a list with no
duplicate elements. This class provides a simple implementation of
a set whose elements can be placed in an arbitrary order. (In
contrast, the elements of a SortedSet
are ordered based upon intrinsic properties of the objects.) This
class is implemented in terms of a backing list, and it will
support all of the methods supported by that list.
The notion of equality is different for sets and lists, and this
class adheres to the contract of Set
rather
than List
. In particular, this implies that
a List
and a ListSet
formed from it are
not equal. Such comparisons can be made correctly by
accessing the backing list via asList
.
Field Summary | |
protected List |
list
The underlying list. |
Constructor Summary | |
ListSet()
Constructor. |
|
ListSet(Collection c)
Constructor. |
|
ListSet(Object obj)
Constructor. |
|
ListSet(Object[] objs)
Constructor. |
Method Summary | |
void |
add(int index,
Object element)
Inserts the specified element at the specified position in this set (optional operation). |
boolean |
add(Object o)
Appends the specified element to the end of this set if it is not already in the set (optional operation). |
boolean |
addAll(Collection c)
Appends all of the elements in the specified collection to the end of this set, in the order that they are returned by the specified collection's iterator. |
boolean |
addAll(int index,
Collection c)
Inserts all of the elements in the specified collection into this set at the specified position (optional operation). |
List |
asList()
Returns an unmodifiable view of this set as a list. |
void |
clear()
Removes all of the elements from this set (optional operation). |
ListSet |
complement(Set other)
Creates an ordered set that is the complement of this set in the supplied set of objects. |
boolean |
contains(Object o)
Returns true if this set contains the specified element. |
boolean |
containsAll(Collection c)
Returns true if this set contains all of the elements of the specified collection. |
boolean |
containsAny(Collection c)
Returns true if this set contains any of the elements of the specified collection. |
Object |
get(int index)
Returns the element at the specified position in this set. |
int |
indexOf(Object o)
Returns the index in this set of the specified element, or -1 if this set does not contain this element. |
boolean |
isEmpty()
Returns true if this set contains no elements. |
Iterator |
iterator()
Returns an iterator over the elements in this set in proper sequence. |
int |
lastIndexOf(Object o)
Returns the index in this set of the specified element, or -1 if this set does not contain this element. |
ListIterator |
listIterator()
Returns a list iterator of the elements in this set (in proper sequence). |
ListIterator |
listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this set. |
Object |
remove(int index)
Removes the element at the specified position in this set (optional operation). |
boolean |
remove(Object o)
Removes the the specified element from this set (optional operation). |
boolean |
removeAll(Collection c)
Removes from this set all the elements that are contained in the specified collection (optional operation). |
boolean |
retainAll(Collection c)
Retains only the elements in this set that are contained in the specified collection (optional operation). |
Object |
set(int index,
Object element)
Replaces the element at the specified position in this set with the specified element (optional operation). |
int |
size()
Returns the number of elements in this set. |
List |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this set between the specified fromIndex, inclusive, and toIndex, exclusive. |
Object[] |
toArray()
Returns an array containing all of the elements in this set in proper sequence. |
Object[] |
toArray(Object[] a)
Returns an array containing all of the elements in this set in proper sequence; the runtime type of the returned array is that of the specified array. |
Methods inherited from class java.util.AbstractSet |
equals, hashCode |
Methods inherited from class java.util.AbstractCollection |
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 |
Field Detail |
protected List list
Constructor Detail |
public ListSet()
LinkedList
.
public ListSet(Object obj)
LinkedList
, and the set is initialized to contain the single
supplied object.
public ListSet(Object[] objs)
LinkedList
, and the set is initialized to contain the single
supplied object, and the set is initialized to contain the
elements of the supplied array (in order). Only the first
occurrence of each element is retained.
public ListSet(Collection c)
LinkedList
, and the set is initialized to contain the elements
of the supplied collection (in their iteration order). Only the
first occurrence of each element is retained.
Method Detail |
public List asList()
public int size()
size
in interface List
size
in class AbstractCollection
public boolean isEmpty()
isEmpty
in interface List
isEmpty
in class AbstractCollection
public boolean contains(Object o)
contains
in interface List
contains
in class AbstractCollection
o
- element whose presence in this set is to be tested.
public Iterator iterator()
iterator
in interface List
iterator
in class AbstractCollection
public Object[] toArray()
toArray
in interface List
toArray
in class AbstractCollection
public Object[] toArray(Object[] a)
toArray
in interface List
toArray
in class AbstractCollection
a
- the array into which the elements of this set are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
ArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in
this set.public boolean add(Object o)
add
in interface List
add
in class AbstractCollection
o
- element to be appended to this set.
true
if the element was added
UnsupportedOperationException
- if the add method is
not supported by the backing list.
ClassCastException
- if the class of an element in the specified
collection prevents it from being added to the backing list.
IllegalArgumentException
- if some aspect of an element in the
specified collection prevents it from being added to this
backing list.public boolean remove(Object o)
remove
in interface List
remove
in class AbstractCollection
o
- element to be removed from this set, if present.
UnsupportedOperationException
- if the remove method is
not supported by the backing list.public boolean containsAll(Collection c)
containsAll
in interface List
containsAll
in class AbstractCollection
c
- collection to be checked for containment in this set.
contains(Object)
public boolean containsAny(Collection c)
c
- collection to be checked for intersection in this set.
contains(Object)
public ListSet complement(Set other)
public boolean addAll(Collection c)
addAll
in interface List
addAll
in class AbstractCollection
c
- collection whose elements are to be added to this set.
UnsupportedOperationException
- if the add method is
not supported by the backing list.
ClassCastException
- if the class of an element in the specified
collection prevents it from being added to the backing list.
IllegalArgumentException
- if some aspect of an element in the
specified collection prevents it from being added to the
backing list.add(Object)
public boolean addAll(int index, Collection c)
addAll
in interface List
index
- index at which to insert first element from the specified
collection.c
- elements to be inserted into this set.
UnsupportedOperationException
- if the addAll method is
not supported by the backing list.
ClassCastException
- if the class of one of elements of the
specified collection prevents it from being added to the
backing list.
IllegalArgumentException
- if some aspect of one of elements of
the specified collection prevents it from being added to
the backing list.
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index > size()).public boolean removeAll(Collection c)
removeAll
in interface List
removeAll
in class AbstractSet
c
- collection that defines which elements will be removed from
this set.
UnsupportedOperationException
- if the removeAll method
is not supported by the backing list.remove(Object)
,
contains(Object)
public boolean retainAll(Collection c)
retainAll
in interface List
retainAll
in class AbstractCollection
c
- collection that defines which elements this set will retain.
UnsupportedOperationException
- if the retainAll method
is not supported by the backing list.remove(Object)
,
contains(Object)
public void clear()
clear
in interface List
clear
in class AbstractCollection
UnsupportedOperationException
- if the clear method is
not supported by the backing list.public Object get(int index)
get
in interface List
index
- index of element to return.
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public Object set(int index, Object element)
set
in interface List
index
- index of element to replace.element
- element to be stored at the specified position; this
element must not be currently in the set.
UnsupportedOperationException
- if the set method is not
supported by the backing list.
ClassCastException
- if the class of the specified element
prevents it from being added to the backing list.
IllegalArgumentException
- if the supplied element is already
in the set
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).public void add(int index, Object element)
add
in interface List
index
- index at which the specified element is to be inserted.element
- element to be inserted.
UnsupportedOperationException
- if the add method is not
supported by the backing list.
ClassCastException
- if the class of the specified element
prevents it from being added to the backing list.
IllegalArgumentException
- if the supplied element is already
in this set
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size()).public Object remove(int index)
remove
in interface List
index
- the index of the element to removed.
UnsupportedOperationException
- if the remove method is
not supported by the backing list.
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public int indexOf(Object o)
indexOf
in interface List
o
- element to search for.
public int lastIndexOf(Object o)
lastIndexOf
in interface List
o
- element to search for.
public ListIterator listIterator()
listIterator
in interface List
public ListIterator listIterator(int index)
listIterator
in interface List
index
- index of first element to be returned from the
list iterator (by a call to the next method).
IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index > size()).public List subList(int fromIndex, int toIndex)
subList
in interface List
fromIndex
- low endpoint (inclusive) of the subList.toIndex
- high endpoint (exclusive) of the subList.
IndexOutOfBoundsException
- for an illegal endpoint index value
(fromIndex < 0 || toIndex > size || fromIndex > toIndex).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |