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
Constructors Constructor Description BatchIterator(Collection<E> collection, int batchSize)
Returns a BatchIterator over the specified collection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <E> BatchIterator<E>
batches(Collection<E> collection, int batchSize)
Returns a BatchIterator over the specified collection.boolean
hasNext()
Iterator<Collection<E>>
iterator()
Collection<E>
next()
void
remove()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
BatchIterator
public BatchIterator(Collection<E> collection, int batchSize)
Returns a BatchIterator over the specified collection.- Parameters:
collection
- the collection over which to iteratebatchSize
- the maximum size of each batch returned
-
-
Method Detail
-
batches
public static <E> BatchIterator<E> batches(Collection<E> collection, int batchSize)
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
-
next
public Collection<E> next()
-
-