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
A
AsyncPeekIterator
is an extension of the AsyncIterator
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 conforming AsyncIterator
implementation, should not be blocking in the
case that one calls onHasNext()
and waits
for that future to complete before calling either next()
or peek()
. If one calls AsyncIterator.next()
immediately
after a peek()
, both calls should return the same value.
Conforming implementations do not necessarily need to be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionpeek()
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 Details
-
peek
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
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
-