Package com.apple.foundationdb.async
Interface AsyncPeekIterator<T>
-
- Type Parameters:
T
- type of elements returned by the scan
- All Superinterfaces:
AsyncIterator<T>
,Iterator<T>
- All Known Subinterfaces:
AsyncPeekCallbackIterator<T>
- All Known Implementing Classes:
BunchedMapIterator
,BunchedMapMultiIterator
@API(STABLE) public interface AsyncPeekIterator<T> extends AsyncIterator<T>
AAsyncPeekIterator
is an extension of theAsyncIterator
interface that adds peek semantics, i.e., viewing the next element of the iterator without advancing it forward. A conforming implementation should, much like a conformingAsyncIterator
implementation, should not be blocking in the case that one callsonHasNext()
and waits for that future to complete before calling eithernext()
orpeek()
. If one callsAsyncIterator.next()
immediately after apeek()
, both calls should return the same value.Conforming implementations do not necessarily need to be thread-safe.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description T
peek()
Get the next item of the scan without advancing it.static <T> AsyncPeekIterator<T>
wrap(AsyncIterator<T> iterator)
Wrap anAsyncIterator
with anAsyncPeekIterator
.-
Methods inherited from interface com.apple.foundationdb.async.AsyncIterator
cancel, hasNext, next, onHasNext
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Method Detail
-
peek
T peek() throws NoSuchElementException
Get the next item of the scan without advancing it. This item can be called multiple times, and it should return the same value each time as long as there are no intervening calls tonext()
.- Returns:
- the next item that will be returned by
next()
- Throws:
NoSuchElementException
- if there are no items remaining in the scan
-
wrap
static <T> AsyncPeekIterator<T> wrap(@Nonnull AsyncIterator<T> iterator)
Wrap anAsyncIterator
with anAsyncPeekIterator
. The returned scan iterator return the same sequence of elements as the suppliedAsyncIterator
instance in the same order. The wrapping implementation is free to advance the underlying iterator, so it is unsafe to modifyiterator
directly after calling this method. The returnediterator
is also not thread safe, so concurrent calls toonHasNext
, for example, may lead to unexpected behavior.- Type Parameters:
T
- type of items returned by the scan- Parameters:
iterator
-AsyncIterator
to wrap- Returns:
- an scan over the same values as
scan
that supports peek semantics
-
-