Simplify DeviceFlowRegistryImpl streaming 80/82580/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 20 Jun 2019 10:12:01 +0000 (12:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Jun 2019 12:58:23 +0000 (14:58 +0200)
This patch takes advantage of Optional.ifPresent() and nonnullFoo()
methods to simplify the stream processing pipeline.

Change-Id: I9395a011fd7956d909b0b22d334aa9dcee601db6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java

index bd628ff9407383fd0b2faa75f0dff2db323d6ee6..77e5ae3e48e139e4bc8b7854f3145548dd1b2aa2 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -114,16 +113,14 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
         future.addCallback(new FutureCallback<Optional<FlowCapableNode>>() {
             @Override
             public void onSuccess(Optional<FlowCapableNode> result) {
-                result.map(Collections::singleton).orElse(Collections.emptySet()).stream()
-                        .filter(Objects::nonNull)
-                        .filter(flowCapableNode -> flowCapableNode.getTable() != null)
-                        .flatMap(flowCapableNode -> flowCapableNode.getTable().stream())
-                        .filter(Objects::nonNull)
-                        .filter(table -> table.getFlow() != null)
-                        .flatMap(table -> table.getFlow().stream())
-                        .filter(Objects::nonNull)
-                        .filter(flow -> flow.getId() != null)
-                        .forEach(flowConsumer);
+                result.ifPresent(flowCapableNode -> {
+                    flowCapableNode.nonnullTable().stream()
+                    .filter(Objects::nonNull)
+                    .flatMap(table -> table.nonnullFlow().stream())
+                    .filter(Objects::nonNull)
+                    .filter(flow -> flow.getId() != null)
+                    .forEach(flowConsumer);
+                });
             }
 
             @Override