Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Use Stream API instead of explicit loop

Change-Id: I6ed6aba185a0ce3680fe0612de801a466a848d78
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 -import com.google.common.collect.ImmutableList;
19 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
...@@ -50,9 +49,9 @@ import java.util.Collection; ...@@ -50,9 +49,9 @@ import java.util.Collection;
50 import java.util.EnumSet; 49 import java.util.EnumSet;
51 import java.util.List; 50 import java.util.List;
52 import java.util.Map; 51 import java.util.Map;
52 +import java.util.Objects;
53 import java.util.Optional; 53 import java.util.Optional;
54 import java.util.concurrent.CompletableFuture; 54 import java.util.concurrent.CompletableFuture;
55 -import java.util.concurrent.ExecutionException;
56 import java.util.concurrent.ExecutorService; 55 import java.util.concurrent.ExecutorService;
57 import java.util.stream.Collectors; 56 import java.util.stream.Collectors;
58 57
...@@ -340,16 +339,15 @@ public class IntentManager ...@@ -340,16 +339,15 @@ public class IntentManager
340 } 339 }
341 340
342 private List<FinalIntentProcessPhase> waitForFutures(List<CompletableFuture<FinalIntentProcessPhase>> futures) { 341 private List<FinalIntentProcessPhase> waitForFutures(List<CompletableFuture<FinalIntentProcessPhase>> futures) {
343 - ImmutableList.Builder<FinalIntentProcessPhase> updateBuilder = ImmutableList.builder(); 342 + return futures.stream()
344 - for (CompletableFuture<FinalIntentProcessPhase> future : futures) { 343 + .map(x -> x.exceptionally(e -> {
345 - try { 344 + //FIXME
346 - updateBuilder.add(future.get()); 345 + log.warn("Future failed: {}", e);
347 - } catch (InterruptedException | ExecutionException e) { 346 + return null;
348 - //FIXME 347 + }))
349 - log.warn("Future failed: {}", e); 348 + .map(CompletableFuture::join)
350 - } 349 + .filter(Objects::nonNull)
351 - } 350 + .collect(Collectors.toList());
352 - return updateBuilder.build();
353 } 351 }
354 352
355 private void submitUpdates(List<FinalIntentProcessPhase> updates) { 353 private void submitUpdates(List<FinalIntentProcessPhase> updates) {
......