java.util
public abstract class AbstractSequentialList<E> extends AbstractList<E>
get
, set
, add
, and
remove
) atop the list iterator, opposite of AbstractList's
approach of implementing the iterator atop random access.
To implement a list, you need an implementation for size()
and listIterator
. With just hasNext
,
next
, hasPrevious
, previous
,
nextIndex
, and previousIndex
, you have an
unmodifiable list. For a modifiable one, add set
, and for
a variable-size list, add add
and remove
.
The programmer should provide a no-argument constructor, and one that accepts another Collection, as recommended by the Collection interface. Unfortunately, there is no way to enforce this in Java.
Since: 1.2
See Also: Collection List AbstractList AbstractCollection ListIterator LinkedList
UNKNOWN: updated to 1.4
Constructor Summary | |
---|---|
protected | AbstractSequentialList()
The main constructor, for use by subclasses. |
Method Summary | |
---|---|
void | add(int index, E o)
Insert an element into the list at a given position (optional operation).
|
boolean | addAll(int index, Collection<? extends E> c)
Insert the contents of a collection into the list at a given position
(optional operation). |
E | get(int index)
Get the element at a given index in this list. |
Iterator<E> | iterator()
Obtain an Iterator over this list, whose sequence is the list order. |
abstract ListIterator<E> | listIterator(int index)
Returns a ListIterator over the list, starting from position index.
|
E | remove(int index)
Remove the element at a given position in this list (optional operation).
|
E | set(int index, E o)
Replace an element of this list with another object (optional operation).
|
Parameters: index the location to insert the item o the object to insert
Throws: UnsupportedOperationException if this list does not support the add operation IndexOutOfBoundsException if index < 0 || index > size() ClassCastException if o cannot be added to this list due to its type IllegalArgumentException if o cannot be added to this list for some other reason. NullPointerException if o is null and the list does not permit the addition of null values.
This implementation grabs listIterator(index), then proceeds to use add for each element returned by c's iterator. Sun's online specs are wrong, claiming that this also calls next(): listIterator.add() correctly skips the added element.
Parameters: index the location to insert the collection c the collection to insert
Returns: true if the list was modified by this action, that is, if c is non-empty
Throws: UnsupportedOperationException if this list does not support the addAll operation IndexOutOfBoundsException if index < 0 || index > size() ClassCastException if some element of c cannot be added to this list due to its type IllegalArgumentException if some element of c cannot be added to this list for some other reason NullPointerException if the specified collection is null NullPointerException if an object, o, in c is null and the list does not permit the addition of null values.
See Also: AbstractSequentialList
Parameters: index the index of the element to be returned
Returns: the element at index index in this list
Throws: IndexOutOfBoundsException if index < 0 || index >= size()
Returns: an Iterator over the elements of this list, in order
Parameters: index the starting position of the list
Returns: the list iterator
Throws: IndexOutOfBoundsException if index < 0 || index > size()
Parameters: index the position within the list of the object to remove
Returns: the object that was removed
Throws: UnsupportedOperationException if this list does not support the remove operation IndexOutOfBoundsException if index < 0 || index >= size()
Parameters: index the position within this list of the element to be replaced o the object to replace it with
Returns: the object that was replaced
Throws: UnsupportedOperationException if this list does not support the set operation IndexOutOfBoundsException if index < 0 || index >= size() ClassCastException if o cannot be added to this list due to its type IllegalArgumentException if o cannot be added to this list for some other reason NullPointerException if o is null and the list does not allow a value to be set to null.