net.sf.molae.pipe.basic
Class AbstractListIterator<E>

java.lang.Object
  extended by net.sf.molae.pipe.basic.AbstractListIterator<E>
All Implemented Interfaces:
Iterator<E>, ListIterator<E>
Direct Known Subclasses:
ListBasedListIterator

public abstract class AbstractListIterator<E>
extends Object
implements ListIterator<E>

This class provides a skeletal implementation of the ListIterator interface, to minimize the effort required to implement this interface. It provides an int property that stores the index of the actual cursor position. For immutable lists only hasNext() and get() have to be implemented. Instead of get(), next() and previous() can be implemented directly. For mutable lists use ListBasedListIterator.


Constructor Summary
AbstractListIterator()
           
 
Method Summary
 void add(E o)
          This implementation always throws an UnsupportedOperationException.
protected  void forwardTo(int index)
          Calls next() until cursor equals specified index.
protected  E get()
          This method can be used as a common body for next() and previous().
abstract  boolean hasNext()
           
 boolean hasPrevious()
          Tests if the value of the cursor is zero.
 E next()
          This implementation calls get() and increments the cursor.
 int nextIndex()
          This implementation returns the value of the cursor.
 E previous()
          This implementation decrements the cursor and calls get().
 int previousIndex()
          This implementation returns the value of the cursor-1.
 void remove()
          This implementation always throws an UnsupportedOperationException.
 void set(E o)
          This implementation always throws an UnsupportedOperationException.
protected  void setCursor(int newCursor)
          Replaces the value of the cursor with the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractListIterator

public AbstractListIterator()
Method Detail

setCursor

protected final void setCursor(int newCursor)
Replaces the value of the cursor with the specified value. It does not call any other methods. To advance the cursor use forwardTo(int).

Parameters:
newCursor - new value of the underlying cursor

forwardTo

protected void forwardTo(int index)
Calls next() until cursor equals specified index. Used for starting at a specific position.

Parameters:
index - index of first element to be returned from the list iterator (by a call to the next method).
Throws:
IndexOutOfBoundsException - if index < 0 || index > size().

hasNext

public abstract boolean hasNext()
Specified by:
hasNext in interface Iterator<E>
Specified by:
hasNext in interface ListIterator<E>

get

protected E get()
This method can be used as a common body for next() and previous(). Return the object at current cursor position.

Returns:
the object at current cursor position.

next

public E next()
This implementation calls get() and increments the cursor.

Specified by:
next in interface Iterator<E>
Specified by:
next in interface ListIterator<E>
Throws:
NoSuchElementException - if the iteration has no next element.

hasPrevious

public boolean hasPrevious()
Tests if the value of the cursor is zero.

Specified by:
hasPrevious in interface ListIterator<E>
Returns:
true if the cursor is zero.

previous

public E previous()
This implementation decrements the cursor and calls get().

Specified by:
previous in interface ListIterator<E>
Throws:
NoSuchElementException - if the iteration has no previous element.

nextIndex

public int nextIndex()
This implementation returns the value of the cursor.

Specified by:
nextIndex in interface ListIterator<E>

previousIndex

public int previousIndex()
This implementation returns the value of the cursor-1.

Specified by:
previousIndex in interface ListIterator<E>

remove

public void remove()
This implementation always throws an UnsupportedOperationException.

Specified by:
remove in interface Iterator<E>
Specified by:
remove in interface ListIterator<E>

set

public void set(E o)
This implementation always throws an UnsupportedOperationException.

Specified by:
set in interface ListIterator<E>

add

public void add(E o)
This implementation always throws an UnsupportedOperationException.

Specified by:
add in interface ListIterator<E>