Simplify lambdas 81/77981/2
authorStephen Kitt <skitt@redhat.com>
Tue, 20 Nov 2018 13:16:08 +0000 (14:16 +0100)
committerStephen Kitt <skitt@redhat.com>
Tue, 20 Nov 2018 16:51:36 +0000 (17:51 +0100)
... where it makes the code more readable.

Change-Id: I96f312601e9619b7f5186f00c3e759d0faebcf84
Signed-off-by: Stephen Kitt <skitt@redhat.com>
15 files changed:
applications/forwardingrules-manager/src/test/java/test/mock/util/FRMTest.java
applications/notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/notification/supplier/impl/AbstractNotificationSupplierBase.java
applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/ReconciliationServiceImpl.java
applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/cli/Reconciliation.java
applications/topology-manager/src/test/java/org/opendaylight/openflowplugin/applications/topology/manager/TestUtils.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/AbstractOutboundQueueManager.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ChannelOutboundQueue.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java
openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/MockPlugin.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/initialization/OF10DeviceInitializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MatchUtil.java
samples/sample-bundles/src/main/java/org/opendaylight/openflowplugin/samples/sample/bundles/SampleFlowCapableNodeListener.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestCommiter.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java

index 02bcd1ee5411c7615be7168dafc47307c32e2768..fb2bceb2bf649dc7d09b9c3c242b0be30d5930c3 100644 (file)
@@ -100,10 +100,7 @@ public abstract class FRMTest extends AbstractDataBrokerTest {
     }
 
     protected Callable<Integer> listSize(List<?> list) {
-        return new Callable<Integer>() {
-            public Integer call() throws Exception {
-                return list.size(); // The condition supplier part
-            }
-        };
+        // The condition supplier part
+        return list::size;
     }
 }
index b6faa26f4c8ecc246efb5e3d655029d55172f0ac..937b00d360b3f56ed8e57795d44a01ff2a322b17 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowplugin.applications.notification.supplier.impl;
 
 import com.google.common.base.Preconditions;
