Committed by
Gerrit Code Review
Refactor: Reduce number of invocations of Stream#collect()
Change-Id: Idde16505cbe0a1e56e2b651678a0169df0d06bf7
Showing
1 changed file
with
8 additions
and
9 deletions
... | @@ -54,6 +54,7 @@ import java.util.Optional; | ... | @@ -54,6 +54,7 @@ import java.util.Optional; |
54 | import java.util.concurrent.CompletableFuture; | 54 | import java.util.concurrent.CompletableFuture; |
55 | import java.util.concurrent.ExecutorService; | 55 | import java.util.concurrent.ExecutorService; |
56 | import java.util.stream.Collectors; | 56 | import java.util.stream.Collectors; |
57 | +import java.util.stream.Stream; | ||
57 | 58 | ||
58 | import static com.google.common.base.Preconditions.checkNotNull; | 59 | import static com.google.common.base.Preconditions.checkNotNull; |
59 | import static java.util.concurrent.Executors.newFixedThreadPool; | 60 | import static java.util.concurrent.Executors.newFixedThreadPool; |
... | @@ -339,26 +340,24 @@ public class IntentManager | ... | @@ -339,26 +340,24 @@ public class IntentManager |
339 | } | 340 | } |
340 | } | 341 | } |
341 | 342 | ||
342 | - private List<CompletableFuture<FinalIntentProcessPhase>> createIntentUpdates(Collection<IntentData> data) { | 343 | + private Stream<CompletableFuture<FinalIntentProcessPhase>> createIntentUpdates(Collection<IntentData> data) { |
343 | return data.stream() | 344 | return data.stream() |
344 | - .map(IntentManager.this::submitIntentData) | 345 | + .map(IntentManager.this::submitIntentData); |
345 | - .collect(Collectors.toList()); | ||
346 | } | 346 | } |
347 | 347 | ||
348 | - private List<FinalIntentProcessPhase> waitForFutures(List<CompletableFuture<FinalIntentProcessPhase>> futures) { | 348 | + private Stream<FinalIntentProcessPhase> waitForFutures(Stream<CompletableFuture<FinalIntentProcessPhase>> futures) { |
349 | - return futures.stream() | 349 | + return futures |
350 | .map(x -> x.exceptionally(e -> { | 350 | .map(x -> x.exceptionally(e -> { |
351 | //FIXME | 351 | //FIXME |
352 | log.warn("Future failed: {}", e); | 352 | log.warn("Future failed: {}", e); |
353 | return null; | 353 | return null; |
354 | })) | 354 | })) |
355 | .map(CompletableFuture::join) | 355 | .map(CompletableFuture::join) |
356 | - .filter(Objects::nonNull) | 356 | + .filter(Objects::nonNull); |
357 | - .collect(Collectors.toList()); | ||
358 | } | 357 | } |
359 | 358 | ||
360 | - private void submitUpdates(List<FinalIntentProcessPhase> updates) { | 359 | + private void submitUpdates(Stream<FinalIntentProcessPhase> updates) { |
361 | - store.batchWrite(updates.stream() | 360 | + store.batchWrite(updates |
362 | .map(FinalIntentProcessPhase::data) | 361 | .map(FinalIntentProcessPhase::data) |
363 | .collect(Collectors.toList())); | 362 | .collect(Collectors.toList())); |
364 | } | 363 | } | ... | ... |
-
Please register or login to post a comment