Class BatchingIterator<T>

  • Type Parameters:
    T - element type
    All Implemented Interfaces:
    java.util.Iterator<java.util.Iterator<T>>

    public class BatchingIterator<T>
    extends com.google.common.collect.AbstractIterator<java.util.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 Summary

      Constructors 
      Constructor Description
      BatchingIterator​(java.util.Iterator<T> sourceIterator, java.util.function.Predicate<T> theBatchPredicate)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Iterator<T> computeNext()  
      static <T> java.util.Iterator<java.util.Iterator<T>> sized​(java.util.Iterator<T> source, int size)
      Return a BatchingIterator which creates fixed size batches.
      • Methods inherited from class com.google.common.collect.AbstractIterator

        endOfData, hasNext, next, peek
      • Methods inherited from class com.google.common.collect.UnmodifiableIterator

        remove
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • BatchingIterator

        public BatchingIterator​(java.util.Iterator<T> sourceIterator,
                                java.util.function.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 Detail

      • computeNext

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

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