Package com.complexible.common.collect
Class BatchingIterator<T>
- java.lang.Object
-
- com.google.common.collect.UnmodifiableIterator<T>
-
- com.google.common.collect.AbstractIterator<java.util.Iterator<T>>
-
- com.complexible.common.collect.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 aBatchingIterator
which creates fixed size batches.-
Methods inherited from class com.google.common.collect.AbstractIterator
endOfData, hasNext, next, peek
-
-
-
-
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 fromtheBatchPredicate
- 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 classcom.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 aBatchingIterator
which creates fixed size batches.
-
-