Class BatchingIterator<T>

java.lang.Object
com.google.common.collect.UnmodifiableIterator<Iterator<T>>
com.google.common.collect.AbstractIterator<Iterator<T>>
com.complexible.common.collect.BatchingIterator<T>
Type Parameters:
T - element type
All Implemented Interfaces:
Iterator<Iterator<T>>

public class BatchingIterator<T> extends com.google.common.collect.AbstractIterator<Iterator<T>>
An iterator which batches elements of the underlying iterator. This iterator iterates over batches (iterators) of the element type. Each returned iterator is one batch. Batches must be exhausted sequentially to avoid interfering with each other.
  • Constructor Details

    • BatchingIterator

      public BatchingIterator(Iterator<T> sourceIterator, Predicate<T> theBatchPredicate)
      Parameters:
      sourceIterator - underlying source iterator where elements will be taken from
      theBatchPredicate - a predicate indicating whether the element should be included in the current batch
  • Method Details

    • computeNext

      protected Iterator<T> computeNext()
      Specified by:
      computeNext in class com.google.common.collect.AbstractIterator<Iterator<T>>
    • sized

      public static <T> Iterator<Iterator<T>> sized(Iterator<T> source, int size)
      Return a BatchingIterator which creates fixed size batches.