Fix checkstyle violations in sal-inmemory-datastore
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / ResolveDataChangeState.java
index 6bbed57f392db63c647f704ef71a5d223384d60a..a644dca91d901cebda997c0f183eb57596887fdb 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -14,10 +17,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent.Builder;
-import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerNode;
+import org.opendaylight.mdsal.dom.spi.RegistrationTreeNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -27,11 +29,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Multimap;
-
 /**
  * Recursion state used in {@link ResolveDataChangeEventsTask}. Instances of this
  * method track which listeners are affected by a particular change node. It takes
@@ -40,16 +37,18 @@ import com.google.common.collect.Multimap;
  */
 final class ResolveDataChangeState {
     private static final Logger LOG = LoggerFactory.getLogger(ResolveDataChangeState.class);
+
     /**
-     * Inherited from all parents
+     * Inherited from all parents.
      */
     private final Iterable<Builder> inheritedSub;
+
     /**
-     * Inherited from immediate parent
+     * Inherited from immediate parent.
      */
     private final Collection<Builder> inheritedOne;
     private final YangInstanceIdentifier nodeId;
-    private final Collection<ListenerNode> nodes;
+    private final Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> nodes;
 
     private final Map<DataChangeListenerRegistration<?>, Builder> subBuilders;
     private final Map<DataChangeListenerRegistration<?>, Builder> oneBuilders;
@@ -57,7 +56,7 @@ final class ResolveDataChangeState {
 
     private ResolveDataChangeState(final YangInstanceIdentifier nodeId,
             final Iterable<Builder> inheritedSub, final Collection<Builder> inheritedOne,
-            final Collection<ListenerNode> nodes) {
+            final Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> nodes) {
         this.nodeId = Preconditions.checkNotNull(nodeId);
         this.nodes = Preconditions.checkNotNull(nodes);
         this.inheritedSub = Preconditions.checkNotNull(inheritedSub);
@@ -69,19 +68,21 @@ final class ResolveDataChangeState {
         final Map<DataChangeListenerRegistration<?>, Builder> sub = new HashMap<>();
         final Map<DataChangeListenerRegistration<?>, Builder> one = new HashMap<>();
         final Map<DataChangeListenerRegistration<?>, Builder> base = new HashMap<>();
-        for (ListenerNode n : nodes) {
-            for (DataChangeListenerRegistration<?> l : n.getListeners()) {
+        for (RegistrationTreeNode<DataChangeListenerRegistration<?>> n : nodes) {
+            for (DataChangeListenerRegistration<?> l : n.getRegistrations()) {
                 final Builder b = DOMImmutableDataChangeEvent.builder(DataChangeScope.BASE);
                 switch (l.getScope()) {
-                case BASE:
-                    base.put(l, b);
-                    break;
-                case ONE:
-                    one.put(l, b);
-                    break;
-                case SUBTREE:
-                    sub.put(l, b);
-                    break;
+                    case BASE:
+                        base.put(l, b);
+                        break;
+                    case ONE:
+                        one.put(l, b);
+                        break;
+                    case SUBTREE:
+                        sub.put(l, b);
+                        break;
+                    default:
+                        break;
                 }
             }
         }
@@ -102,12 +103,12 @@ final class ResolveDataChangeState {
      * Create an initial state handle at a particular root node.
      *
      * @param rootId root instance identifier
-     * @param root root node
-     * @return
+     * @param registrationTreeNode root node
      */
-    public static ResolveDataChangeState initial(final YangInstanceIdentifier rootId, final ListenerNode root) {
+    public static ResolveDataChangeState initial(final YangInstanceIdentifier rootId,
+            final RegistrationTreeNode<DataChangeListenerRegistration<?>> registrationTreeNode) {
         return new ResolveDataChangeState(rootId, Collections.<Builder>emptyList(),
-            Collections.<Builder>emptyList(), Collections.singletonList(root));
+            Collections.<Builder>emptyList(), Collections.singletonList(registrationTreeNode));
     }
 
     /**
@@ -153,7 +154,7 @@ final class ResolveDataChangeState {
     }
 
     /**
-     * Get the current path
+     * Get the current path.
      *
      * @return Current path.
      */
@@ -198,8 +199,6 @@ final class ResolveDataChangeState {
 
     /**
      * Add an event to all current listeners.
-     *
-     * @param event
      */
     public void addEvent(final DOMImmutableDataChangeEvent event) {
         // Subtree builders get always notified
@@ -257,13 +256,14 @@ final class ResolveDataChangeState {
         LOG.trace("Collected events {}", map);
     }
 
-    private static Collection<ListenerNode> getListenerChildrenWildcarded(final Collection<ListenerNode> parentNodes,
+    private static Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> getListenerChildrenWildcarded(
+            final Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> parentNodes,
             final PathArgument child) {
         if (parentNodes.isEmpty()) {
             return Collections.emptyList();
         }
 
-        final List<ListenerNode> result = new ArrayList<>();
+        final List<RegistrationTreeNode<DataChangeListenerRegistration<?>>> result = new ArrayList<>();
         if (child instanceof NodeWithValue || child instanceof NodeIdentifierWithPredicates) {
             NodeIdentifier wildcardedIdentifier = new NodeIdentifier(child.getNodeType());
             addChildNodes(result, parentNodes, wildcardedIdentifier);
@@ -272,11 +272,13 @@ final class ResolveDataChangeState {
         return result;
     }
 
-    private static void addChildNodes(final List<ListenerNode> result, final Collection<ListenerNode> parentNodes, final PathArgument childIdentifier) {
-        for (ListenerNode node : parentNodes) {
-            Optional<ListenerNode> child = node.getChild(childIdentifier);
-            if (child.isPresent()) {
-                result.add(child.get());
+    private static void addChildNodes(final List<RegistrationTreeNode<DataChangeListenerRegistration<?>>> result,
+            final Collection<RegistrationTreeNode<DataChangeListenerRegistration<?>>> parentNodes,
+            final PathArgument childIdentifier) {
+        for (RegistrationTreeNode<DataChangeListenerRegistration<?>> node : parentNodes) {
+            RegistrationTreeNode<DataChangeListenerRegistration<?>> child = node.getExactChild(childIdentifier);
+            if (child != null) {
+                result.add(child);
             }
         }
     }