Overview | Package | Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractList | +--java.util.AbstractSequentialList
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.
Fields inherited from class java.util.AbstractList | |
modCount |
Constructor Summary | |
AbstractSequentialList()
|
Method Summary | |
void | add(int index,
java.lang.Object element)
Inserts the specified element at the specified position in this List. |
boolean | addAll(int index,
Collection c)
Inserts all of the elements in in the specified Collection into this List at the specified position. |
java.lang.Object | get(int index)
Returns the element at the specified position in this List. |
Iterator | iterator()
Returns an iterator over the elements in this List (in proper sequence). |
ListIterator | listIterator(int index)
Returns a ListIterator over the elements in this List (in proper sequence). |
java.lang.Object | remove(int index)
Removes the element at the specified position in this List. shifts any subsequent elements to the left (subtracts one from their indices). |
java.lang.Object | set(int index,
java.lang.Object element)
Replaces the element at the specified position in this List with the specified element. |
Methods inherited from class java.util.AbstractList | |
add, add, addAll, equals, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, set, subList |
Methods inherited from class java.util.AbstractCollection | |
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object | |
Constructor Detail |
public AbstractSequentialList()
Method Detail |
public java.lang.Object 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.
index
- index of element to return.public java.lang.Object set(int index, java.lang.Object 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.
index
- index of element to replace.
element
- element to be stored at the specified position.c
is null.public void add(int index, java.lang.Object 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.
index
- index at which the specified element is to be inserted.
element
- element to be inserted.c
is null.public java.lang.Object 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.
index
- the index of the element to removed.public boolean addAll(int index, Collection 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.
index
- index at which to insert first element
from the specified collection.
c
- elements to be inserted into this List.c
is null.public Iterator iterator()
This implementation merely returns a ListIterator over the List.
public abstract ListIterator listIterator(int index)
Overview | Package | Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |