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();
}
| Constructor and Description |
|---|
BatchIterator(Collection<E> collection,
int batchSize)
Returns a BatchIterator over the specified collection.
|
| Modifier and Type | Method and 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() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorforEachRemainingpublic BatchIterator(Collection<E> collection, int batchSize)
collection - the collection over which to iteratebatchSize - the maximum size of each batch returnedpublic static <E> BatchIterator<E> batches(Collection<E> collection, int batchSize)
collection - the collection over which to iteratebatchSize - the maximum size of each batch returnedpublic boolean hasNext()
hasNext in interface Iterator<Collection<E>>public Iterator<Collection<E>> iterator()
iterator in interface Iterable<Collection<E>>public Collection<E> next()
next in interface Iterator<Collection<E>>public void remove()
remove in interface Iterator<Collection<E>>Copyright © 2003–2023 UBC Michael Smith Laboratories. All rights reserved.