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

java.lang.Object
  extended by com.google.common.collect.UnmodifiableIterator<T>
      extended by com.google.common.collect.AbstractLinkedIterator<T>
All Implemented Interfaces:
Iterator<T>

@Beta
@GwtCompatible
public abstract class AbstractLinkedIterator<T>
extends UnmodifiableIterator<T>

This class provides a skeletal implementation of the Iterator interface for sequences whose next element can always be derived from the previous element. Null elements are not supported, nor is the UnmodifiableIterator.remove() method.

Since:
8
Author:
Chris Povirk

Constructor Summary
protected AbstractLinkedIterator(T firstOrNull)
          Creates a new iterator with the given first element, or, if firstOrNull is null, creates a new empty iterator.
 
Method Summary
protected abstract  T computeNext(T previous)
          Returns the element that follows previous, or returns null if no elements remain.
 boolean hasNext()
          Returns true if the iteration has more elements.
 T next()
          Returns the next element in the iteration.
 
Methods inherited from class com.google.common.collect.UnmodifiableIterator
remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLinkedIterator

protected AbstractLinkedIterator(@Nullable
                                 T firstOrNull)
Creates a new iterator with the given first element, or, if firstOrNull is null, creates a new empty iterator.

Method Detail

computeNext

protected abstract T computeNext(T previous)
Returns the element that follows previous, or returns null if no elements remain. This method is invoked during each call to next() in order to compute the result of a future call to next().


hasNext

public final boolean hasNext()
Description copied from interface: java.util.Iterator
Returns true if the iteration has more elements. (In other words, returns true if Iterator.next() would return an element rather than throwing an exception.)

Returns:
true if the iteration has more elements

next

public final T next()
Description copied from interface: java.util.Iterator
Returns the next element in the iteration.

Returns:
the next element in the iteration