/java-utils

A collection of useful Java utilities

Primary LanguageJava

java-utils Build Status

A collection of useful Java utilities

Batch Collector

A stream collector that allows batch processing of elements with a given Consumer (batch processor).

Use the supplied utility class to get new instances:

List<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<Integer> output = new ArrayList<>();

int batchSize = 3;
Consumer<List<Integer>> batchProcessor = xs -> output.addAll(xs);

input.stream()
     .collect(StreamUtils.batchCollector(batchSize, batchProcessor));