Update MutableTreeNode methods 08/93908/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Nov 2020 12:39:36 +0000 (13:39 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Nov 2020 12:40:25 +0000 (13:40 +0100)
Rename addChild() to putChild() and make it return previous child
if this was a replace operation. Also update removeChild() to return
removed child.

JIRA: YANGTOOLS-1182
Change-Id: I0c601f4b6b9d99bcc403b6928f6e8c9bfef36a34
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/AbstractMutableContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/MutableTreeNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractNodeContainerModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListModificationStrategy.java

index 22b2488c9f14ab840fdcab99ae2491ddb213fb22..958a6073d540b0707c080f49833fdb06f4ce4ccf 100644 (file)
@@ -53,13 +53,13 @@ abstract class AbstractMutableContainerNode implements MutableTreeNode {
     }
 
     @Override
-    public final void addChild(final TreeNode child) {
-        children.put(child.getIdentifier(), child);
+    public final TreeNode putChild(final TreeNode child) {
+        return children.put(child.getIdentifier(), child);
     }
 
     @Override
-    public final void removeChild(final PathArgument id) {
-        children.remove(requireNonNull(id));
+    public final TreeNode removeChild(final PathArgument id) {
+        return children.remove(requireNonNull(id));
     }
 
     @Override
index 432d1f2782bfdbea2a111afbcddeb20d6c5587c4..9a95f3f6ceb618ddd045e483bd28824b7a062453 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 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.StoreTreeNode;
@@ -35,22 +36,24 @@ public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
     void setSubtreeVersion(Version subtreeVersion);
 
     /**
-     * Add a new child node. This acts as add-or-replace operation, e.g. it
-     * succeeds even if a conflicting child is already present.
+     * Add a new child node. This acts as add-or-replace operation, e.g. it succeeds even if a conflicting child is
+     * already present.
      *
      * @param child New child node.
+     * @return Replaced child, or null if there was no previous child
      * @throws NullPointerException if {@code child} is null
      */
-    void addChild(TreeNode child);
+    @Nullable TreeNode putChild(TreeNode child);
 
     /**
-     * Remove a child node. This acts as delete-or-nothing operation, e.g. it
-     * succeeds even if the corresponding child is not present.
+     * Remove a child node. This acts as delete-or-nothing operation, e.g. it succeeds even if the corresponding child
+     * is not present.
      *
      * @param id Child identifier.
+     * @return Removed child, or null if there was no matching child
      * @throws NullPointerException if {@code id} is null
      */
-    void removeChild(PathArgument id);
+    @Nullable TreeNode removeChild(PathArgument id);
 
     /**
      * Finish node modification and return a read-only view of this node. After
index 36a22a0064a2a4e4a095397b23c9eec5edc46089..4f5516133b5f2876e79f8ef5baaf3e7796e9a2c3 100644 (file)
@@ -218,7 +218,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
             final Optional<? extends TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
             if (result.isPresent()) {
                 final TreeNode tn = result.get();
-                meta.addChild(tn);
+                meta.putChild(tn);
                 data.addChild(tn.getData());
             } else {
                 meta.removeChild(id);
index a13d004756d4a0648ffd4cbb91b1693d7fc830ce..9deeb404bfd6d31d8a9955eaa18f9a78ccff098e 100644 (file)
@@ -112,7 +112,7 @@ final class ListModificationStrategy extends SchemaAwareApplyOperation<ListSchem
             final Optional<? extends TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
             if (result.isPresent()) {
                 final TreeNode tn = result.get();
-                meta.addChild(tn);
+                meta.putChild(tn);
                 data.addChild(tn.getData());
             } else {
                 meta.removeChild(id);