Simplify AbstractDOMBroker.isSupported() 64/71564/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Apr 2018 08:18:38 +0000 (10:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Apr 2018 08:18:38 +0000 (10:18 +0200)
This is simple check if all datastore are instances of the specified
contract -- simplify the expression with Streams.allMatch()
and Class.isInstance().

Change-Id: I260d3b2296f085023a722c3f59e08c4926e91b2d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBroker.java

index e3b1c30..799e94a 100644 (file)
@@ -62,7 +62,7 @@ public abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory<DO
             extBuilder.put(DOMDataTreeCommitCohortRegistry.class, new DOMDataTreeCommitCohortRegistry() {
                 @Override
                 public <T extends DOMDataTreeCommitCohort> DOMDataTreeCommitCohortRegistration<T> registerCommitCohort(
-                        DOMDataTreeIdentifier path, T cohort) {
+                        final DOMDataTreeIdentifier path, final T cohort) {
                     DOMStore store = getDOMStore(path.getDatastoreType());
                     return ((DOMDataTreeCommitCohortRegistry) store).registerCommitCohort(path, cohort);
                 }
@@ -72,15 +72,9 @@ public abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory<DO
         extensions = extBuilder.build();
     }
 
-    private static boolean isSupported(Map<LogicalDatastoreType, DOMStore> datastores,
-            Class<?> expDOMStoreInterface) {
-        for (DOMStore ds : datastores.values()) {
-            if (!expDOMStoreInterface.isAssignableFrom(ds.getClass())) {
-                return false;
-            }
-        }
-
-        return true;
+    private static boolean isSupported(final Map<LogicalDatastoreType, DOMStore> datastores,
+            final Class<?> expDOMStoreInterface) {
+        return datastores.values().stream().allMatch(expDOMStoreInterface::isInstance);
     }
 
     public void setCloseable(final AutoCloseable closeable) {

©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.