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(UNSTABLE) public interface AsyncPeekIterator<T> extends AsyncIterator<T>
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 Details

    • 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 to next().
      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 an AsyncIterator with an AsyncPeekIterator. The returned scan iterator return the same sequence of elements as the supplied AsyncIterator instance in the same order. The wrapping implementation is free to advance the underlying iterator, so it is unsafe to modify iterator directly after calling this method. The returned iterator is also not thread safe, so concurrent calls to onHasNext, 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