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 -
Method Summary
Modifier and TypeMethodDescriptionCompletionStage<com.ibm.asyncutil.util.Either<com.ibm.asyncutil.iteration.AsyncIterator.End,T>> 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.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
-
-
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 usingpeek(), it will be returned immediately without consuming it from the underlying iterator.- Specified by:
nextStagein interfacecom.ibm.asyncutil.iteration.AsyncIterator<T>- Returns:
- A CompletionStage that resolves to either an End signal or the next element in the iterator.
-
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
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
-