Package ubic.basecode.util
Class BatchIterator<E>
java.lang.Object
ubic.basecode.util.BatchIterator<E>
- All Implemented Interfaces:
Iterable<Collection<E>>,Iterator<Collection<E>>
public class BatchIterator<E>
extends Object
implements Iterable<Collection<E>>, Iterator<Collection<E>>
Example usage:
Collection items;
int batchSize = 1000;
for ( Collection batch : BatchIterator.batches( items, batchSize ) ) {
}
or
Collection items;
int batchSize = 1000;
BatchIterator iterator = new BatchIterator( items, batchSize );
while ( iterator.hasNext() ) {
Collection batch = iterator.next();
}
- Author:
- luke
-
Constructor Summary
ConstructorsConstructorDescriptionBatchIterator(Collection<E> collection, int batchSize) Returns a BatchIterator over the specified collection. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> BatchIterator<E> batches(Collection<E> collection, int batchSize) Returns a BatchIterator over the specified collection.booleanhasNext()iterator()next()voidremove()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
BatchIterator
Returns a BatchIterator over the specified collection.- Parameters:
collection- the collection over which to iteratebatchSize- the maximum size of each batch returned
-
-
Method Details
-
batches
Returns a BatchIterator over the specified collection. This is a convenience method to simplify the code need to loop over an existing collection.- Parameters:
collection- the collection over which to iteratebatchSize- the maximum size of each batch returned- Returns:
- a BatchIterator over the specified collection
-
hasNext
public boolean hasNext() -
iterator
-
next
-
remove
public void remove()
-