|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
public abstract class AbstractSequentialList<E>
Abstract superclass to make it easier to implement the List interface when
backed by a sequential-access store, such as a linked list. For random
access data, use AbstractList. This class implements the random access
methods (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.
Collection,
List,
AbstractList,
AbstractCollection,
ListIterator,
LinkedList| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| 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). |
| Methods inherited from class java.util.AbstractList |
|---|
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray |
| Constructor Detail |
|---|
protected AbstractSequentialList()
| Method Detail |
|---|
public abstract ListIterator<E> listIterator(int index)
listIterator in interface List<E>listIterator in class AbstractList<E>index - the starting position of the list
IndexOutOfBoundsException - if index < 0 || index > size()AbstractList.modCount
public void add(int index,
E o)
add in interface List<E>add in class AbstractList<E>index - the location to insert the itemo - the object to insert
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.AbstractList.modCount
public boolean addAll(int index,
Collection<? extends E> c)
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.
addAll in interface List<E>addAll in class AbstractList<E>index - the location to insert the collectionc - the collection to insert
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.add(int, Object)public E get(int index)
get in interface List<E>get in class AbstractList<E>index - the index of the element to be returned
IndexOutOfBoundsException - if index < 0 || index >= size()public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface List<E>iterator in class AbstractList<E>AbstractList.modCountpublic E remove(int index)
remove in interface List<E>remove in class AbstractList<E>index - the position within the list of the object to remove
UnsupportedOperationException - if this list does not support the
remove operation
IndexOutOfBoundsException - if index < 0 || index >= size()AbstractList.modCount
public E set(int index,
E o)
set in interface List<E>set in class AbstractList<E>index - the position within this list of the element to be replacedo - the object to replace it with
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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||