Top Description Fields Constructors Methods
com.google.common.collect

public abstract Class AbstractSequentialIterator<T>

extends UnmodifiableIterator<T>
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, java.util.NoSuchElementException, javax.annotation.CheckForNull

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 remove() method.

Example:

Iterator<Integer> powersOfTwo =
    new AbstractSequentialIterator<Integer>(1) {
      protected Integer computeNext(Integer previous) {
        return (previous == 1 << 30) ? null : previous * 2;
      }
    };
Author
Chris Povirk
Since
12.0 (in Guava as AbstractLinkedIterator since 8.0)

Field Summary

Modifier and TypeField and Description
private T

Constructor Summary

AccessConstructor and Description
protected
AbstractSequentialIterator(T firstOrNull)

Creates a new iterator with the given first element, or, if firstOrNull is null, creates a new empty iterator.

Method Summary

Modifier and TypeMethod and Description
protected abstract T
computeNext(T previous)

Returns the element that follows previous, or returns null if no elements remain.

public final boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public final T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
Inherited from com.google.common.collect.UnmodifiableIterator:
remove

Field Detail

nextOrNullback to summary
private T nextOrNull
Annotations
@CheckForNull

Constructor Detail

AbstractSequentialIteratorback to summary
protected AbstractSequentialIterator(T firstOrNull)

Creates a new iterator with the given first element, or, if firstOrNull is null, creates a new empty iterator.

Method Detail

computeNextback to summary
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().

Annotations
@CheckForNull
hasNextback to summary
public final boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public final T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the iteration

Annotations
@Override