BAEL-5924 Java 8 Stream with Batch Processing Support (#13366)
This commit is contained in:
parent
aab7f72429
commit
b40a061969
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue