From: Stephen Kitt Date: Tue, 16 May 2017 15:51:42 +0000 (+0200) Subject: sal-inmemory-datastore: use lambdas X-Git-Tag: release/nitrogen~236 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=a014c21dce3c024c1fb34ffdb419070ac26302f6 sal-inmemory-datastore: use lambdas 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 --- diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java index 1ba5015371..61ecf93732 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java @@ -60,14 +60,10 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype impl private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class); private static final Invoker, DOMImmutableDataChangeEvent> DCL_NOTIFICATION_MGR_INVOKER = - new Invoker, DOMImmutableDataChangeEvent>() { - @Override - public void invokeListener(final DataChangeListenerRegistration listener, - final DOMImmutableDataChangeEvent notification ) { - final AsyncDataChangeListener> inst = listener.getInstance(); - if (inst != null) { - inst.onDataChanged(notification); - } + (listener, notification) -> { + final AsyncDataChangeListener> inst = listener.getInstance(); + if (inst != null) { + inst.onDataChanged(notification); } }; diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java index 2f3b46366a..342dc0c35b 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java @@ -29,14 +29,11 @@ import org.slf4j.LoggerFactory; final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher { private static final Invoker, DataTreeCandidate> MANAGER_INVOKER = - new Invoker, 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); diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java index 8384dd8d1b..63e1498c0e 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java @@ -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); } } diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DefaultDataChangeListenerTestSuite.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DefaultDataChangeListenerTestSuite.java index af58f63331..c82fff3662 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DefaultDataChangeListenerTestSuite.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DefaultDataChangeListenerTestSuite.java @@ -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);