net.sf.molae.pipe.basic
Class AbstractListIterator

java.lang.Object
  |
  +--net.sf.molae.pipe.basic.AbstractListIterator
All Implemented Interfaces:
Iterator, ListIterator
Direct Known Subclasses:
ListBasedListIterator

public abstract class AbstractListIterator
extends Object
implements ListIterator

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(Object o)
          This implementation always throws an UnsupportedOperationException.
protected  void forwardTo(int index)
          Calls next() until cursor equals specified index.
protected  Object 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.
 Object next()
          This implementation calls get() and increments the cursor.
 int nextIndex()
          This implementation returns the value of the cursor.
 Object 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(Object 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 ListIterator

get

protected Object 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 Object next()
This implementation calls get() and increments the cursor.
Specified by:
next in interface ListIterator
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
Returns:
true if the cursor is zero.

previous

public Object previous()
This implementation decrements the cursor and calls get().
Specified by:
previous in interface ListIterator
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

previousIndex

public int previousIndex()
This implementation returns the value of the cursor-1.
Specified by:
previousIndex in interface ListIterator

remove

public void remove()
This implementation always throws an UnsupportedOperationException.
Specified by:
remove in interface ListIterator

set

public void set(Object o)
This implementation always throws an UnsupportedOperationException.
Specified by:
set in interface ListIterator

add

public void add(Object o)
This implementation always throws an UnsupportedOperationException.
Specified by:
add in interface ListIterator