[all packages]
[package java.util]
[class hierarchy]
[index]
java.lang.Object | +----java.util.AbstractCollection<A> | +----java.util.AbstractList<A> | +----java.util.AbstractSequentialList<A>
public abstract class AbstractSequentialList<A> extends AbstractList<A>
This class is the opposite of AbstractList in the sense that it implements the "random access" methods (get(int index), set(int index, Object element), set(int index, Object element), add(int index, Object element) and remove(int index)) on top of List's listIterator, instead of the other way around.
To implement a List the programmer needs only to extend this class and provide implementations for the listIterator and size methods. For an unmodifiable List, the programmer need only implement the listIterator's hasNext, next, hasPrevious, previous and index methods.
For a modifiable List the programmer should additionally implement the listIterator's set method. For a variable-size list the programmer should additionally implement the listIterator's remove and add methods.
The programmer should generally provide a void (no argument) and Collection constructor, as per the recommendation in the Collection interface specification.
public AbstractSequentialList();
get
public A get(int index);
This implementation first gets a ListIterator pointing to the indexed element (with listIterator(index)). Then, it gets the element using ListIterator.next and returns it.
public A set(int index, A element);
This implementation first gets a ListIterator pointing to the indexed element (with listIterator(index)). Then, it gets the current element using ListIterator.next and replaces it with ListIterator.set.
Note that this implementation will throw an UnsupportedOperationException if listIterator does not implement the set operation.
c
is null.public void add(int index, A element);
This implementation first gets a ListIterator pointing to the indexed element (with listIterator(index)). Then, it inserts the specified element with ListIterator.add.
Note that this implementation will throw an UnsupportedOperationException if listIterator does not implement the add operation.
c
is null.public A remove(int index);
This implementation first gets a ListIterator pointing to the indexed element (with listIterator(index)). Then, it removes the element with ListIterator.remove.
Note that this implementation will throw an UnsupportedOperationException if listIterator does not implement the remove operation.
public void removeRange(int fromIndex, int toIndex);
This implementation first checks to see that the indices are in range. Then, it gets a ListIterator pointing to the element at the beginning of the range (with listIterator(index)). Finally, it iterates over the range, calling ListIterator's remove operation for each element to be removed.
Note that this implementation will throw an UnsupportedOperationException if listIterator does not implement the remove operation.
public boolean addAll(int index, Collection<A> c);
This implementation gets an Iterator over the specified Collection and a ListIterator over this List pointing to the indexed element (with listIterator(index)). Then, it iterates over the specified Collection, inserting the elements obtained from the Iterator into this List, one at a time, using ListIterator.add followed by ListIterator.next (to skip over the added element).
Note that this implementation will throw an UnsupportedOperationException if the ListIterator returned by listIterator does not implement the add operation.
c
is null.public Iterator<A> iterator();
This implementation merely returns a ListIterator over the List.
public abstract ListIterator<A> listIterator(int index);
[all packages]
[package java.util]
[class hierarchy]
[index]