Skip to content

Commit

Permalink
#325: Fuse toArray into Stream chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
heshamMassoud committed Nov 24, 2018
1 parent c275a52 commit 325ed1d
Showing 1 changed file with 5 additions and 7 deletions.
Expand Up @@ -98,13 +98,11 @@ protected CompletionStage<InventorySyncStatistics> process(@Nonnull final List<I
final List<InventoryEntryDraft> validInventories = inventories.stream()
.filter(this::validateDraft)
.collect(toList());
final List<CompletableFuture<InventorySyncStatistics>> completableFutures = IntStream
.range(0, calculateNumberOfBatches(validInventories.size()))
.mapToObj(batchIndex -> getBatch(batchIndex, validInventories))
.map(this::processBatch)
.map(CompletionStage::toCompletableFuture)
.collect(toList());
return allOf(completableFutures.toArray(new CompletableFuture[completableFutures.size()]))
return allOf(IntStream
.range(0, calculateNumberOfBatches(validInventories.size()))
.mapToObj(batchIndex -> getBatch(batchIndex, validInventories))
.map(this::processBatch)
.map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new))
.thenApply(v -> {
statistics.incrementProcessed(inventories.size());
return statistics;
Expand Down

0 comments on commit 325ed1d

Please sign in to comment.