Package com.ocient.util

# Class Iterators.PeekingAsyncIterator<T>

java.lang.Object
com.ocient.util.Iterators.PeekingAsyncIterator<T>

Type Parameters:
  `T` - The type of elements in the iterator.

All Implemented Interfaces:
  `com.ibm.asyncutil.iteration.AsyncIterator<T>`, `com.ibm.asyncutil.util.AsyncCloseable`

Enclosing class:
  `Iterators`

public static class Iterators.PeekingAsyncIterator<T> extends Object implements com.ibm.asyncutil.iteration.AsyncIterator<T>
An implementation of the `AsyncIterator` interface that allows peeking at the next element without consuming it from the underlying iterator.

## Nested Class Summary

## Nested classes/interfaces inherited from interface com.ibm.asyncutil.iteration.AsyncIterator

`com.ibm.asyncutil.iteration.AsyncIterator.End`

## Constructor Summary

Constructors
Constructor
Description
`PeekingAsyncIterator(com.ibm.asyncutil.iteration.AsyncIterator<T> delegate)`

## Method Summary

Modifier and Type
Method
Description
`CompletionStage<com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,T>>`
`nextStage()`
Retrieves the next element in the iterator asynchronously.
`final com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,T>`
`peek()`
Peeks at the next element in the iterator without consuming it.
`final CompletionStage<Void>`
`prefetch()`
Prefetches the next element from the underlying iterator and stores it for peeking without consuming it.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface com.ibm.asyncutil.iteration.AsyncIterator

`batch, batch, close, collect, collect, consume, exceptionally, filter, filterApply, filterCompose, find, fold, fold, forEach, fuse, take, takeWhile, thenApply, thenApplyAsync, thenApplyAsync, thenCompose, thenComposeAhead, thenComposeAsync, thenComposeAsync, thenFlatten, thenFlattenAhead`

## Constructor Details

### PeekingAsyncIterator

public PeekingAsyncIterator(com.ibm.asyncutil.iteration.AsyncIterator<T> delegate)

## Method Details

### nextStage

public CompletionStage<com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,T>> nextStage()
Retrieves the next element in the iterator asynchronously. If an element has been peeked using `peek()`, it will be returned immediately without consuming it from the underlying iterator.

Specified by:
  `nextStage` in interface `com.ibm.asyncutil.iteration.AsyncIterator<T>`
Returns:
  A CompletionStage that resolves to either an End signal or the next element in the iterator.

### prefetch

public final CompletionStage<Void> prefetch()
Prefetches the next element from the underlying iterator and stores it for peeking without consuming it.

Returns:
  A CompletionStage that resolves to void when the prefetch is complete.

### peek

public final com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,T> peek()
Peeks at the next element in the iterator without consuming it. If there is no element to peek, an IllegalStateException is thrown.

Returns:
  The next element in the iterator.
Throws:
  `IllegalStateException` - if there is no element to peek.

### toString

public String toString()

Overrides:
  `toString` in class `Object`