Class PagingIterator<T>

java.lang.Object
com.github.basking2.sdsai.itrex.iterators.PagingIterator<T>
Type Parameters:
T - The type of elements to page.
All Implemented Interfaces:
Iterator<Iterator<T>>

public class PagingIterator<T> extends Object implements Iterator<Iterator<T>>
This iterator wraps its input iterator in HeadIterators until no elements remain in the source iterator. This structures the computation into pages of data. Users of this class must take care, all HeadIterator instances share the source iterator and calling them in parallel will yield unexpected results. A returned iterator should be exhausted before another is called.
  • Constructor Details

    • PagingIterator

      public PagingIterator(int pageSize, Iterator<T> iterator)
  • Method Details

    • hasNext

      public boolean hasNext()
      Returns true if the source iterator has more elements to be paged over. If the user is consuming an iterator returned by a call to next(), this may return inconsistent results.
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true if the source iterator has more elements to be paged over.
    • next

      public Iterator<T> next()
      Return a PagingIterator for the source iterator. The previously returned iterator must be empty.
      Specified by:
      next in interface Iterator<T>
      Returns:
      A HeadIterator that pages over elements of the input iterator.
      Throws:
      IllegalStateException - when the previously returned iterator is not fully consumed.