All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.util.collections.AbstractSequentialList

java.lang.Object
   |
   +----com.sun.java.util.collections.AbstractCollection
           |
           +----com.sun.java.util.collections.AbstractList
                   |
                   +----com.sun.java.util.collections.AbstractSequentialList

public abstract class AbstractSequentialList
extends AbstractList
This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "sequential access" data store (such as a linked list). For random access data (such as an array), AbstractList should be used in preference to this Class.

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.

See Also:
Collection, List, AbstractList, AbstractCollection

Constructor Index

 o AbstractSequentialList()

Method Index

 o add(int, Object)
Inserts the specified element at the specified position in this List.
 o addAll(int, Collection)
Inserts all of the elements in in the specified Collection into this List at the specified position.
 o get(int)
Returns the element at the specified position in this List.
 o iterator()
Returns an iterator over the elements in this List (in proper sequence).
 o listIterator(int)
Returns a ListIterator over the elements in this List (in proper sequence).
 o remove(int)
Removes the element at the specified position in this List.
 o set(int, Object)
Replaces the element at the specified position in this List with the specified element.

Constructors

 o AbstractSequentialList
 public AbstractSequentialList()

Methods

 o get
 public Object get(int index)
Returns the element at the specified position in this List.

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.

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this List.
Throws: IndexOutOfBoundsException
index is out of range (index < 0 || index >= size()).
Overrides:
get in class AbstractList
 o set
 public Object set(int index,
                   Object element)
Replaces the element at the specified position in this List with the specified 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.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws: UnsupportedOperationException
set is not supported by this List.
Throws: NullPointerException
this List does not permit null elements and one of the elements of c is null.
Throws: ClassCastException
class of the specified element prevents it from being added to this List.
Throws: IllegalArgumentException
some aspect of the specified element prevents it from being added to this List.
Throws: IndexOutOfBoundsException
index out of range (index < 0 || index >= size()).
Throws: IllegalArgumentException
fromIndex > toIndex.
Overrides:
set in class AbstractList
 o add
 public void add(int index,
                 Object element)
Inserts the specified element at the specified position in this List. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

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.

Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws: UnsupportedOperationException
add is not supported by this List.
Throws: NullPointerException
this List does not permit null elements and one of the elements of c is null.
Throws: ClassCastException
class of the specified element prevents it from being added to this List.
Throws: IllegalArgumentException
some aspect of the specified element prevents it from being added to this List.
Throws: IndexOutOfBoundsException
index is out of range (index < 0 || index > size()).
Overrides:
add in class AbstractList
 o remove
 public 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).

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.

Parameters:
the - index of the element to be removed from the List.
index - the index of the element to removed.
Returns:
the element that was removed from the List.
Throws: UnsupportedOperationException
remove is not supported by this List.
Throws: IndexOutOfBoundsException
index out of range (index < 0 || index >= size()).
Overrides:
remove in class AbstractList
 o addAll
 public boolean addAll(int index,
                       Collection c)
Inserts all of the elements in in the specified Collection into this List at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the List in the order that they are returned by the specified Collection's iterator. The behavior of this operation is unspecified if the specified Collection is modified while the operation is in progress. (Note that this will occur if the specified Collection is this List, and it's nonempty.) Optional operation.

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.

Parameters:
index - index at which to insert first element from the specified collection.
c - elements to be inserted into this List.
Returns:
true if this List changed as a result of the call.
Throws: UnsupportedOperationException
addAll is not supported by this List.
Throws: NullPointerException
this List does not permit null elements and one of the elements of c is null.
Throws: ClassCastException
class of the specified element prevents it from being added to this List.
Throws: IllegalArgumentException
some aspect of the specified element prevents it from being added to this List.
Throws: IndexOutOfBoundsException
index out of range (index < 0 || index > size()).
Overrides:
addAll in class AbstractList
 o iterator
 public Iterator iterator()
Returns an iterator over the elements in this List (in proper sequence).

This implementation merely returns a ListIterator over the List.

Returns:
an iterator over the elements in this List (in proper sequence).
Overrides:
iterator in class AbstractList
 o listIterator
 public abstract ListIterator listIterator(int index)
Returns a ListIterator over the elements in this List (in proper sequence).

Returns:
a ListIterator over the elements in this List (in proper sequence).
Overrides:
listIterator in class AbstractList

All Packages  Class Hierarchy  This Package  Previous  Next  Index