-import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
@@ -62,12 +61,8 @@ public abstract class AbstractNotificationSupplierBase<O extends DataObject> imp
         SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
         try {
             listenerRegistration = looper
-                    .loopUntilNoException(new Callable<ListenerRegistration<DataTreeChangeListener<O>>>() {
-                        @Override
-                        public ListenerRegistration<DataTreeChangeListener<O>> call() throws Exception {
-                            return db.registerDataTreeChangeListener(treeId, AbstractNotificationSupplierBase.this);
-                        }
-                    });
+                    .loopUntilNoException(
+                        () -> db.registerDataTreeChangeListener(treeId, AbstractNotificationSupplierBase.this));
         } catch (final Exception ex) {
             LOG.debug("AbstractNotificationSupplierBase DataTreeChange listener registration fail ..{}",
                       ex.getMessage());
index 28e24c6d0f4317fd9f6655e563cb98d955db697d..93a0674238887457e0fe4e762732c9cfd208ce8c 100644 (file)
@@ -104,7 +104,7 @@ public class ReconciliationServiceImpl implements ReconciliationService, AutoClo
         SettableFuture<RpcResult<ReconcileOutput>> result = SettableFuture.create();
         List<Long> nodeList = getAllNodes();
         List<Long> nodesToReconcile = reconcileAllNodes ? nodeList :
-                inputNodes.stream().distinct().map(node -> node.longValue()).collect(Collectors.toList());
+                inputNodes.stream().distinct().map(BigInteger::longValue).collect(Collectors.toList());
         if (nodesToReconcile.size() > 0) {
             List<Long> unresolvedNodes =
                     nodesToReconcile.stream().filter(node -> !nodeList.contains(node)).collect(Collectors.toList());
@@ -160,7 +160,7 @@ public class ReconciliationServiceImpl implements ReconciliationService, AutoClo
 
     private List<Long> getAllNodes() {
         List<OFNode> nodeList = ShellUtil.getAllNodes(broker);
-        List<Long> nodes = nodeList.stream().distinct().map(node -> node.getNodeId()).collect(Collectors.toList());
+        List<Long> nodes = nodeList.stream().distinct().map(OFNode::getNodeId).collect(Collectors.toList());
         return nodes;
     }
 
index 02832b628bceb9d3149ee3b25e9f368a0fa3b8c1..8d12e992ab0e83bbdf4e0b6febb132b8fd5b7791 100644 (file)
@@ -47,7 +47,7 @@ public class Reconciliation extends OsgiCommandSupport {
     protected Object doExecute() throws Exception {
         List<BigInteger> nodes = (nodeIds == null)
                 ? new ArrayList<>()
-                : nodeIds.stream().distinct().map(node -> BigInteger.valueOf(node)).collect(Collectors.toList());
+                : nodeIds.stream().distinct().map(BigInteger::valueOf).collect(Collectors.toList());
         LOG.debug("Triggering reconciliation for nodes {}", nodes);
         ReconcileInput rpcInput = new ReconcileInputBuilder().setNodes(nodes)
                 .setReconcileAllNodes(reconcileAllNodes).build();
index 103320303dfbc6fe51f8064ec1efd3df034a72d3..1a4e60289da1c9d31ecb9952a6beb4bcc2a6ed6b 100644 (file)
@@ -65,13 +65,10 @@ public final class TestUtils {
     }
 
     static void setReadFutureAsync(final Topology topology, final SettableFuture<Optional<Topology>> readFuture) {
-        new Thread() {
-            @Override
-            public void run() {
-                Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
-                readFuture.set(Optional.of(topology));
-            }
-        }.start();
+        new Thread(() -> {
+            Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
+            readFuture.set(Optional.of(topology));
+        }).start();
     }
 
     static void waitForSubmit(CountDownLatch latch) {
index 2252ab58f36963c05b2040f3547e90f523f6e7f5..ebb170e6f371e55f71e2c9693ba17b38de3203e0 100644 (file)
@@ -79,7 +79,7 @@ abstract class AbstractOutboundQueueManager<T extends OutboundQueueHandler, O ex
     protected boolean shuttingDown;
 
     // Passed to executor to request triggering of flush
-    protected final Runnable flushRunnable = () -> flush();
+    protected final Runnable flushRunnable = this::flush;
 
     AbstractOutboundQueueManager(final ConnectionAdapterImpl parent, final InetSocketAddress address, final T handler) {
         this.parent = Preconditions.checkNotNull(parent);
index d9a30ffa9973df4dfde67442cf26133aaa2c0452..c2c8e244c0e5f8c19e79858ef771247c02576f37 100644 (file)
@@ -76,7 +76,7 @@ final class ChannelOutboundQueue extends ChannelInboundHandlerAdapter {
     private static final Logger LOG = LoggerFactory.getLogger(ChannelOutboundQueue.class);
 
     // Passed to executor to request triggering of flush
-    private final Runnable flushRunnable = () -> ChannelOutboundQueue.this.flush();
+    private final Runnable flushRunnable = ChannelOutboundQueue.this::flush;
 
     /*
      * Instead of using an AtomicBoolean object, we use these two. It saves us
index 1769facefa4f597c487dbfcb479e9ad13e01edaf..b0b2270c76a6d3516bd4e359425cfc1535be14c1 100644 (file)
@@ -29,12 +29,7 @@ final class OutboundQueueManager<T extends OutboundQueueHandler> extends
     private int nonBarrierMessages;
 
     // Passed to executor to request a periodic barrier check
-    private final Runnable barrierRunnable = new Runnable() {
-        @Override
-        public void run() {
-            barrier();
-        }
-    };
+    private final Runnable barrierRunnable = this::barrier;
 
     OutboundQueueManager(final ConnectionAdapterImpl parent, final InetSocketAddress address, final T handler,
         final int maxNonBarrierMessages, final long maxBarrierNanos) {
index cef1255a1ff8725b59bd81d7ac3639735755e659..3b87325a8b703016b9bee62f1f5b893ea4056303 100644 (file)
@@ -121,7 +121,7 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan
             HelloInput hi = hib.build();
             adapter.hello(hi);
             LOGGER.debug("hello msg sent");
-            new Thread(() -> getSwitchFeatures()).start();
+            new Thread(this::getSwitchFeatures).start();
         }).start();
 
     }
index 26e4d38f1baf838d3cd05de37d28127e760d57da..a7290f4cfe6f43400a9dc7ded629165eaac84d28 100644 (file)
@@ -45,6 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -156,14 +157,14 @@ public class OF10DeviceInitializer extends AbstractDeviceInitializer {
                     new SingleLayerMultipartCollectorService(deviceContext, deviceContext);
 
             return Futures.transform(service.handleServiceCall(multipartType),
-                input -> input.isSuccessful(), MoreExecutors.directExecutor());
+                RpcResult::isSuccessful, MoreExecutors.directExecutor());
         }
 
         final MultiLayerMultipartCollectorService service =
                 new MultiLayerMultipartCollectorService(deviceContext, deviceContext);
 
         return Futures.transform(service.handleServiceCall(multipartType),
-            input -> input.isSuccessful(), MoreExecutors.directExecutor());
+            RpcResult::isSuccessful, MoreExecutors.directExecutor());
     }
 
 }
index 99d37f41f7bb23d1fc42037ca34380dfd788df52..b0d6c14583d6658a582921ebd2bc1f79343704ca 100755 (executable)
@@ -174,16 +174,15 @@ public final class StatisticsGatheringUtils {
         }
 
         try {
-            Futures.transform(Futures.catchingAsync(future, Throwable.class, throwable -> {
-                return Futures.immediateFailedFuture(throwable);
-            }, MoreExecutors.directExecutor()), (Function<Optional<FlowCapableNode>, Void>) flowCapNodeOpt -> {
+            Futures.transform(Futures.catchingAsync(future, Throwable.class, Futures::immediateFailedFuture,
+                MoreExecutors.directExecutor()), (Function<Optional<FlowCapableNode>, Void>) flowCapNodeOpt -> {
                     // we have to read actual tables with all information before we set empty Flow list,
                     // merge is expensive and not applicable for lists
                     if (flowCapNodeOpt != null && flowCapNodeOpt.isPresent()) {
                         for (final Table tableData : flowCapNodeOpt.get().getTable()) {
                             final Table table = new TableBuilder(tableData).setFlow(Collections.emptyList()).build();
                             final InstanceIdentifier<Table> iiToTable = instanceIdentifier
-                                    .child(Table.class, tableData.key());
+                                .child(Table.class, tableData.key());
                             txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
                         }
                     }
index d388ed40743d2963ec3f9d63f1df4e027dd5f773..165f6aff5aac433baba3570a99b013f55724f98f 100644 (file)
@@ -47,13 +47,11 @@ public final class MatchUtil {
             .put(SetField.class, match -> {
                 final SetFieldBuilder matchBuilder = new SetFieldBuilder(match);
 
-                resolveExtensions(match).ifPresent(extensionLists -> {
-                    matchBuilder
-                            .addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
-                                    new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
-                                            .setExtensionList(extensionLists)
-                                            .build());
-                });
+                resolveExtensions(match).ifPresent(extensionLists -> matchBuilder
+                        .addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
+                                new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
+                                        .setExtensionList(extensionLists)
+                                        .build()));
 
                 return matchBuilder.build();
             })
index 83e5601ce238ee5717e65f4b1f5c2e54c2898347..b81f3ef005e15786ad778dfcd9809913bcd4502c 100644 (file)
@@ -175,10 +175,8 @@ public class SampleFlowCapableNodeListener implements ClusteredDataTreeChangeLis
                                 makeCompletableFuture(bundleService.controlBundle(commitBundleInput));
 
                         return controlCommitFuture;
-                    }).thenAccept(voidRpcResult -> {
-                        LOG.debug("Commit successful: {}, msg: {}", voidRpcResult.isSuccessful(),
-                                voidRpcResult.getErrors());
-                    });
+                    }).thenAccept(voidRpcResult -> LOG.debug("Commit successful: {}, msg: {}",
+                        voidRpcResult.isSuccessful(), voidRpcResult.getErrors()));
             }
         }
     }
index a9d199590ba43feac725bab7e32847a2080dac3a..cb0bf7478870506adbff1a12553da9d360071423 100644 (file)
@@ -42,24 +42,21 @@ public class DropTestCommiter extends AbstractDropTest {
 
     private static final AtomicLong ID_COUNTER = new AtomicLong();
 
-    private static final ThreadLocal<FlowBuilder> BUILDER = new ThreadLocal<FlowBuilder>() {
-        @Override
-        protected FlowBuilder initialValue() {
-            final FlowBuilder fb = new FlowBuilder();
-
-            fb.setPriority(PRIORITY);
-            fb.setBufferId(BUFFER_ID);
-            final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
-            fb.setCookie(cookie);
-            fb.setCookieMask(cookie);
-
-            fb.setTableId(TABLE_ID);
-            fb.setHardTimeout(HARD_TIMEOUT);
-            fb.setIdleTimeout(IDLE_TIMEOUT);
-            fb.setFlags(new FlowModFlags(false, false, false, false, false));
-            return fb;
-        }
-    };
+    private static final ThreadLocal<FlowBuilder> BUILDER = ThreadLocal.withInitial(() -> {
+        final FlowBuilder fb = new FlowBuilder();
+
+        fb.setPriority(PRIORITY);
+        fb.setBufferId(BUFFER_ID);
+        final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
+        fb.setCookie(cookie);
+        fb.setCookieMask(cookie);
+
+        fb.setTableId(TABLE_ID);
+        fb.setHardTimeout(HARD_TIMEOUT);
+        fb.setIdleTimeout(IDLE_TIMEOUT);
+        fb.setFlags(new FlowModFlags(false, false, false, false, false));
+        return fb;
+    });
 
     private NotificationService notificationService;
 
index 9e28ffad75583a57587622a12e9084598b2a3ca9..d11f5a85d28c316f30668c6b85e574a58b6e8150 100644 (file)
@@ -44,25 +44,22 @@ public class DropTestRpcSender extends AbstractDropTest {
         this.flowService = flowService;
     }
 
-    private static final ThreadLocal<AddFlowInputBuilder> BUILDER = new ThreadLocal<AddFlowInputBuilder>() {
-        @Override
-        protected AddFlowInputBuilder initialValue() {
-            final AddFlowInputBuilder fb = new AddFlowInputBuilder();
-
-            fb.setPriority(PRIORITY);
-            fb.setBufferId(BUFFER_ID);
-
-            final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
-            fb.setCookie(cookie);
-            fb.setCookieMask(cookie);
-            fb.setTableId(TABLE_ID);
-            fb.setHardTimeout(HARD_TIMEOUT);
-            fb.setIdleTimeout(IDLE_TIMEOUT);
-            fb.setFlags(new FlowModFlags(false, false, false, false, false));
-
-            return fb;
-        }
-    };
+    private static final ThreadLocal<AddFlowInputBuilder> BUILDER = ThreadLocal.withInitial(() -> {
+        final AddFlowInputBuilder fb = new AddFlowInputBuilder();
+
+        fb.setPriority(PRIORITY);
+        fb.setBufferId(BUFFER_ID);
+
+        final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
+        fb.setCookie(cookie);
+        fb.setCookieMask(cookie);
+        fb.setTableId(TABLE_ID);
+        fb.setHardTimeout(HARD_TIMEOUT);
+        fb.setIdleTimeout(IDLE_TIMEOUT);
+        fb.setFlags(new FlowModFlags(false, false, false, false, false));
+
+        return fb;
+    });
 
     private NotificationService notificationService;