Added getModifiedChild to DataTreeCandidateNode. 81/14281/2
authorTony Tkacik <ttkacik@cisco.com>
Tue, 20 Jan 2015 09:37:22 +0000 (10:37 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 21 Jan 2015 10:18:32 +0000 (11:18 +0100)
Change-Id: I2e1466d8ef903de2b87a36c49b0b5deba9de9ad8
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTreeCandidateNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeCandidate.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NoopDataTreeCandidate.java

index 76f3f563cd8596544121258c8e390a6820501fc3..4a8ced9be79421fcc04fa63418336f3cd82aa2c1 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema.tree;
 
+import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
-import com.google.common.base.Optional;
-
 /**
  * A single node within a {@link DataTreeCandidate}. The nodes are organized
  * in tree hierarchy, reflecting the modification from which this candidate
@@ -19,26 +20,36 @@ import com.google.common.base.Optional;
  * tree restricted to the modified nodes.
  */
 public interface DataTreeCandidateNode {
+
     /**
      * Get the node identifier.
      *
      * @return The node identifier.
      */
-    PathArgument getIdentifier();
+    @Nonnull PathArgument getIdentifier();
 
     /**
      * Get an unmodifiable iterable of modified child nodes.
      *
      * @return Unmodifiable iterable of modified child nodes.
      */
-    Iterable<DataTreeCandidateNode> getChildNodes();
+    @Nonnull Iterable<DataTreeCandidateNode> getChildNodes();
+
+    /**
+     * Returns modified child or null if child was not modified
+     * / does not exists.
+     *
+     * @param identifier Identifier of child node
+     * @return Modified child or null if child was not modified.
+     */
+    @Nullable DataTreeCandidateNode getModifiedChild(PathArgument identifier);
 
     /**
      * Return the type of modification this node is undergoing.
      *
      * @return Node modification type.
      */
-    ModificationType getModificationType();
+    @Nonnull ModificationType getModificationType();
 
     /**
      * Return the before-image of data corresponding to the node.
index 45227c88b549cce7a4395cfe964df8e56e4cd90e..94387be4a278f06cb7a9df91bc0099868627dd33 100644 (file)
@@ -51,13 +51,17 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
             }
         }
 
+        private DataTreeCandidateNode childNode(final ModifiedNode input) {
+            final PathArgument id = input.getIdentifier();
+            return new ChildNode(input, childMeta(oldMeta, id), childMeta(newMeta, id));
+        }
+
         @Override
         public Iterable<DataTreeCandidateNode> getChildNodes() {
             return Iterables.transform(mod.getChildren(), new Function<ModifiedNode, DataTreeCandidateNode>() {
                 @Override
                 public DataTreeCandidateNode apply(final ModifiedNode input) {
-                    final PathArgument id = input.getIdentifier();
-                    return new ChildNode(input, childMeta(oldMeta, id), childMeta(newMeta, id));
+                    return childNode(input);
                 }
             });
         }
@@ -84,6 +88,15 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
         public Optional<NormalizedNode<?, ?>> getDataBefore() {
             return optionalData(oldMeta);
         }
+
+        @Override
+        public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+            final Optional<ModifiedNode> childMod = mod.getChild(identifier);
+            if(childMod.isPresent()) {
+                return childNode(mod);
+            }
+            return null;
+        }
     }
 
     private static final class ChildNode extends AbstractNode {
index 08e15d07a83ef2938311e6b4edc66a998306db03..5f77994996ece3a99a8847063d6b8023f727145d 100644 (file)
@@ -9,14 +9,13 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import java.util.Collections;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 
-import java.util.Collections;
-
 /**
  * Internal utility class for an empty candidate. We instantiate this class
  * for empty modifications, saving memory and processing speed. Instances
@@ -48,6 +47,11 @@ final class NoopDataTreeCandidate extends AbstractDataTreeCandidate {
         public Optional<NormalizedNode<?, ?>> getDataBefore() {
             return Optional.absent();
         }
+
+        @Override
+        public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+            return null;
+        }
     };
 
     protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot) {