sal-inmemory-datastore: use lambdas 88/57188/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 May 2017 15:51:42 +0000 (17:51 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 16 May 2017 23:14:06 +0000 (23:14 +0000)
This series of patches uses lambdas instead of anonymous classes for
functional interfaces when possible. Lambdas are replaced with method
references when appropriate.

Change-Id: I3ed4fecf12d64254a3f3ec701ea22037e52149cc
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java
opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java
opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DefaultDataChangeListenerTestSuite.java

index 1ba5015..61ecf93 100644 (file)
@@ -60,14 +60,10 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class);
 
     private static final Invoker<DataChangeListenerRegistration<?>, DOMImmutableDataChangeEvent> DCL_NOTIFICATION_MGR_INVOKER =
-            new Invoker<DataChangeListenerRegistration<?>, DOMImmutableDataChangeEvent>() {
-                @Override
-                public void invokeListener(final DataChangeListenerRegistration<?> listener,
-                                           final DOMImmutableDataChangeEvent notification ) {
-                    final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> inst = listener.getInstance();
-                    if (inst != null) {
-                        inst.onDataChanged(notification);
-                    }
+            (listener, notification) -> {
+                final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> inst = listener.getInstance();
+                if (inst != null) {
+                    inst.onDataChanged(notification);
                 }
             };
 
index 2f3b463..342dc0c 100644 (file)
@@ -29,14 +29,11 @@ import org.slf4j.LoggerFactory;
 
 final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher {
     private static final Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> MANAGER_INVOKER =
-            new Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>() {
-                @Override
-                public void invokeListener(final AbstractDOMDataTreeChangeListenerRegistration<?> listener, final DataTreeCandidate notification) {
-                    // FIXME: this is inefficient, as we could grab the entire queue for the listener and post it
-                    final DOMDataTreeChangeListener inst = listener.getInstance();
-                    if (inst != null) {
-                        inst.onDataTreeChanged(Collections.singletonList(notification));
-                    }
+            (listener, notification) -> {
+                // FIXME: this is inefficient, as we could grab the entire queue for the listener and post it
+                final DOMDataTreeChangeListener inst = listener.getInstance();
+                if (inst != null) {
+                    inst.onDataTreeChanged(Collections.singletonList(notification));
                 }
             };
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreTreeChangePublisher.class);
index 8384dd8..63e1498 100644 (file)
@@ -169,32 +169,15 @@ public class DatastoreTestTask {
 
     public static final WriteTransactionCustomizer simpleWrite(final YangInstanceIdentifier path,
             final NormalizedNode<?, ?> data) {
-        return new WriteTransactionCustomizer() {
-
-            @Override
-            public void customize(final DOMStoreReadWriteTransaction tx) {
-                tx.write(path, data);
-            }
-        };
+        return tx -> tx.write(path, data);
     }
 
     public static final WriteTransactionCustomizer simpleMerge(final YangInstanceIdentifier path,
             final NormalizedNode<?, ?> data) {
-        return new WriteTransactionCustomizer() {
-
-            @Override
-            public void customize(final DOMStoreReadWriteTransaction tx) {
-                tx.merge(path, data);
-            }
-        };
+        return tx -> tx.merge(path, data);
     }
 
     public static final WriteTransactionCustomizer simpleDelete(final YangInstanceIdentifier path) {
-        return new WriteTransactionCustomizer() {
-            @Override
-            public void customize(final DOMStoreReadWriteTransaction tx) {
-                tx.delete(path);
-            }
-        };
+        return tx -> tx.delete(path);
     }
 }
index af58f63..c82fff3 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.controller.md.sal.dom.store.impl;
 import java.util.concurrent.ExecutionException;
 
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.store.impl.DatastoreTestTask.WriteTransactionCustomizer;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
 
 /**
  * Base template for a test suite for testing DataChangeListener functionality.
@@ -39,12 +37,7 @@ public abstract class DefaultDataChangeListenerTestSuite extends AbstractDataCha
     @Test
     public final void existingTopWriteSibling() throws Exception {
         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO)).test(
-                new WriteTransactionCustomizer() {
-                    @Override
-                    public void customize(final DOMStoreReadWriteTransaction tx) {
-                        tx.write(path(FOO_SIBLING), topLevelList(FOO_SIBLING).build());
-                    }
-                });
+                tx -> tx.write(path(FOO_SIBLING), topLevelList(FOO_SIBLING).build()));
         customizeTask(task);
         task.run();
         existingTopWriteSibling(task);
@@ -56,12 +49,9 @@ public abstract class DefaultDataChangeListenerTestSuite extends AbstractDataCha
     @Test
     public final void existingTopWriteTwoNested() throws Exception {
         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO)).test(
-                new WriteTransactionCustomizer() {
-                    @Override
-                    public void customize(final DOMStoreReadWriteTransaction tx) {
-                        tx.write(path(FOO,BAR), nestedList(BAR).build());
-                        tx.write(path(FOO,BAZ), nestedList(BAZ).build());
-                    }
+                tx -> {
+                    tx.write(path(FOO,BAR), nestedList(BAR).build());
+                    tx.write(path(FOO,BAZ), nestedList(BAZ).build());
                 });
         customizeTask(task);
         task.run();
@@ -74,12 +64,7 @@ public abstract class DefaultDataChangeListenerTestSuite extends AbstractDataCha
     @Test
     public final void existingOneNestedWriteAdditionalNested() throws Exception {
         DatastoreTestTask task = newTestTask().setup(writeOneTopMultipleNested(FOO, BAR)).test(
-                new WriteTransactionCustomizer() {
-                    @Override
-                    public void customize(final DOMStoreReadWriteTransaction tx) {
-                        tx.write(path(FOO,BAZ), nestedList(BAZ).build());
-                    }
-                });
+                tx -> tx.write(path(FOO,BAZ), nestedList(BAZ).build()));
         customizeTask(task);
         task.run();
         existingOneNestedWriteAdditionalNested(task);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.