@@ -0,0 +1,1085 @@
+package net.automatalib.commons.util.collections;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.NoSuchElementException;%0A%0A/**%0A * An iterator that aggregates elements of a given source iterator in batches of a given size. While elements are%0A * collected eagerly within a batch, the overall batches are computed lazily.%0A *%0A * The source iterator is consumed in this process.%0A *%0A * @param %3CT%3E type of elements to aggregate%0A *%0A * @author frohme%0A */%0Apublic class BatchingIterator%3CT%3E implements Iterator%3CList%3CT%3E%3E %7B%0A%0A%09private int batchSize;%0A%0A%09private Iterator%3CT%3E source;%0A%0A%09public BatchingIterator(final Iterator%3CT%3E source, final int batchSize) %7B%0A%09%09this.batchSize = batchSize;%0A%09%09this.source = source;%0A%09%7D%0A%0A%09@Override%0A%09public boolean hasNext() %7B%0A%09%09return source.hasNext();%0A%09%7D%0A%0A%09@Override%0A%09public List%3CT%3E next() %7B%0A%09%09if (!hasNext()) %7B%0A%09%09%09throw new NoSuchElementException();%0A%09%09%7D%0A%0A%09%09final List%3CT%3E result = new ArrayList%3C%3E(batchSize);%0A%0A%09%09while (source.hasNext() && result.size() %3C batchSize) %7B%0A%09%09%09result.add(source.next());%0A%09%09%7D%0A%0A%09%09return result;%0A%09%7D%0A%0A%7D

add batching iterator