com.google.common.collect
Class ForwardingListIterator<E>

java.lang.Object
  extended by com.google.common.collect.ForwardingObject
      extended by com.google.common.collect.ForwardingIterator<E>
          extended by com.google.common.collect.ForwardingListIterator<E>
All Implemented Interfaces:
Iterator<E>, ListIterator<E>

public abstract class ForwardingListIterator<E>
extends ForwardingIterator<E>
implements ListIterator<E>

A list iterator which forwards all its method calls to another list iterator. Subclasses should override one or more methods to modify the behavior of the backing iterator as desired per the decorator pattern.

Since:
2 (imported from Google Collections Library)
Author:
Mike Bostock

Constructor Summary
protected ForwardingListIterator()
          Constructor for use by subclasses.
 
Method Summary
 void add(E element)
          Inserts the specified element into the list (optional operation).
protected abstract  ListIterator<E> delegate()
          Returns the backing delegate instance that methods are forwarded to.
 boolean hasPrevious()
          Returns true if this list iterator has more elements when traversing the list in the reverse direction.
 int nextIndex()
          Returns the index of the element that would be returned by a subsequent call to ListIterator.next().
 E previous()
          Returns the previous element in the list and moves the cursor position backwards.
 int previousIndex()
          Returns the index of the element that would be returned by a subsequent call to ListIterator.previous().
 void set(E element)
          Replaces the last element returned by ListIterator.next() or ListIterator.previous() with the specified element (optional operation).
 
Methods inherited from class com.google.common.collect.ForwardingIterator
hasNext, next, remove
 
Methods inherited from class com.google.common.collect.ForwardingObject
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.ListIterator
hasNext, next, remove
 

Constructor Detail

ForwardingListIterator

protected ForwardingListIterator()
Constructor for use by subclasses.

Method Detail

delegate

protected abstract ListIterator<E> delegate()
Description copied from class: ForwardingObject
Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.

Specified by:
delegate in class ForwardingIterator<E>

add

public void add(E element)
Description copied from interface: java.util.ListIterator
Inserts the specified element into the list (optional operation). The element is inserted immediately before the next element that would be returned by ListIterator.next(), if any, and after the next element that would be returned by ListIterator.previous(), if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Specified by:
add in interface ListIterator<E>
Parameters:
element - the element to insert

hasPrevious

public boolean hasPrevious()
Description copied from interface: java.util.ListIterator
Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if ListIterator.previous() would return an element rather than throwing an exception.)

Specified by:
hasPrevious in interface ListIterator<E>
Returns:
true if the list iterator has more elements when traversing the list in the reverse direction

nextIndex

public int nextIndex()
Description copied from interface: java.util.ListIterator
Returns the index of the element that would be returned by a subsequent call to ListIterator.next(). (Returns list size if the list iterator is at the end of the list.)

Specified by:
nextIndex in interface ListIterator<E>
Returns:
the index of the element that would be returned by a subsequent call to next, or list size if the list iterator is at the end of the list

previous

public E previous()
Description copied from interface: java.util.ListIterator
Returns the previous element in the list and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to ListIterator.next() to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Specified by:
previous in interface ListIterator<E>
Returns:
the previous element in the list

previousIndex

public int previousIndex()
Description copied from interface: java.util.ListIterator
Returns the index of the element that would be returned by a subsequent call to ListIterator.previous(). (Returns -1 if the list iterator is at the beginning of the list.)

Specified by:
previousIndex in interface ListIterator<E>
Returns:
the index of the element that would be returned by a subsequent call to previous, or -1 if the list iterator is at the beginning of the list

set

public void set(E element)
Description copied from interface: java.util.ListIterator
Replaces the last element returned by ListIterator.next() or ListIterator.previous() with the specified element (optional operation). This call can be made only if neither ListIterator.remove() nor ListIterator.add(E) have been called after the last call to next or previous.

Specified by:
set in interface ListIterator<E>
Parameters:
element - the element with which to replace the last element returned by next or previous