From 2113ddf9534f979f917e642baac932ce1ac69f83 Mon Sep 17 00:00:00 2001 From: alemoles Date: Mon, 30 Jan 2023 14:19:57 -0300 Subject: [PATCH] BAEL-5924 Java 8 Stream with Batch Processing Support (#13366) --- .../baeldung/streams/processing/CustomBatchIterator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/processing/CustomBatchIterator.java b/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/processing/CustomBatchIterator.java index b5407b7283..bfc7ffae3b 100644 --- a/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/processing/CustomBatchIterator.java +++ b/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/processing/CustomBatchIterator.java @@ -14,20 +14,20 @@ public class CustomBatchIterator implements Iterator> { private List currentBatch; private final Iterator iterator; - public CustomBatchIterator(Iterator sourceIterator, int batchSize) { + private CustomBatchIterator(Iterator sourceIterator, int batchSize) { this.batchSize = batchSize; this.iterator = sourceIterator; } @Override public List next() { + prepareNextBatch(); return currentBatch; } @Override public boolean hasNext() { - prepareNextBatch(); - return currentBatch != null && !currentBatch.isEmpty(); + return iterator.hasNext(); } public static Stream> batchStreamOf(Stream stream, int batchSize) {