com.google.common.collect
Class ForwardingIterator<T>

java.lang.Object
  extended by com.google.common.collect.ForwardingIterator<T>
All Implemented Interfaces:
java.util.Iterator<T>
Direct Known Subclasses:
ForwardingListIterator

public abstract class ForwardingIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>

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

Unlike most Forwarding classes, this class does not implement Serializable, since iterators are rarely serialized.

Author:
Kevin Bourrillion
See Also:
ForwardingObject

Constructor Summary
protected ForwardingIterator(java.util.Iterator<T> delegate)
          Constructs a forwarding iterator that forwards to the provided delegate.
 
Method Summary
protected  java.util.Iterator<T> delegate()
          Returns the backing delegate object.
 boolean hasNext()
           
 T next()
           
 void remove()
           
 java.lang.String toString()
          Returns the string representation generated by the delegate's toString method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ForwardingIterator

protected ForwardingIterator(java.util.Iterator<T> delegate)
Constructs a forwarding iterator that forwards to the provided delegate.

Method Detail

delegate

protected java.util.Iterator<T> delegate()
Returns the backing delegate object. This method should be overridden to specify the correct return type. For example:
  @SuppressWarnings("unchecked")
  @Override protected Foo delegate() {
    return (Foo) super.delegate();
  }
This method should always return the same delegate instance that was passed to the constructor.


hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<T>

next

public T next()
Specified by:
next in interface java.util.Iterator<T>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<T>

toString

public java.lang.String toString()
Returns the string representation generated by the delegate's toString method.

Overrides:
toString in class java.lang.Object


Copyright © 2008 Google. All Rights Reserved.