BAEL-5924 Java 8 Stream with Batch Processing Support (#13366)

This commit is contained in:
alemoles 2023-01-30 14:19:57 -03:00 committed by GitHub
parent aab7f72429
commit b40a061969
1 changed files with 3 additions and 3 deletions

View File

@ -14,20 +14,20 @@ public class CustomBatchIterator<T> implements Iterator<List<T>> {
private List<T> currentBatch; private List<T> currentBatch;
private final Iterator<T> iterator; private final Iterator<T> iterator;
public CustomBatchIterator(Iterator<T> sourceIterator, int batchSize) { private CustomBatchIterator(Iterator<T> sourceIterator, int batchSize) {
this.batchSize = batchSize; this.batchSize = batchSize;
this.iterator = sourceIterator; this.iterator = sourceIterator;
} }
@Override @Override
public List<T> next() { public List<T> next() {
prepareNextBatch();
return currentBatch; return currentBatch;
} }
@Override @Override
public boolean hasNext() { public boolean hasNext() {
prepareNextBatch(); return iterator.hasNext();
return currentBatch != null && !currentBatch.isEmpty();
} }
public static <T> Stream<List<T>> batchStreamOf(Stream<T> stream, int batchSize) { public static <T> Stream<List<T>> batchStreamOf(Stream<T> stream, int batchSize) {