Modernize DataTreeCandidateNode API 17/106217/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 28 May 2023 20:54:25 +0000 (22:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 29 May 2023 08:59:33 +0000 (10:59 +0200)
Use @Nullable/@NonNull properties aligned with record naming and
deprecate all the get*() methods.

JIRA: YANGTOOLS-1513
Change-Id: If7179fcc025d351ad339f3570495d41c524ce994
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
36 files changed:
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractDataTreeCandidateNode.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/DataTreeCandidateInputOutput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/DeletedDataTreeCandidateNode.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/ModifiedDataTreeCandidateNode.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/UnmodifiedRootDataTreeCandidateNode.java
codec/yang-data-codec-binfmt/src/test/java/org/opendaylight/yangtools/yang/data/codec/binfmt/DataTreeCandidateInputOutputTest.java
data/yang-data-tree-api/src/main/java/org/opendaylight/yangtools/yang/data/tree/api/DataTreeCandidateNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/AbstractModifiedNodeBasedCandidateNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/InMemoryDataTreeCandidate.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/NoopDataTreeCandidate.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/leafref/LeafRefValidation.java
data/yang-data-tree-ri/src/test/java/org/opendaylight/yangtools/yang/data/tree/impl/Bug3674Test.java
data/yang-data-tree-ri/src/test/java/org/opendaylight/yangtools/yang/data/tree/impl/DataTreeCandidatesTest.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/AbstractAvailableLeafCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/AbstractDataTreeCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/AbstractLeafCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/AbstractRecursiveCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/AbstractWriteCandidate.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/DataTreeCandidateNodes.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/DataTreeCandidates.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/DeleteLeafCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/EmptyDataTreeCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/NormalizedNodeDataTreeCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/RecursiveDeleteCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/RecursiveReplaceCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/RecursiveUnmodifiedCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/RecursiveWriteCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/ReplaceLeafCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/TerminalDataTreeCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/UnmodifiedLeafCandidateNode.java
data/yang-data-tree-spi/src/main/java/org/opendaylight/yangtools/yang/data/tree/spi/WriteLeafCandidateNode.java
data/yang-data-tree-spi/src/test/java/org/opendaylight/yangtools/yang/data/tree/spi/DataTreeCandidateNodesTest.java
data/yang-data-tree-spi/src/test/java/org/opendaylight/yangtools/yang/data/tree/spi/DataTreeCandidatesAggregateTest.java
data/yang-data-tree-spi/src/test/java/org/opendaylight/yangtools/yang/data/tree/spi/DataTreeCandidatesTest.java
data/yang-data-tree-spi/src/test/java/org/opendaylight/yangtools/yang/data/tree/spi/NormalizedNodeDataTreeCandidateNodeTest.java
data/yang-data-tree-spi/src/test/java/org/opendaylight/yangtools/yang/data/tree/spi/YT1455Test.java

index 1dea7316fbc7c4614b719f80f567dc422ba7c39f..f5198685fbfed65b8cc893f34879c50cdc7a784f 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
 import static java.util.Objects.requireNonNull;
 
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -31,17 +30,17 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
     }
 
     @Override
-    public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
-        throw new UnsupportedOperationException("Not implemented");
+    public final ModificationType modificationType() {
+        return type;
     }
 
     @Override
-    public final ModificationType getModificationType() {
-        return type;
+    public final DataTreeCandidateNode modifiedChild(final PathArgument identifier) {
+        throw new UnsupportedOperationException("Not implemented");
     }
 
     @Override
-    public final Optional<NormalizedNode> getDataBefore() {
+    public final NormalizedNode dataBefore() {
         throw new UnsupportedOperationException("Before-image not available after serialization");
     }
 }
index e22beaa73e78cb5bce5c37d6606cdf92b6fd1f31..f3eb60d07f95fbfdeb8b7cbc28d0a6053c6b64cb 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
+import static com.google.common.base.Verify.verifyNotNull;
+
 import com.google.common.collect.ImmutableList;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -69,24 +71,24 @@ public final class DataTreeCandidateInputOutput {
         out.writeYangInstanceIdentifier(candidate.getRootPath());
 
         final var node = candidate.getRootNode();
-        switch (node.getModificationType()) {
+        switch (node.modificationType()) {
             case APPEARED -> {
                 out.writeByte(APPEARED);
-                writeChildren(out, node.getChildNodes());
+                writeChildren(out, node.childNodes());
             }
             case DELETE -> out.writeByte(DELETE);
             case DISAPPEARED -> {
                 out.writeByte(DISAPPEARED);
-                writeChildren(out, node.getChildNodes());
+                writeChildren(out, node.childNodes());
             }
             case SUBTREE_MODIFIED -> {
                 out.writeByte(SUBTREE_MODIFIED);
-                writeChildren(out, node.getChildNodes());
+                writeChildren(out, node.childNodes());
             }
             case UNMODIFIED -> out.writeByte(UNMODIFIED);
             case WRITE -> {
                 out.writeByte(WRITE);
-                out.writeNormalizedNode(node.getDataAfter().orElseThrow());
+                out.writeNormalizedNode(verifyNotNull(node.dataAfter()));
             }
             default -> throw unhandledNodeType(node);
         }
@@ -145,29 +147,29 @@ public final class DataTreeCandidateInputOutput {
 
     private static void writeNode(final NormalizedNodeDataOutput out, final DataTreeCandidateNode node)
             throws IOException {
-        switch (node.getModificationType()) {
+        switch (node.modificationType()) {
             case APPEARED -> {
                 out.writeByte(APPEARED);
-                out.writePathArgument(node.getIdentifier());
-                writeChildren(out, node.getChildNodes());
+                out.writePathArgument(node.name());
+                writeChildren(out, node.childNodes());
             }
             case DELETE -> {
                 out.writeByte(DELETE);
-                out.writePathArgument(node.getIdentifier());
+                out.writePathArgument(node.name());
             }
             case DISAPPEARED -> {
                 out.writeByte(DISAPPEARED);
-                out.writePathArgument(node.getIdentifier());
-                writeChildren(out, node.getChildNodes());
+                out.writePathArgument(node.name());
+                writeChildren(out, node.childNodes());
             }
             case SUBTREE_MODIFIED -> {
                 out.writeByte(SUBTREE_MODIFIED);
-                out.writePathArgument(node.getIdentifier());
-                writeChildren(out, node.getChildNodes());
+                out.writePathArgument(node.name());
+                writeChildren(out, node.childNodes());
             }
             case WRITE -> {
                 out.writeByte(WRITE);
-                out.writeNormalizedNode(node.getDataAfter().orElseThrow());
+                out.writeNormalizedNode(verifyNotNull(node.dataAfter()));
             }
             case UNMODIFIED -> {
                 out.writeByte(UNMODIFIED);
@@ -181,6 +183,6 @@ public final class DataTreeCandidateInputOutput {
     }
 
     private static IllegalArgumentException unhandledNodeType(final DataTreeCandidateNode node) {
-        return new IllegalArgumentException("Unhandled node type " + node.getModificationType());
+        return new IllegalArgumentException("Unhandled node type " + node.modificationType());
     }
 }
index 0accce5088021a49ea3e7d0699634680fae5cc7e..7894d659d517b7d6570547d6784ff50d8ad88c37 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
+import static java.util.Objects.requireNonNull;
+
 import java.util.Collection;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
@@ -25,28 +26,29 @@ abstract class DeletedDataTreeCandidateNode extends AbstractDataTreeCandidateNod
     static DataTreeCandidateNode create() {
         return new DeletedDataTreeCandidateNode() {
             @Override
-            public PathArgument getIdentifier() {
+            public PathArgument name() {
                 throw new UnsupportedOperationException("Root node does not have an identifier");
             }
         };
     }
 
     static DataTreeCandidateNode create(final PathArgument identifier) {
+        final var name = requireNonNull(identifier);
         return new DeletedDataTreeCandidateNode() {
             @Override
-            public PathArgument getIdentifier() {
-                return identifier;
+            public PathArgument name() {
+                return name;
             }
         };
     }
 
     @Override
-    public final Optional<NormalizedNode> getDataAfter() {
-        return Optional.empty();
+    public final NormalizedNode dataAfter() {
+        return null;
     }
 
     @Override
-    public final Collection<DataTreeCandidateNode> getChildNodes() {
+    public final Collection<DataTreeCandidateNode> childNodes() {
         // We would require the before-image to reconstruct the list of nodes which
         // were deleted.
         throw new UnsupportedOperationException("Children not available after serialization");
index 1048459300fb77fb6f663a7abc369eb1295336c3..40b33046ead2e062dc16864798c8a4268ec61a14 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.data.codec.binfmt;
 import static java.util.Objects.requireNonNull;
 
 import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
  * one of its children.
  */
 abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode {
-    private final Collection<DataTreeCandidateNode> children;
+    private final @NonNull Collection<DataTreeCandidateNode> children;
 
     private ModifiedDataTreeCandidateNode(final ModificationType type,
             final Collection<DataTreeCandidateNode> children) {
@@ -32,7 +32,7 @@ abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNo
     static DataTreeCandidateNode create(final ModificationType type, final Collection<DataTreeCandidateNode> children) {
         return new ModifiedDataTreeCandidateNode(type, children) {
             @Override
-            public PathArgument getIdentifier() {
+            public PathArgument name() {
                 throw new UnsupportedOperationException("Root node does not have an identifier");
             }
         };
@@ -40,21 +40,22 @@ abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNo
 
     static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type,
             final Collection<DataTreeCandidateNode> children) {
+        final var name = requireNonNull(identifier);
         return new ModifiedDataTreeCandidateNode(type, children) {
             @Override
-            public PathArgument getIdentifier() {
-                return identifier;
+            public PathArgument name() {
+                return name;
             }
         };
     }
 
     @Override
-    public final Optional<NormalizedNode> getDataAfter() {
+    public final NormalizedNode dataAfter() {
         throw new UnsupportedOperationException("After-image not available after serialization");
     }
 
     @Override
-    public final Collection<DataTreeCandidateNode> getChildNodes() {
+    public final Collection<DataTreeCandidateNode> childNodes() {
         return children;
     }
 }
index 9dfce27a3356d5f64e2976e062f93bb6ba2a241e..ecb909cea06e2084e6eefb4e76a2b42cfb3b09b9 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
 import java.util.Collection;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
@@ -22,17 +21,17 @@ final class UnmodifiedRootDataTreeCandidateNode extends AbstractDataTreeCandidat
     }
 
     @Override
-    public PathArgument getIdentifier() {
+    public PathArgument name() {
         throw new UnsupportedOperationException("Root node does not have an identifier");
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
+    public NormalizedNode dataAfter() {
         throw new UnsupportedOperationException("After-image not available after serialization");
     }
 
     @Override
-    public Collection<DataTreeCandidateNode> getChildNodes() {
+    public Collection<DataTreeCandidateNode> childNodes() {
         throw new UnsupportedOperationException("Children not available after serialization");
     }
 }
\ No newline at end of file
index b6dba1105fd090c0c66df1069f41b2415dec08e2..b2bd08150883152ba9717169316ede74ac997679 100644 (file)
@@ -148,16 +148,16 @@ public class DataTreeCandidateInputOutputTest {
     }
 
     private static void assertEqualMod(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) {
-        assertEquals(expected.getModificationType(), actual.getModificationType());
+        assertEquals(expected.modificationType(), actual.modificationType());
 
-        switch (expected.getModificationType()) {
+        switch (expected.modificationType()) {
             case DELETE:
             case UNMODIFIED:
                 // No children to verify
                 break;
             default:
-                final Collection<DataTreeCandidateNode> expectedChildren = expected.getChildNodes();
-                final Collection<DataTreeCandidateNode> actualChildren = actual.getChildNodes();
+                final Collection<DataTreeCandidateNode> expectedChildren = expected.childNodes();
+                final Collection<DataTreeCandidateNode> actualChildren = actual.childNodes();
                 assertEquals(expectedChildren.size(), actualChildren.size());
 
                 final Iterator<DataTreeCandidateNode> ait = actualChildren.iterator();
@@ -169,7 +169,7 @@ public class DataTreeCandidateInputOutputTest {
     }
 
     private static void assertEqualNodes(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) {
-        assertEquals(expected.getIdentifier(), actual.getIdentifier());
+        assertEquals(expected.name(), actual.name());
         assertEqualMod(expected, actual);
     }
 }
index 0354440e20898dc2412d8f1ad59f23f8af7fb46f..099b5568f2f9f7c0d12c1f8a07c4732b2970c279 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.data.tree.api;
 import java.util.Collection;
 import java.util.Optional;
 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;
 
@@ -19,52 +20,162 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * of the tree restricted to the modified nodes.
  */
 public interface DataTreeCandidateNode {
+    /**
+     * Get the node underlying {@link NormalizedNode#name()}.
+     *
+     * @return The node identifier.
+     */
+    @NonNull PathArgument name();
+
     /**
      * Get the node identifier.
      *
+     * @implSpec Default implementation defers to {@link #name()}.
      * @return The node identifier.
+     * @deprecated Use {@link #name()} instead.
+     */
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @NonNull PathArgument getIdentifier() {
+        return name();
+    }
+
+    /**
+     * Get an unmodifiable collection of modified child nodes. Note that the collection may include
+     * {@link ModificationType#UNMODIFIED} nodes, which the caller is expected to handle as if they were not present.
+     *
+     * @return Unmodifiable collection of modified child nodes.
      */
-    @NonNull PathArgument getIdentifier();
+    @NonNull Collection<DataTreeCandidateNode> childNodes();
 
     /**
      * Get an unmodifiable collection of modified child nodes. Note that the collection may include
      * {@link ModificationType#UNMODIFIED} nodes, which the caller is expected to handle as if they were not present.
      *
+     * @implSpec Default implementation defers to {@link #childNodes()}.
      * @return Unmodifiable collection of modified child nodes.
+     * @deprecated Use {@link #childNodes()} instead.
+     */
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @NonNull Collection<DataTreeCandidateNode> getChildNodes() {
+        return childNodes();
+    }
+
+    /**
+     * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
+     * when there is evidence of the node or its parent being involved in modification which has turned out not to
+     * modify the node's contents.
+     *
+     * @param childName Identifier of child node
+     * @return Modified child or {@code null} if the specified child has not been modified
+     * @throws NullPointerException if {@code childNamez} is {@code null}
+     */
+    @Nullable DataTreeCandidateNode modifiedChild(PathArgument childName);
+
+    /**
+     * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
+     * when there is evidence of the node or its parent being involved in modification which has turned out not to
+     * modify the node's contents.
+     *
+     * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on
+     *           {@link #modifiedChild(PathArgument)}.
+     * @param childName Identifier of child node
+     * @return Modified child or empty.
+     * @throws NullPointerException if {@code childIdentifier} is {@code null}
      */
-    @NonNull Collection<DataTreeCandidateNode> getChildNodes();
+    default @NonNull Optional<DataTreeCandidateNode> findModifiedChild(final PathArgument childName) {
+        return Optional.ofNullable(modifiedChild(childName));
+    }
 
     /**
      * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
      * when there is evidence of the node or its parent being involved in modification which has turned out not to
      * modify the node's contents.
      *
-     * @param childIdentifier Identifier of child node
+     * @implSpec Default implementation defers to {@link #findModifiedChild(PathArgument)}.
+     * @param childName Identifier of child node
      * @return Modified child or empty.
-     * @throws NullPointerException if {@code childIdentifier} is null
+     * @throws NullPointerException if {@code childIdentifier} is {@code null}
+     * @deprecated Use {@link #modifiedChild(PathArgument)} or {@link #findModifiedChild(PathArgument)} instead.
      */
-    @NonNull Optional<DataTreeCandidateNode> getModifiedChild(PathArgument childIdentifier);
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @NonNull Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childName) {
+        return findModifiedChild(childName);
+    }
 
     /**
      * Return the type of modification this node is undergoing.
      *
      * @return Node modification type.
      */
-    @NonNull ModificationType getModificationType();
+    @NonNull ModificationType modificationType();
 
     /**
-     * Return the after-image of data corresponding to the node.
+     * Return the type of modification this node is undergoing.
+     *
+     * @implSpec Default implementation defers to {@link #modificationType()}.
+     * @return Node modification type.
+     * @deprecated Use {@link #modificationType()} instead.
+     */
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @NonNull ModificationType getModificationType() {
+        return modificationType();
+    }
+
+    /**
+     * Return the before-image of data corresponding to the node.
      *
-     * @return Node data as they will be present in the tree after
-     *         the modification is applied.
+     * @return Node data as they were present in the tree before the modification was applied.
      */
-    @NonNull Optional<NormalizedNode> getDataAfter();
+    @Nullable NormalizedNode dataBefore();
 
     /**
      * Return the before-image of data corresponding to the node.
      *
-     * @return Node data as they were present in the tree before
-     *         the modification was applied.
+     * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on {@link #dataBefore()}.
+     * @return Node data as they were present in the tree before the modification was applied, or empty.
+     */
+    default @NonNull Optional<NormalizedNode> findDataBefore() {
+        return Optional.ofNullable(dataBefore());
+    }
+
+    /**
+     * Return the before-image of data corresponding to the node.
+     *
+     * @implSpec Default implementation defers to {@link #findDataBefore()}.
+     * @return Node data as they were present in the tree before the modification was applied.
+     * @deprecated Use {@link #dataBefore()} or {@link #findDataBefore()} instead.
+     */
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @NonNull Optional<NormalizedNode> getDataBefore() {
+        return findDataBefore();
+    }
+
+    /**
+     * Return the after-image of data corresponding to the node.
+     *
+     * @return Node data as they will be present in the tree after the modification is applied
+     */
+    @Nullable NormalizedNode dataAfter();
+
+    /**
+     * Return the after-image of data corresponding to the node.
+     *
+     * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on {@link #dataAfter()}.
+     * @return Node data as they will be present in the tree after the modification is applied, or empty
+     */
+    default @NonNull Optional<NormalizedNode> findDataAfter() {
+        return Optional.ofNullable(dataAfter());
+    }
+
+    /**
+     * Return the after-image of data corresponding to the node.
+     *
+     * @implSpec Default implementation defers to {@link #findDataAfter()}.
+     * @return Node data as they will be present in the tree after the modification is applied.
+     * @deprecated Use {@link #dataAfter()} or {@link #findDataAfter()} instead.
      */
-    @NonNull Optional<NormalizedNode> getDataBefore();
+    @Deprecated(since = "11.0.0", forRemoval = true)
+    default @NonNull Optional<NormalizedNode> getDataAfter() {
+        return findDataAfter();
+    }
 }
index f2c162c74f31e40f954c82fdc5e420628a6f6806..fc41db6bc443a89ff9de5c3a7c9b96238741917d 100644 (file)
@@ -13,7 +13,6 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
 import java.util.Collection;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -69,13 +68,13 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
         return meta == null ? null : (DistinctNodeContainer<PathArgument, NormalizedNode>)meta.getData();
     }
 
-    private ChildNode childNode(final ModifiedNode childMod) {
-        final PathArgument id = childMod.getIdentifier();
+    private @NonNull ChildNode childNode(final ModifiedNode childMod) {
+        final var id = childMod.getIdentifier();
         return new ChildNode(childMod, childMeta(oldMeta, id), childMeta(newMeta, id));
     }
 
     @Override
-    public Collection<DataTreeCandidateNode> getChildNodes() {
+    public Collection<DataTreeCandidateNode> childNodes() {
         return switch (mod.getModificationType()) {
             case APPEARED, DISAPPEARED, SUBTREE_MODIFIED -> Collections2.transform(mod.getChildren(), this::childNode);
             case UNMODIFIED -> {
@@ -99,42 +98,43 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return verifyNotNull(mod.getModificationType(), "Node %s does not have resolved modification type", mod);
     }
 
-    private static @NonNull Optional<NormalizedNode> optionalData(final TreeNode meta) {
-        return meta == null ? Optional.empty() : Optional.of(meta.getData());
+    @Override
+    public final NormalizedNode dataBefore() {
+        return data(oldMeta);
     }
 
     @Override
-    public final Optional<NormalizedNode> getDataAfter() {
-        return optionalData(newMeta);
+    public final NormalizedNode dataAfter() {
+        return data(newMeta);
     }
 
-    @Override
-    public final Optional<NormalizedNode> getDataBefore() {
-        return optionalData(oldMeta);
+    private static @Nullable NormalizedNode data(final TreeNode meta) {
+        return meta == null ? null : meta.getData();
     }
 
+
     @Override
-    public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
+    public final DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+        final var identifier = requireNonNull(childName);
         return switch (mod.getModificationType()) {
             case APPEARED, DISAPPEARED, SUBTREE_MODIFIED -> {
-                final ModifiedNode child = mod.childByArg(identifier);
-                yield child == null ? Optional.empty() : Optional.of(childNode(child));
+                final var child = mod.childByArg(identifier);
+                yield child == null ? null : childNode(child);
             }
             case UNMODIFIED -> {
                 if (!canHaveChildren(oldMeta, newMeta)) {
-                    yield Optional.empty();
+                    yield null;
                 }
-                yield getContainer(newMeta != null ? newMeta : oldMeta)
-                    .findChildByArg(identifier)
-                    .map(DataTreeCandidateNodes::unmodified);
+                final var child = getContainer(newMeta != null ? newMeta : oldMeta).childByArg(identifier);
+                yield child == null ? null : DataTreeCandidateNodes.unmodified(child);
             }
             case DELETE, WRITE -> {
                 if (!canHaveChildren(oldMeta, newMeta)) {
-                    yield Optional.empty();
+                    yield null;
                 }
                 yield DataTreeCandidateNodes.containerDelta(getContainer(oldMeta), getContainer(newMeta), identifier);
             }
@@ -147,7 +147,7 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
         }
 
         @Override
-        public PathArgument getIdentifier() {
+        public PathArgument name() {
             return getMod().getIdentifier();
         }
     }
index 8eb1f12af9f9414755f2542ee921d2c809dcd3a2..c0ff4518c89673fc39977eb4bfd66da4de9ef660 100644 (file)
@@ -14,14 +14,13 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
 
 final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
-
     private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode {
         RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
             super(mod, oldMeta, newMeta);
         }
 
         @Override
-        public PathArgument getIdentifier() {
+        public PathArgument name() {
             throw new IllegalStateException("Attempted to get identifier of the root node");
         }
     }
@@ -31,7 +30,7 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
     InMemoryDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
             final TreeNode beforeRoot, final TreeNode afterRoot) {
         super(rootPath);
-        this.root = new RootNode(modificationRoot, beforeRoot, afterRoot);
+        root = new RootNode(modificationRoot, beforeRoot, afterRoot);
     }
 
     @Override
index 55e6e8fcfc369eb82f93a45dfa9860fd98c3a274..c32d7f63b4cb3e65602eea7a87f764129cb77e98 100644 (file)
@@ -10,9 +10,8 @@ package org.opendaylight.yangtools.yang.data.tree.impl;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.collect.ImmutableList;
 import java.util.Collection;
-import java.util.Optional;
+import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -29,33 +28,33 @@ import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
 final class NoopDataTreeCandidate extends AbstractDataTreeCandidate {
     private static final DataTreeCandidateNode ROOT = new DataTreeCandidateNode() {
         @Override
-        public ModificationType getModificationType() {
+        public ModificationType modificationType() {
             return ModificationType.UNMODIFIED;
         }
 
         @Override
-        public Collection<DataTreeCandidateNode> getChildNodes() {
-            return ImmutableList.of();
+        public Collection<DataTreeCandidateNode> childNodes() {
+            return List.of();
         }
 
         @Override
-        public PathArgument getIdentifier() {
+        public PathArgument name() {
             throw new IllegalStateException("Attempted to read identifier of the no-operation change");
         }
 
         @Override
-        public Optional<NormalizedNode> getDataAfter() {
-            return Optional.empty();
+        public NormalizedNode dataAfter() {
+            return null;
         }
 
         @Override
-        public Optional<NormalizedNode> getDataBefore() {
-            return Optional.empty();
+        public NormalizedNode dataBefore() {
+            return null;
         }
 
         @Override
-        public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
-            return Optional.empty();
+        public DataTreeCandidateNode modifiedChild(final PathArgument identifier) {
+            return null;
         }
     };
 
index d178b39d4f0a7dd84efce709d14e4f8901194b88..12a02e3845f77030895675331b631c8af647e42a 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.leafref;
 
+import static com.google.common.base.Verify.verifyNotNull;
+
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.ArrayDeque;
@@ -58,18 +60,17 @@ public final class LeafRefValidation {
 
     public static void validate(final DataTreeCandidate tree, final LeafRefContext rootLeafRefCtx)
             throws LeafRefDataValidationFailedException {
-        final var root = tree.getRootNode().getDataAfter();
-        if (root.isPresent()) {
-            new LeafRefValidation(root.orElseThrow())
-                .validateChildren(rootLeafRefCtx, tree.getRootNode().getChildNodes());
+        final var root = tree.getRootNode().dataAfter();
+        if (root != null) {
+            new LeafRefValidation(root).validateChildren(rootLeafRefCtx, tree.getRootNode().childNodes());
         }
     }
 
     private void validateChildren(final LeafRefContext rootLeafRefCtx, final Collection<DataTreeCandidateNode> children)
             throws LeafRefDataValidationFailedException {
         for (var dataTreeCandidateNode : children) {
-            if (dataTreeCandidateNode.getModificationType() != ModificationType.UNMODIFIED) {
-                final PathArgument identifier = dataTreeCandidateNode.getIdentifier();
+            if (dataTreeCandidateNode.modificationType() != ModificationType.UNMODIFIED) {
+                final PathArgument identifier = dataTreeCandidateNode.name();
                 final QName childQName = identifier.getNodeType();
 
                 final LeafRefContext referencedByCtx = rootLeafRefCtx.getReferencedChildByName(childQName);
@@ -93,28 +94,29 @@ public final class LeafRefValidation {
     }
 
     private void validateNode(final DataTreeCandidateNode node, final LeafRefContext referencedByCtx,
-        final LeafRefContext referencingCtx, final YangInstanceIdentifier current) {
+            final LeafRefContext referencingCtx, final YangInstanceIdentifier current) {
+        final var modType = node.modificationType();
 
-        if (node.getModificationType() == ModificationType.WRITE && node.getDataAfter().isPresent()) {
-            validateNodeData(node.getDataAfter().orElseThrow(), referencedByCtx, referencingCtx,
-                node.getModificationType(), current);
+        if (modType == ModificationType.WRITE) {
+            final var dataAfter = node.dataAfter();
+            if (dataAfter != null) {
+                validateNodeData(dataAfter, referencedByCtx, referencingCtx, ModificationType.WRITE, current);
+            }
             return;
         }
 
-        if (node.getModificationType() == ModificationType.DELETE && referencedByCtx != null) {
-            validateNodeData(node.getDataBefore().orElseThrow(), referencedByCtx, null, node.getModificationType(),
-                current);
+        if (modType == ModificationType.DELETE && referencedByCtx != null) {
+            validateNodeData(verifyNotNull(node.dataBefore()), referencedByCtx, null, node.modificationType(), current);
             return;
         }
 
-        for (var childNode : node.getChildNodes()) {
-            if (childNode.getModificationType() != ModificationType.UNMODIFIED) {
+        for (var childNode : node.childNodes()) {
+            if (childNode.modificationType() != ModificationType.UNMODIFIED) {
                 final LeafRefContext childReferencedByCtx = getReferencedByCtxChild(referencedByCtx, childNode);
                 final LeafRefContext childReferencingCtx = getReferencingCtxChild(referencingCtx, childNode);
 
                 if (childReferencedByCtx != null || childReferencingCtx != null) {
-                    validateNode(childNode, childReferencedByCtx,childReferencingCtx,
-                        current.node(childNode.getIdentifier()));
+                    validateNode(childNode, childReferencedByCtx,childReferencingCtx, current.node(childNode.name()));
                 }
             }
         }
@@ -126,10 +128,10 @@ public final class LeafRefValidation {
             return null;
         }
 
-        final QName childQName = childNode.getIdentifier().getNodeType();
+        final QName childQName = childNode.name().getNodeType();
         LeafRefContext childReferencingCtx = referencingCtx.getReferencingChildByName(childQName);
         if (childReferencingCtx == null) {
-            final NormalizedNode data = childNode.getDataAfter().orElseThrow();
+            final NormalizedNode data = verifyNotNull(childNode.dataAfter());
             if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) {
                 childReferencingCtx = referencingCtx;
             }
@@ -144,10 +146,10 @@ public final class LeafRefValidation {
             return null;
         }
 
-        final QName childQName = childNode.getIdentifier().getNodeType();
+        final QName childQName = childNode.name().getNodeType();
         LeafRefContext childReferencedByCtx = referencedByCtx.getReferencedChildByName(childQName);
         if (childReferencedByCtx == null) {
-            final NormalizedNode data = childNode.getDataAfter().orElseThrow();
+            final NormalizedNode data = verifyNotNull(childNode.dataAfter());
             if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) {
                 childReferencedByCtx = referencedByCtx;
             }
index c302171fbbe73ddc8849d022e1d68ecf878455ab..efc686b329203f5fe99791eec3fe5e457a5079f0 100644 (file)
@@ -48,6 +48,6 @@ public class Bug3674Test extends AbstractTestModelTest {
 
         final DataTreeCandidate candidate = tree.prepare(mod);
         final DataTreeCandidateNode root = candidate.getRootNode();
-        assertEquals(ModificationType.UNMODIFIED, root.getModificationType());
+        assertEquals(ModificationType.UNMODIFIED, root.modificationType());
     }
 }
index d556ad7c22cf22be3675377bd4aa10a2587bdd60..635455056b8212d2939a893b1092de8fa1a34ba7 100644 (file)
@@ -8,10 +8,10 @@
 package org.opendaylight.yangtools.yang.data.tree.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 
-import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -33,13 +33,8 @@ import org.opendaylight.yangtools.yang.data.tree.api.TreeType;
 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.data.tree.spi.DataTreeCandidates;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class DataTreeCandidatesTest extends AbstractTestModelTest {
-
-    private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidatesTest.class);
-
     private DataTree dataTree;
 
     @Before
@@ -86,13 +81,8 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH,
             candidate.getRootNode());
 
-        try {
-            // lets see if getting the identifier of the root node throws an exception
-            newCandidate.getRootNode().getIdentifier();
-            fail();
-        } catch (IllegalStateException e) {
-            LOG.debug("Cannot get identifier of root node candidate which is correct", e);
-        }
+        // lets see if getting the identifier of the root node throws an exception
+        assertThrows(IllegalStateException.class, () ->  newCandidate.getRootNode().name());
 
         // lets see if we can apply this rooted candidate to a new dataTree
         DataTreeCandidates.applyToModification(newModification,
@@ -112,10 +102,10 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         // The entire transaction needs to fizzle to a no-op
         DataTreeCandidate candidate = dataTree.prepare(modification);
         DataTreeCandidateNode node = candidate.getRootNode();
-        assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+        assertEquals(ModificationType.UNMODIFIED, node.modificationType());
 
         // 'test'
-        assertUnmodified(1, node.getChildNodes());
+        assertUnmodified(1, node.childNodes());
     }
 
     @Test
@@ -128,10 +118,10 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         // The entire transaction needs to fizzle to a no-op
         DataTreeCandidate candidate = dataTree.prepare(modification);
         DataTreeCandidateNode node = candidate.getRootNode();
-        assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+        assertEquals(ModificationType.UNMODIFIED, node.modificationType());
 
         // 'test'
-        assertUnmodified(1, node.getChildNodes());
+        assertUnmodified(1, node.childNodes());
     }
 
     @Test
@@ -145,10 +135,10 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         final DataTreeCandidate candidate = dataTree.prepare(modification);
         assertEquals(YangInstanceIdentifier.of(), candidate.getRootPath());
         final DataTreeCandidateNode node = candidate.getRootNode();
-        assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+        assertEquals(ModificationType.UNMODIFIED, node.modificationType());
 
         // 'test'
-        assertUnmodified(1, node.getChildNodes());
+        assertUnmodified(1, node.childNodes());
     }
 
     @Test
@@ -171,10 +161,10 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         final DataTreeCandidate candidate = dataTree.prepare(modification);
         assertEquals(YangInstanceIdentifier.of(), candidate.getRootPath());
         final DataTreeCandidateNode node = candidate.getRootNode();
-        assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+        assertEquals(ModificationType.UNMODIFIED, node.modificationType());
 
         // 'non-presence' and 'test'
-        assertUnmodified(2, node.getChildNodes());
+        assertUnmodified(2, node.childNodes());
     }
 
     @Test
@@ -195,9 +185,9 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         DataTreeCandidate candidate2 = dataTree.prepare(modification2);
         dataTree.commit(candidate2);
 
-        DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(Arrays.asList(candidate1,candidate2));
+        DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(ModificationType.UNMODIFIED,aggregateCandidate.getRootNode().getModificationType());
+        assertEquals(ModificationType.UNMODIFIED, aggregateCandidate.getRootNode().modificationType());
     }
 
     @Test
@@ -227,13 +217,13 @@ public class DataTreeCandidatesTest extends AbstractTestModelTest {
         DataTreeCandidate candidate2 = dataTree.prepare(modification2);
         dataTree.commit(candidate2);
 
-        DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(Arrays.asList(candidate1,candidate2));
+        DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(ModificationType.SUBTREE_MODIFIED,aggregateCandidate.getRootNode().getModificationType());
+        assertEquals(ModificationType.SUBTREE_MODIFIED,aggregateCandidate.getRootNode().modificationType());
     }
 
     private static void assertUnmodified(final int expSize, final Collection<DataTreeCandidateNode> nodes) {
         assertEquals(expSize, nodes.size());
-        nodes.forEach(node -> assertEquals(ModificationType.UNMODIFIED, node.getModificationType()));
+        nodes.forEach(node -> assertEquals(ModificationType.UNMODIFIED, node.modificationType()));
     }
 }
index c447e82e42018ef390e9d84931de4e28d5a9cff0..68f7fe81235443095487ae5a3c6ece58ff778d74 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 abstract class AbstractAvailableLeafCandidateNode extends AbstractLeafCandidateNode {
@@ -16,7 +15,7 @@ abstract class AbstractAvailableLeafCandidateNode extends AbstractLeafCandidateN
     }
 
     @Override
-    public final Optional<NormalizedNode> getDataAfter() {
-        return dataOptional();
+    public final NormalizedNode dataAfter() {
+        return data;
     }
 }
\ No newline at end of file
index 9efd66ec8657453bb77541e9c673a24a163a69eb..e7524e29f964af6647438d5d1ea69c6fb4b7ef1a 100644 (file)
@@ -17,14 +17,14 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 
 abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
-    private final DistinctNodeContainer<PathArgument, NormalizedNode> data;
+    final @NonNull DistinctNodeContainer<PathArgument, NormalizedNode> data;
 
     AbstractDataTreeCandidateNode(final DistinctNodeContainer<PathArgument, NormalizedNode> data) {
         this.data = requireNonNull(data);
     }
 
     @Override
-    public final PathArgument getIdentifier() {
+    public final PathArgument name() {
         return data.name();
     }
 
@@ -32,10 +32,6 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
         return Optional.of(data);
     }
 
-    final DistinctNodeContainer<PathArgument, NormalizedNode> data() {
-        return data;
-    }
-
     @Override
     public String toString() {
         return this.getClass().getSimpleName() + "{data = " + data + "}";
index 6183ab326b66988117c22286969c40c092122687..6d119417499c7fce3f4299d46fbe608dd8c9465f 100644 (file)
@@ -9,38 +9,32 @@ package org.opendaylight.yangtools.yang.data.tree.spi;
 
 import static java.util.Objects.requireNonNull;
 
-import java.util.Collection;
 import java.util.List;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 
 abstract class AbstractLeafCandidateNode implements DataTreeCandidateNode {
-    private final NormalizedNode data;
+    final @NonNull NormalizedNode data;
 
     AbstractLeafCandidateNode(final NormalizedNode data) {
         this.data = requireNonNull(data);
     }
 
-    final @NonNull Optional<NormalizedNode> dataOptional() {
-        return Optional.of(data);
-    }
-
     @Override
-    public final Collection<DataTreeCandidateNode> getChildNodes() {
+    public final List<DataTreeCandidateNode> childNodes() {
         return List.of();
     }
 
     @Override
-    public final PathArgument getIdentifier() {
+    public final PathArgument name() {
         return data.name();
     }
 
     @Override
-    public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
-        requireNonNull(identifier);
-        return Optional.empty();
+    public final DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+        requireNonNull(childName);
+        return null;
     }
 }
\ No newline at end of file
index 2c3eb1a97281f7e32669aa4e796c75df5e8c023e..a58929f6dfc35f2f1b0f01749819a84a9652188d 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.data.tree.spi;
 
 import com.google.common.collect.Collections2;
 import java.util.Collection;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -21,13 +20,14 @@ abstract class AbstractRecursiveCandidateNode extends AbstractDataTreeCandidateN
     }
 
     @Override
-    public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
-        return data().findChildByArg(identifier).map(this::createChild);
+    public final DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+        final var child = data.childByArg(childName);
+        return child != null ? createChild(child) : null;
     }
 
     @Override
-    public final Collection<DataTreeCandidateNode> getChildNodes() {
-        return Collections2.transform(data().body(), this::createChild);
+    public final Collection<DataTreeCandidateNode> childNodes() {
+        return Collections2.transform(data.body(), this::createChild);
     }
 
     abstract DataTreeCandidateNode createContainer(DistinctNodeContainer<PathArgument, NormalizedNode> childData);
index 0dcede729c1a493764f00f0c73ff7d43837ede2f..db320e46649e4fd5623635606ac629219096c4de 100644 (file)
@@ -16,7 +16,7 @@ abstract class AbstractWriteCandidate extends AbstractAvailableLeafCandidateNode
     }
 
     @Override
-    public final ModificationType getModificationType() {
+    public final ModificationType modificationType() {
         return ModificationType.WRITE;
     }
 }
\ No newline at end of file
index af6f3107d87bc442d3038c167cf0091816d36361..e5b89a05eb6752389c26e56186e585bc50296f4c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
+import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
@@ -15,7 +16,6 @@ import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -126,18 +126,18 @@ public final class DataTreeCandidateNodes {
      * @param newData New data container, may be null
      * @return A {@link DataTreeCandidateNode} describing the change, or empty if the node is not present
      */
-    public static @NonNull Optional<DataTreeCandidateNode> containerDelta(
+    public static @Nullable DataTreeCandidateNode containerDelta(
             final @Nullable DistinctNodeContainer<PathArgument, NormalizedNode> oldData,
             final @Nullable DistinctNodeContainer<PathArgument, NormalizedNode> newData,
             final @NonNull PathArgument child) {
         final NormalizedNode newChild = getChild(newData, child);
         final NormalizedNode oldChild = getChild(oldData, child);
         if (oldChild != null) {
-            return Optional.of(newChild != null ? replaceNode(oldChild, newChild) : deleteNode(oldChild));
+            return newChild != null ? replaceNode(oldChild, newChild) : deleteNode(oldChild);
         } else if (newChild != null) {
-            return Optional.of(DataTreeCandidateNodes.writeNode(newChild));
+            return DataTreeCandidateNodes.writeNode(newChild);
         } else {
-            return Optional.empty();
+            return null;
         }
     }
 
@@ -150,13 +150,13 @@ public final class DataTreeCandidateNodes {
      * @param node candidate tree to apply
      */
     public static void applyToCursor(final DataTreeModificationCursor cursor, final DataTreeCandidateNode node) {
-        switch (node.getModificationType()) {
+        switch (node.modificationType()) {
             case DELETE:
-                cursor.delete(node.getIdentifier());
+                cursor.delete(node.name());
                 break;
             case SUBTREE_MODIFIED:
-                cursor.enter(node.getIdentifier());
-                AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.getChildNodes().iterator());
+                cursor.enter(node.name());
+                AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.childNodes().iterator());
                 do {
                     iterator = iterator.next(cursor);
                 } while (iterator != null);
@@ -165,10 +165,10 @@ public final class DataTreeCandidateNodes {
                 // No-op
                 break;
             case WRITE:
-                cursor.write(node.getIdentifier(), node.getDataAfter().orElseThrow());
+                cursor.write(node.name(), verifyNotNull(node.dataAfter()));
                 break;
             default:
-                throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+                throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
         }
     }
 
@@ -182,13 +182,13 @@ public final class DataTreeCandidateNodes {
      */
     public static void applyRootedNodeToCursor(final DataTreeModificationCursor cursor,
             final YangInstanceIdentifier rootPath, final DataTreeCandidateNode node) {
-        switch (node.getModificationType()) {
+        switch (node.modificationType()) {
             case DELETE:
                 cursor.delete(rootPath.getLastPathArgument());
                 break;
             case SUBTREE_MODIFIED:
                 cursor.enter(rootPath.getLastPathArgument());
-                AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.getChildNodes().iterator());
+                AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.childNodes().iterator());
                 do {
                     iterator = iterator.next(cursor);
                 } while (iterator != null);
@@ -197,20 +197,20 @@ public final class DataTreeCandidateNodes {
                 // No-op
                 break;
             case WRITE:
-                cursor.write(rootPath.getLastPathArgument(), node.getDataAfter().orElseThrow());
+                cursor.write(rootPath.getLastPathArgument(), verifyNotNull(node.dataAfter()));
                 break;
             default:
-                throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+                throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
         }
     }
 
     public static void applyRootToCursor(final DataTreeModificationCursor cursor, final DataTreeCandidateNode node) {
-        switch (node.getModificationType()) {
+        switch (node.modificationType()) {
             case DELETE:
                 throw new IllegalArgumentException("Can not delete root.");
             case WRITE:
             case SUBTREE_MODIFIED:
-                AbstractNodeIterator iterator = new RootNonExitingIterator(node.getChildNodes().iterator());
+                AbstractNodeIterator iterator = new RootNonExitingIterator(node.childNodes().iterator());
                 do {
                     iterator = iterator.next(cursor);
                 } while (iterator != null);
@@ -219,7 +219,7 @@ public final class DataTreeCandidateNodes {
                 // No-op
                 break;
             default:
-                throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+                throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
         }
     }
 
@@ -266,16 +266,16 @@ public final class DataTreeCandidateNodes {
         final AbstractNodeIterator next(final DataTreeModificationCursor cursor) {
             while (iterator.hasNext()) {
                 final DataTreeCandidateNode node = iterator.next();
-                switch (node.getModificationType()) {
+                switch (node.modificationType()) {
                     case DELETE:
-                        cursor.delete(node.getIdentifier());
+                        cursor.delete(node.name());
                         break;
                     case APPEARED:
                     case DISAPPEARED:
                     case SUBTREE_MODIFIED:
-                        final Collection<DataTreeCandidateNode> children = node.getChildNodes();
+                        final var children = node.childNodes();
                         if (!children.isEmpty()) {
-                            cursor.enter(node.getIdentifier());
+                            cursor.enter(node.name());
                             return new ExitingNodeIterator(this, children.iterator());
                         }
                         break;
@@ -283,10 +283,10 @@ public final class DataTreeCandidateNodes {
                         // No-op
                         break;
                     case WRITE:
-                        cursor.write(node.getIdentifier(), node.getDataAfter().orElseThrow());
+                        cursor.write(node.name(), verifyNotNull(node.dataAfter()));
                         break;
                     default:
-                        throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+                        throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
                 }
             }
             exitNode(cursor);
index ba8ccc3e50e69b053d6b19e7c14abbf50fb1435a..c0e57bf0742d0c656b951840ab215a5eeb39c50f 100644 (file)
@@ -8,14 +8,13 @@
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -63,7 +62,7 @@ public final class DataTreeCandidates {
 
         final DataTreeCandidateNode node = candidate.getRootNode();
         final YangInstanceIdentifier path = candidate.getRootPath();
-        switch (node.getModificationType()) {
+        switch (node.modificationType()) {
             case DELETE:
                 modification.delete(path);
                 LOG.debug("Modification {} deleted path {}", modification, path);
@@ -71,7 +70,7 @@ public final class DataTreeCandidates {
             case SUBTREE_MODIFIED:
                 LOG.debug("Modification {} modified path {}", modification, path);
 
-                NodeIterator iterator = new NodeIterator(null, path, node.getChildNodes().iterator());
+                NodeIterator iterator = new NodeIterator(null, path, node.childNodes().iterator());
                 do {
                     iterator = iterator.next(modification);
                 } while (iterator != null);
@@ -81,11 +80,11 @@ public final class DataTreeCandidates {
                 // No-op
                 break;
             case WRITE:
-                modification.write(path, node.getDataAfter().orElseThrow());
+                modification.write(path, verifyNotNull(node.dataAfter()));
                 LOG.debug("Modification {} written path {}", modification, path);
                 break;
             default:
-                throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+                throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
         }
     }
 
@@ -119,26 +118,24 @@ public final class DataTreeCandidates {
 
     private static DataTreeCandidateNode fastCompressNode(final DataTreeCandidateNode first,
                                                           final List<DataTreeCandidateNode> input) {
-        final DataTreeCandidateNode last = input.get(input.size() - 1);
-        ModificationType nodeModification = last.getModificationType();
-        Optional<NormalizedNode> dataBefore = first.getDataBefore();
-        Optional<NormalizedNode> dataAfter = last.getDataAfter();
+        final var last = input.get(input.size() - 1);
+        final var nodeModification = last.modificationType();
+        final var dataBefore = first.dataBefore();
+        final var dataAfter = last.dataAfter();
         switch (nodeModification) {
             case DELETE:
-                ModificationType previous = first.getModificationType();
+                ModificationType previous = first.modificationType();
                 // Check if node had data before
-                if (previous == ModificationType.DELETE
-                        || previous == ModificationType.DISAPPEARED
-                        || previous == ModificationType.UNMODIFIED && dataBefore.isEmpty()) {
+                if (previous == ModificationType.DELETE || previous == ModificationType.DISAPPEARED
+                    || previous == ModificationType.UNMODIFIED && dataBefore == null) {
                     illegalModification(ModificationType.DELETE, ModificationType.DELETE);
                 }
-                if (dataBefore.isEmpty()) {
+                if (dataBefore == null) {
                     return new TerminalDataTreeCandidateNode(null, ModificationType.UNMODIFIED, null, null);
                 }
-                return new TerminalDataTreeCandidateNode(null, nodeModification, dataBefore.orElseThrow(), null);
+                return new TerminalDataTreeCandidateNode(null, nodeModification, verifyNotNull(dataBefore), null);
             case WRITE:
-                return new TerminalDataTreeCandidateNode(null, nodeModification, dataBefore.orElse(null),
-                        dataAfter.orElseThrow());
+                return new TerminalDataTreeCandidateNode(null, nodeModification, dataBefore, verifyNotNull(dataAfter));
             case APPEARED:
             case DISAPPEARED:
             case SUBTREE_MODIFIED:
@@ -153,10 +150,9 @@ public final class DataTreeCandidates {
     private static DataTreeCandidateNode slowCompressNodes(final DataTreeCandidateNode first,
                                                            final List<DataTreeCandidateNode> input) {
         // finalNode contains summarized changes
-        TerminalDataTreeCandidateNode finalNode = new TerminalDataTreeCandidateNode(
-                null, first.getDataBefore().orElse(null));
+        TerminalDataTreeCandidateNode finalNode = new TerminalDataTreeCandidateNode(null, first.dataBefore());
         input.forEach(node -> compressNode(finalNode, node, null));
-        finalNode.setAfter(input.get(input.size() - 1).getDataAfter().orElse(null));
+        finalNode.setAfter(input.get(input.size() - 1).dataAfter());
         return cleanUpTree(finalNode);
     }
 
@@ -164,7 +160,7 @@ public final class DataTreeCandidates {
                                      final PathArgument parent) {
         PathArgument identifier;
         try {
-            identifier = node.getIdentifier();
+            identifier = node.name();
         } catch (IllegalStateException e) {
             identifier = null;
         }
@@ -174,12 +170,12 @@ public final class DataTreeCandidates {
                     .orElseThrow(() -> new IllegalArgumentException("No node found for " + parent + " identifier"));
             TerminalDataTreeCandidateNode childNode = new TerminalDataTreeCandidateNode(
                     identifier,
-                    node.getDataBefore().orElse(null),
+                    node.dataBefore(),
                     parentNode);
             parentNode.addChildNode(childNode);
         }
 
-        ModificationType nodeModification = node.getModificationType();
+        ModificationType nodeModification = node.modificationType();
         switch (nodeModification) {
             case UNMODIFIED:
                 // If node is unmodified there is no need iterate through its child nodes
@@ -191,10 +187,10 @@ public final class DataTreeCandidates {
             case SUBTREE_MODIFIED:
                 finalNode.setModification(identifier,
                         compressModifications(finalNode.getModification(identifier), nodeModification,
-                                finalNode.getDataAfter(identifier).isEmpty()));
-                finalNode.setData(identifier, node.getDataAfter().orElse(null));
+                                finalNode.dataAfter(identifier) == null));
+                finalNode.setData(identifier, node.dataAfter());
 
-                for (DataTreeCandidateNode child : node.getChildNodes()) {
+                for (DataTreeCandidateNode child : node.childNodes()) {
                     compressNode(finalNode, child, identifier);
                 }
                 break;
@@ -211,13 +207,13 @@ public final class DataTreeCandidates {
     // Compare data before and after in order to find modified nodes without actual changes
     private static DataTreeCandidateNode cleanUpTree(final TerminalDataTreeCandidateNode finalNode,
                                                      final TerminalDataTreeCandidateNode node) {
-        PathArgument identifier = node.getIdentifier();
-        ModificationType nodeModification = node.getModificationType();
-        Collection<DataTreeCandidateNode> childNodes = node.getChildNodes();
-        for (DataTreeCandidateNode childNode : childNodes) {
+        final var identifier = node.name();
+        final var nodeModification = node.modificationType();
+        final var childNodes = node.childNodes();
+        for (var childNode : childNodes) {
             cleanUpTree(finalNode, (TerminalDataTreeCandidateNode) childNode);
         }
-        Optional<NormalizedNode> dataBefore = finalNode.getDataBefore(identifier);
+        final var dataBefore = finalNode.dataBefore(identifier);
 
         switch (nodeModification) {
             case UNMODIFIED:
@@ -226,12 +222,12 @@ public final class DataTreeCandidates {
             case WRITE:
                 return finalNode;
             case DELETE:
-                if (dataBefore.isEmpty()) {
+                if (dataBefore == null) {
                     finalNode.deleteNode(identifier);
                 }
                 return finalNode;
             case APPEARED:
-                if (dataBefore.isPresent()) {
+                if (dataBefore != null) {
                     illegalModification(ModificationType.APPEARED, ModificationType.WRITE);
                 }
                 if (childNodes.isEmpty()) {
@@ -239,12 +235,12 @@ public final class DataTreeCandidates {
                 }
                 return finalNode;
             case DISAPPEARED:
-                if (dataBefore.isEmpty() || childNodes.isEmpty()) {
+                if (dataBefore == null || childNodes.isEmpty()) {
                     finalNode.deleteNode(identifier);
                 }
                 return finalNode;
             case SUBTREE_MODIFIED:
-                if (dataBefore.isEmpty()) {
+                if (dataBefore == null) {
                     illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
                 }
                 if (childNodes.isEmpty()) {
@@ -262,102 +258,61 @@ public final class DataTreeCandidates {
         switch (firstModification) {
             case UNMODIFIED:
                 if (hasNoDataBefore) {
-                    switch (secondModification) {
-                        case UNMODIFIED:
-                        case WRITE:
-                        case APPEARED:
-                            return secondModification;
-                        case DELETE:
-                            return illegalModification(ModificationType.DELETE, ModificationType.DELETE);
-                        case SUBTREE_MODIFIED:
-                            return illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
-                        case DISAPPEARED:
-                            return illegalModification(ModificationType.DISAPPEARED, ModificationType.DELETE);
-                        default:
+                    return switch (secondModification) {
+                        case UNMODIFIED, WRITE, APPEARED -> secondModification;
+                        case DELETE -> illegalModification(ModificationType.DELETE, ModificationType.DELETE);
+                        case SUBTREE_MODIFIED ->
+                            illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
+                        case DISAPPEARED -> illegalModification(ModificationType.DISAPPEARED, ModificationType.DELETE);
+                        default ->
                             throw new IllegalStateException("Unsupported modification type " + secondModification);
-                    }
+                    };
                 }
                 if (secondModification == ModificationType.APPEARED) {
                     return illegalModification(ModificationType.APPEARED, ModificationType.WRITE);
                 }
                 return secondModification;
             case WRITE:
-                switch (secondModification) {
-                    case UNMODIFIED:
-                    case WRITE:
-                    case SUBTREE_MODIFIED:
-                        return ModificationType.WRITE;
-                    case DELETE:
-                        return ModificationType.DELETE;
-                    case DISAPPEARED:
-                        return ModificationType.DISAPPEARED;
-                    case APPEARED:
-                        return illegalModification(ModificationType.APPEARED, firstModification);
-                    default:
-                        throw new IllegalStateException("Unsupported modification type " + secondModification);
-                }
+                return switch (secondModification) {
+                    case UNMODIFIED, WRITE, SUBTREE_MODIFIED -> ModificationType.WRITE;
+                    case DELETE -> ModificationType.DELETE;
+                    case DISAPPEARED -> ModificationType.DISAPPEARED;
+                    case APPEARED -> illegalModification(ModificationType.APPEARED, firstModification);
+                    default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+                };
             case DELETE:
-                switch (secondModification) {
-                    case UNMODIFIED:
-                        return ModificationType.DELETE;
-                    case WRITE:
-                    case APPEARED:
-                        return ModificationType.WRITE;
-                    case DELETE:
-                        return illegalModification(ModificationType.DELETE, firstModification);
-                    case DISAPPEARED:
-                        return illegalModification(ModificationType.DISAPPEARED, firstModification);
-                    case SUBTREE_MODIFIED:
-                        return illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
-                    default:
-                        throw new IllegalStateException("Unsupported modification type " + secondModification);
-                }
+                return switch (secondModification) {
+                    case UNMODIFIED -> ModificationType.DELETE;
+                    case WRITE, APPEARED -> ModificationType.WRITE;
+                    case DELETE -> illegalModification(ModificationType.DELETE, firstModification);
+                    case DISAPPEARED -> illegalModification(ModificationType.DISAPPEARED, firstModification);
+                    case SUBTREE_MODIFIED -> illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
+                    default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+                };
             case APPEARED:
-                switch (secondModification) {
-                    case UNMODIFIED:
-                    case SUBTREE_MODIFIED:
-                        return ModificationType.APPEARED;
-                    case DELETE:
-                    case DISAPPEARED:
-                        return ModificationType.UNMODIFIED;
-                    case WRITE:
-                        return ModificationType.WRITE;
-                    case APPEARED:
-                        return illegalModification(ModificationType.APPEARED, firstModification);
-                    default:
-                        throw new IllegalStateException("Unsupported modification type " + secondModification);
-                }
+                return switch (secondModification) {
+                    case UNMODIFIED, SUBTREE_MODIFIED -> ModificationType.APPEARED;
+                    case DELETE, DISAPPEARED -> ModificationType.UNMODIFIED;
+                    case WRITE -> ModificationType.WRITE;
+                    case APPEARED -> illegalModification(ModificationType.APPEARED, firstModification);
+                    default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+                };
             case DISAPPEARED:
-                switch (secondModification) {
-                    case UNMODIFIED:
-                    case WRITE:
-                        return secondModification;
-                    case APPEARED:
-                        return ModificationType.SUBTREE_MODIFIED;
-                    case DELETE:
-                        return illegalModification(ModificationType.DELETE, firstModification);
-                    case DISAPPEARED:
-                        return illegalModification(ModificationType.DISAPPEARED, firstModification);
-
-                    case SUBTREE_MODIFIED:
-                        return illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
-                    default:
-                        throw new IllegalStateException("Unsupported modification type " + secondModification);
-                }
+                return switch (secondModification) {
+                    case UNMODIFIED, WRITE -> secondModification;
+                    case APPEARED -> ModificationType.SUBTREE_MODIFIED;
+                    case DELETE -> illegalModification(ModificationType.DELETE, firstModification);
+                    case DISAPPEARED -> illegalModification(ModificationType.DISAPPEARED, firstModification);
+                    case SUBTREE_MODIFIED -> illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
+                    default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+                };
             case SUBTREE_MODIFIED:
-                switch (secondModification) {
-                    case UNMODIFIED:
-                    case SUBTREE_MODIFIED:
-                        return ModificationType.SUBTREE_MODIFIED;
-                    case WRITE:
-                    case DELETE:
-                    case DISAPPEARED:
-                        return secondModification;
-                    case APPEARED:
-                        return illegalModification(ModificationType.APPEARED, firstModification);
-                    default:
-                        throw new IllegalStateException("Unsupported modification type " + secondModification);
-                }
+                return switch (secondModification) {
+                    case UNMODIFIED, SUBTREE_MODIFIED -> ModificationType.SUBTREE_MODIFIED;
+                    case WRITE, DELETE, DISAPPEARED -> secondModification;
+                    case APPEARED -> illegalModification(ModificationType.APPEARED, firstModification);
+                    default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+                };
             default:
                 throw new IllegalStateException("Unsupported modification type " + secondModification);
         }
@@ -397,9 +352,9 @@ public final class DataTreeCandidates {
         NodeIterator next(final DataTreeModification modification) {
             while (iterator.hasNext()) {
                 final DataTreeCandidateNode node = iterator.next();
-                final YangInstanceIdentifier child = path.node(node.getIdentifier());
+                final YangInstanceIdentifier child = path.node(node.name());
 
-                switch (node.getModificationType()) {
+                switch (node.modificationType()) {
                     case DELETE:
                         modification.delete(child);
                         LOG.debug("Modification {} deleted path {}", modification, child);
@@ -408,17 +363,17 @@ public final class DataTreeCandidates {
                     case DISAPPEARED:
                     case SUBTREE_MODIFIED:
                         LOG.debug("Modification {} modified path {}", modification, child);
-                        return new NodeIterator(this, child, node.getChildNodes().iterator());
+                        return new NodeIterator(this, child, node.childNodes().iterator());
                     case UNMODIFIED:
                         LOG.debug("Modification {} unmodified path {}", modification, child);
                         // No-op
                         break;
                     case WRITE:
-                        modification.write(child, node.getDataAfter().orElseThrow());
+                        modification.write(child, verifyNotNull(node.dataAfter()));
                         LOG.debug("Modification {} written path {}", modification, child);
                         break;
                     default:
-                        throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+                        throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
                 }
             }
             return parent;
index 093b87d467406b7d44127c1bb1f7d257b113609c..5fdfef747658fde5284d97a6a3b3dccc61c72542 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
 
@@ -17,17 +16,17 @@ final class DeleteLeafCandidateNode extends AbstractLeafCandidateNode {
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.DELETE;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return Optional.empty();
+    public NormalizedNode dataBefore() {
+        return data;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return dataOptional();
+    public NormalizedNode dataAfter() {
+        return null;
     }
 }
index f786080ee2f571c66d4b9d0ac60ebb5a3097f4b3..7da7036b59dcfd5859dcff511f9012488a3ae321 100644 (file)
@@ -11,46 +11,46 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableList;
 import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
 
 final class EmptyDataTreeCandidateNode implements DataTreeCandidateNode {
-    private final PathArgument identifier;
+    private final @NonNull PathArgument name;
 
-    EmptyDataTreeCandidateNode(final PathArgument identifier) {
-        this.identifier = requireNonNull(identifier, "Identifier should not be null");
+    EmptyDataTreeCandidateNode(final PathArgument name) {
+        this.name = requireNonNull(name);
     }
 
     @Override
-    public PathArgument getIdentifier() {
-        return identifier;
+    public PathArgument name() {
+        return name;
     }
 
     @Override
-    public Collection<DataTreeCandidateNode> getChildNodes() {
+    public Collection<DataTreeCandidateNode> childNodes() {
         return ImmutableList.of();
     }
 
     @Override
-    public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
-        return Optional.empty();
+    public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+        return null;
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.UNMODIFIED;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return Optional.empty();
+    public NormalizedNode dataAfter() {
+        return null;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.empty();
+    public NormalizedNode dataBefore() {
+        return null;
     }
 }
\ No newline at end of file
index 4ec90be143927f659a152fde2dccc8738d013611..af4d1ec5dd7625e9ae011e57ed6bf2d11a8b3334 100644 (file)
@@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
 import java.util.Collection;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
@@ -37,41 +36,41 @@ final class NormalizedNodeDataTreeCandidateNode implements DataTreeCandidateNode
     }
 
     @Override
-    public PathArgument getIdentifier() {
+    public PathArgument name() {
         return data.name();
     }
 
     @Override
-    public Collection<DataTreeCandidateNode> getChildNodes() {
-        if (data instanceof DistinctNodeContainer) {
-            return Collections2.transform(((DistinctNodeContainer<?, ?>) data).body(),
-                input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input));
-        }
-        return ImmutableList.of();
+    public ModificationType modificationType() {
+        return ModificationType.WRITE;
     }
 
     @Override
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
-        if (data instanceof DistinctNodeContainer) {
-            return ((Optional<@NonNull NormalizedNode>) ((DistinctNodeContainer)data).findChildByArg(childIdentifier))
-                .map(NormalizedNodeDataTreeCandidateNode::new);
-        }
-        return Optional.empty();
+    public NormalizedNode dataBefore() {
+        return null;
     }
 
     @Override
-    public ModificationType getModificationType() {
-        return ModificationType.WRITE;
+    public NormalizedNode dataAfter() {
+        return data;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return Optional.of(data);
+    public Collection<DataTreeCandidateNode> childNodes() {
+        if (data instanceof DistinctNodeContainer<?, ?> container) {
+            return Collections2.transform(container.body(),
+                input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input));
+        }
+        return ImmutableList.of();
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.empty();
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+        if (data instanceof DistinctNodeContainer container) {
+            final var child = container.childByArg(childName);
+            return child != null ? new NormalizedNodeDataTreeCandidateNode(child) : null;
+        }
+        return null;
     }
 }
index ae9839e0e58d1f31efbb2a77bb03b70b02c5e3d0..d2b4587b4baa0dcc839454ea26611781fb07c01f 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -20,18 +19,18 @@ final class RecursiveDeleteCandidateNode extends AbstractRecursiveCandidateNode
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.DELETE;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return Optional.empty();
+    public NormalizedNode dataAfter() {
+        return null;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return dataOptional();
+    public NormalizedNode dataBefore() {
+        return data;
     }
 
     @Override
index 87c6d1d11b63f02179b0851a3092dc4bb31fcc29..5b48dbebf4930a7861e1e6ed3bc082b9c619e7d1 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.data.tree.spi;
 import static java.util.Objects.requireNonNull;
 
 import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
 
 final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode {
-    private final DistinctNodeContainer<PathArgument, NormalizedNode> oldData;
+    private final @NonNull DistinctNodeContainer<PathArgument, NormalizedNode> oldData;
 
     RecursiveReplaceCandidateNode(final DistinctNodeContainer<PathArgument, NormalizedNode> oldData,
             final DistinctNodeContainer<PathArgument, NormalizedNode> newData) {
@@ -27,27 +27,27 @@ final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.WRITE;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return dataOptional();
+    public NormalizedNode dataBefore() {
+        return oldData;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.of(oldData);
+    public NormalizedNode dataAfter() {
+        return data;
     }
 
     @Override
-    public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
-        return DataTreeCandidateNodes.containerDelta(oldData, data(), identifier);
+    public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+        return DataTreeCandidateNodes.containerDelta(oldData, data, childName);
     }
 
     @Override
-    public Collection<DataTreeCandidateNode> getChildNodes() {
-        return DataTreeCandidateNodes.containerDelta(oldData, data());
+    public Collection<DataTreeCandidateNode> childNodes() {
+        return DataTreeCandidateNodes.containerDelta(oldData, data);
     }
 }
index 99c8a9d1898353f0c4fa41e2ea26cee77bacc3bd..7e9ba534421a5cff72fcf7396c326fbd4d1f1911 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -20,18 +19,18 @@ final class RecursiveUnmodifiedCandidateNode extends AbstractRecursiveCandidateN
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.UNMODIFIED;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return dataOptional();
+    public NormalizedNode dataBefore() {
+        return data;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return dataOptional();
+    public NormalizedNode dataAfter() {
+        return data;
     }
 
     @Override
index ad8d4462036b60811cdffd92bb3fb015b99a998e..32e81677f3c58a0c748c23f889247a50f3cec28f 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -20,18 +19,18 @@ final class RecursiveWriteCandidateNode extends AbstractRecursiveCandidateNode {
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.WRITE;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return dataOptional();
+    public NormalizedNode dataBefore() {
+        return null;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.empty();
+    public NormalizedNode dataAfter() {
+        return data;
     }
 
     @Override
index 322cee8bfed920590dfd0c704375fde574a1e50e..cffbafca7302e1b493edbcca93a64da8dc6c689c 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.yangtools.yang.data.tree.spi;
 
 import static java.util.Objects.requireNonNull;
 
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 final class ReplaceLeafCandidateNode extends AbstractWriteCandidate {
-    private final NormalizedNode oldData;
+    private final @NonNull NormalizedNode oldData;
 
     ReplaceLeafCandidateNode(final NormalizedNode oldData, final NormalizedNode newData) {
         super(newData);
@@ -21,7 +21,7 @@ final class ReplaceLeafCandidateNode extends AbstractWriteCandidate {
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.of(oldData);
+    public NormalizedNode dataBefore() {
+        return oldData;
     }
 }
\ No newline at end of file
index 7561f5cd9bb2996cffd70e4e3ae8d8b964e0df9d..8fdd30fe9b3dc5f19edfafcdd908c3c7b48482c4 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
+import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
 import java.util.Collection;
@@ -15,6 +16,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Optional;
 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.tree.api.DataTreeCandidateNode;
@@ -23,7 +25,7 @@ import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
 // Non-final for mocking
 class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
     private ModificationType modificationType;
-    private final PathArgument identifier;
+    private final @NonNull PathArgument name;
     private final NormalizedNode before;
     private NormalizedNode after;
     private final HashMap<PathArgument, TerminalDataTreeCandidateNode> childNodes = new HashMap<>();
@@ -39,50 +41,53 @@ class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
         this(identifier, ModificationType.UNMODIFIED, data, data);
     }
 
-    TerminalDataTreeCandidateNode(final PathArgument identifier, final ModificationType modificationType,
-                                  final NormalizedNode before, final NormalizedNode after) {
-        this.modificationType = modificationType;
-        this.identifier = identifier;
+    TerminalDataTreeCandidateNode(final PathArgument name, final ModificationType modificationType,
+                                  final @Nullable NormalizedNode before, final @Nullable NormalizedNode after) {
+        // FIXME: requireNonNull()
+        this.name = name;
+        this.modificationType = requireNonNull(modificationType);
         this.before = before;
         this.after = after;
     }
 
     @Override
-    public PathArgument getIdentifier() {
-        return identifier;
+    public PathArgument name() {
+        return name;
     }
 
     @Override
-    public Collection<DataTreeCandidateNode> getChildNodes() {
+    public Collection<DataTreeCandidateNode> childNodes() {
         return Collections.unmodifiableCollection(childNodes.values());
     }
 
     @Override
-    public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
-        return Optional.ofNullable(childNodes.get(identifier));
+    public DataTreeCandidateNode modifiedChild(final PathArgument childIdentifier) {
+        return childNodes.get(name);
     }
 
     @Override
-    public ModificationType getModificationType() {
-        return modificationType;
+    public ModificationType modificationType() {
+        return requireNonNull(modificationType);
     }
 
     @Override
-    public Optional<NormalizedNode> getDataAfter() {
-        return Optional.ofNullable(after);
+    public NormalizedNode dataAfter() {
+        return after;
     }
 
-    @NonNull Optional<NormalizedNode> getDataAfter(final PathArgument id) {
-        return getNode(id).flatMap(TerminalDataTreeCandidateNode::getDataAfter);
+    @Nullable NormalizedNode dataAfter(final PathArgument id) {
+        final var child = node(id);
+        return child != null ? child.dataAfter() : null;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.ofNullable(before);
+    public NormalizedNode dataBefore() {
+        return before;
     }
 
-    @NonNull Optional<NormalizedNode> getDataBefore(final PathArgument id) {
-        return getNode(id).flatMap(TerminalDataTreeCandidateNode::getDataBefore);
+    @Nullable NormalizedNode dataBefore(final PathArgument id) {
+        final var child = node(id);
+        return child != null ? child.dataBefore() : null;
     }
 
     void setAfter(final NormalizedNode after) {
@@ -90,7 +95,7 @@ class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
     }
 
     void addChildNode(final TerminalDataTreeCandidateNode node) {
-        childNodes.put(node.getIdentifier(), node);
+        childNodes.put(node.name(), node);
     }
 
     void setModification(final PathArgument id, final ModificationType modification) {
@@ -100,11 +105,11 @@ class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
     }
 
     private void setModification(final ModificationType modification) {
-        modificationType = modification;
+        modificationType = requireNonNull(modification);
     }
 
     ModificationType getModification(final PathArgument id) {
-        return getNode(id).map(TerminalDataTreeCandidateNode::getModificationType).orElse(ModificationType.UNMODIFIED);
+        return getNode(id).map(TerminalDataTreeCandidateNode::modificationType).orElse(ModificationType.UNMODIFIED);
     }
 
     void deleteNode(final PathArgument id) {
@@ -120,25 +125,30 @@ class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
         childNodes.remove(id);
     }
 
-    @NonNull Optional<TerminalDataTreeCandidateNode> getNode(final PathArgument id) {
+    final @Nullable TerminalDataTreeCandidateNode node(final PathArgument id) {
         if (id == null) {
-            return Optional.of(this);
+            return this;
         }
         if (childNodes.isEmpty()) {
-            return Optional.empty();
+            return null;
         }
-        if (childNodes.containsKey(id)) {
-            return Optional.ofNullable(childNodes.get(id));
+        final var childNode = childNodes.get(id);
+        if (childNode != null) {
+            return childNode;
         }
-        return findNode(id);
+        return findNode(id).orElse(null);
+    }
+
+    final @NonNull Optional<TerminalDataTreeCandidateNode> getNode(final PathArgument id) {
+        return Optional.ofNullable(node(id));
     }
 
     void setData(final PathArgument id, final NormalizedNode node) {
-        getNode(id).orElseThrow().setAfter(node);
+        verifyNotNull(node(id)).setAfter(node);
     }
 
     private @NonNull Optional<TerminalDataTreeCandidateNode> findNode(final PathArgument id) {
-        Collection<HashMap<PathArgument, TerminalDataTreeCandidateNode>> nodes = new HashSet<>();
+        final var nodes = new HashSet<HashMap<PathArgument, TerminalDataTreeCandidateNode>>();
         childNodes.forEach((childIdentifier, childNode) -> {
             nodes.add(childNode.childNodes);
         });
@@ -150,8 +160,8 @@ class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
         if (nodes.isEmpty()) {
             return Optional.empty();
         }
-        Collection<HashMap<PathArgument, TerminalDataTreeCandidateNode>> nextNodes = new HashSet<>();
-        for (HashMap<PathArgument, TerminalDataTreeCandidateNode> map : nodes) {
+        final var nextNodes = new HashSet<HashMap<PathArgument, TerminalDataTreeCandidateNode>>();
+        for (var map : nodes) {
             if (map.containsKey(id)) {
                 return Optional.ofNullable(map.get(id));
             }
index 7b2fb5391b8cb6427e868d6db4d51133ef43ed08..f731277efc0dcfb27304d05bd39a0a80efbd25e9 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
 
@@ -17,12 +16,12 @@ final class UnmodifiedLeafCandidateNode extends AbstractAvailableLeafCandidateNo
     }
 
     @Override
-    public ModificationType getModificationType() {
+    public ModificationType modificationType() {
         return ModificationType.UNMODIFIED;
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return dataOptional();
+    public NormalizedNode dataBefore() {
+        return data;
     }
 }
index b437877b89b3d22cebce73c8f185dcd0f29fe240..e08ab5c82f5a48ba7bfdcb49d593ae6dc354df9e 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 final class WriteLeafCandidateNode extends AbstractWriteCandidate {
@@ -16,7 +15,7 @@ final class WriteLeafCandidateNode extends AbstractWriteCandidate {
     }
 
     @Override
-    public Optional<NormalizedNode> getDataBefore() {
-        return Optional.empty();
+    public NormalizedNode dataBefore() {
+        return null;
     }
 }
index 17ac2779043de85e4d974f3d9aaaa2063cd7e5a6..75018ec8702fcf6e1163df19127900f7f471ca87 100644 (file)
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 import java.util.List;
-import java.util.Optional;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -44,9 +43,9 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
         final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
-        doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
+        doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
         DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
         verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
     }
@@ -56,7 +55,7 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
         DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
         verify(mockedCursor, times(1)).delete(isNull());
     }
@@ -66,24 +65,24 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
 
         final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
 
         final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
+        doReturn(ModificationType.WRITE).when(mockedChildNode2).modificationType();
         final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
-        doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
+        doReturn(mockedNormalizedNode).when(mockedChildNode2).dataAfter();
 
         final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).getModificationType();
+        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).modificationType();
         final DataTreeCandidateNode mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).getModificationType();
-        doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).getChildNodes();
+        doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).modificationType();
+        doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).childNodes();
 
         doReturn(List.of(mockedChildNode1, mockedChildNode2, mockedChildNode3))
-            .when(mockedDataTreeCandidateNode).getChildNodes();
+            .when(mockedDataTreeCandidateNode).childNodes();
 
         DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
         verify(mockedCursor, times(2)).enter((PathArgument) isNull());
@@ -96,7 +95,7 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
         final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
             () -> DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode));
         assertThat(ex.getMessage(), containsString("Unsupported modification"));
@@ -107,9 +106,9 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
         final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
-        doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
+        doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
         DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
             mockedDataTreeCandidateNode);
         verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
@@ -120,7 +119,7 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
         DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
             mockedDataTreeCandidateNode);
         verify(mockedCursor, times(1)).delete(isNull());
@@ -131,11 +130,11 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
 
         final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
-        doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).getChildNodes();
+        doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
+        doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).childNodes();
 
         DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
             mockedDataTreeCandidateNode);
@@ -148,7 +147,7 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
         final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
             () -> DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
                 mockedDataTreeCandidateNode));
@@ -160,11 +159,11 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
 
         final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
-        doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).getChildNodes();
+        doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
+        doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).childNodes();
 
         DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode);
         verify(mockedCursor, times(1)).delete(isNull());
@@ -172,11 +171,11 @@ public class DataTreeCandidateNodesTest {
 
     @Test
     public void testApplyRootToCursorWithDeleteModificationType() {
-        final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
-        final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+        final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+        final var mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
+        final var ex = assertThrows(IllegalArgumentException.class,
             () -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
         assertThat(ex.getMessage(), containsString("Can not delete root"));
     }
@@ -186,7 +185,7 @@ public class DataTreeCandidateNodesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
-        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
         final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
             () -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
         assertThat(ex.getMessage(), containsString("Unsupported modification"));
index 5214f78ea397709a323800a71cf7aa6c52a95949..7f08eb5359f82884ca5193deb4d420ac6d725d8f 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -19,7 +20,6 @@ import static org.opendaylight.yangtools.yang.data.tree.api.ModificationType.UNM
 import static org.opendaylight.yangtools.yang.data.tree.api.ModificationType.WRITE;
 
 import java.util.List;
-import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -52,9 +52,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals("value1", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertEquals("value1", aggregationResult.getRootNode().dataAfter().body());
     }
 
     @Test
@@ -71,9 +71,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals("value2", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertEquals("value2", aggregationResult.getRootNode().dataAfter().body());
     }
 
     @Test
@@ -89,9 +89,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertNull(aggregationResult.getRootNode().dataAfter());
     }
 
     @Test
@@ -131,9 +131,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals("value2", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertEquals("value2", aggregationResult.getRootNode().dataAfter().body());
     }
 
     @Test
@@ -150,9 +150,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals("value3", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertEquals("value3", aggregationResult.getRootNode().dataAfter().body());
     }
 
     @Test
@@ -167,9 +167,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
-        assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataBefore());
-        assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
+        assertEquals(null, aggregationResult.getRootNode().dataBefore());
+        assertEquals(null, aggregationResult.getRootNode().dataAfter());
     }
 
     @Test
@@ -185,9 +185,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertNull(aggregationResult.getRootNode().dataAfter());
     }
 
     @Test
@@ -202,9 +202,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value", aggregationResult.getRootNode().dataBefore().body());
+        assertNull(aggregationResult.getRootNode().dataAfter());
     }
 
     @Test
@@ -220,9 +220,9 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
-        assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
-        assertEquals("value2", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+        assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+        assertEquals("value2", aggregationResult.getRootNode().dataAfter().body());
     }
 
     @Test
@@ -284,7 +284,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -304,7 +304,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -326,7 +326,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -368,7 +368,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -410,7 +410,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(APPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(APPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -449,7 +449,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -469,7 +469,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -491,7 +491,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -513,7 +513,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -533,7 +533,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -553,7 +553,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -575,7 +575,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -597,7 +597,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -621,7 +621,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -663,7 +663,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -685,7 +685,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -707,7 +707,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -729,7 +729,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -752,7 +752,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -774,7 +774,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -817,7 +817,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -837,7 +837,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(APPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(APPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -857,7 +857,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -879,7 +879,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -900,7 +900,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(APPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(APPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -939,7 +939,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -959,7 +959,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -1000,7 +1000,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+        assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -1042,7 +1042,7 @@ public class DataTreeCandidatesAggregateTest {
 
         DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
 
-        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+        assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
     }
 
     @Test
@@ -1074,17 +1074,17 @@ public class DataTreeCandidatesAggregateTest {
                                                                        final NormalizedNode after,
                                                                        final ModificationType modification) {
         TerminalDataTreeCandidateNode dataTreeCandidateNode = mock(TerminalDataTreeCandidateNode.class);
-        doReturn(null).when(dataTreeCandidateNode).getIdentifier();
-        doReturn(Optional.ofNullable(before)).when(dataTreeCandidateNode).getDataBefore();
-        doReturn(Optional.ofNullable(after)).when(dataTreeCandidateNode).getDataAfter();
-        doReturn(modification).when(dataTreeCandidateNode).getModificationType();
+        doReturn(null).when(dataTreeCandidateNode).name();
+        doReturn(before).when(dataTreeCandidateNode).dataBefore();
+        doReturn(after).when(dataTreeCandidateNode).dataAfter();
+        doReturn(modification).when(dataTreeCandidateNode).modificationType();
         return dataTreeCandidateNode;
     }
 
     private static void setChildNodes(final TerminalDataTreeCandidateNode parentNode,
                                       final List<DataTreeCandidateNode> childNodes) {
-        doReturn(null).when(parentNode).getIdentifier();
-        childNodes.forEach(child -> doReturn(CHILD_ID).when(child).getIdentifier());
-        doReturn(childNodes).when(parentNode).getChildNodes();
+        doReturn(null).when(parentNode).name();
+        childNodes.forEach(child -> doReturn(CHILD_ID).when(child).name());
+        doReturn(childNodes).when(parentNode).childNodes();
     }
 }
index 9c3d30087bb36ed0d1d43706683113dd9974a7a7..f69b546c190c45e98fbba8997d6d85b397d66247 100644 (file)
@@ -70,7 +70,7 @@ public class DataTreeCandidatesTest {
         final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
 
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
         DataTreeCandidates.applyToCursor(mockedCursor, mockedDataTreeCandidate);
         verify(mockedCursor, times(1)).delete(isNull());
@@ -88,7 +88,7 @@ public class DataTreeCandidatesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
 
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
 
         DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
         verify(mockedModification, times(1)).openCursor(YangInstanceIdentifier.of());
@@ -102,7 +102,7 @@ public class DataTreeCandidatesTest {
         final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
         doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
 
         IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
             () -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
@@ -118,7 +118,7 @@ public class DataTreeCandidatesTest {
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
         doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
 
-        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
 
         DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
         verify(mockedModification, times(1)).delete(YangInstanceIdentifier.of());
@@ -133,9 +133,9 @@ public class DataTreeCandidatesTest {
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
         doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
         final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
-        doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
+        doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
 
-        doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
 
         DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
         verify(mockedModification, times(1)).write(any(YangInstanceIdentifier.class), any(NormalizedNode.class));
@@ -150,28 +150,28 @@ public class DataTreeCandidatesTest {
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
         doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
 
-        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
 
         final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
-        doReturn(new NodeIdentifier(QName.create("test", "test1"))).when(mockedChildNode1).getIdentifier();
+        doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
+        doReturn(new NodeIdentifier(QName.create("test", "test1"))).when(mockedChildNode1).name();
 
         final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
+        doReturn(ModificationType.WRITE).when(mockedChildNode2).modificationType();
         final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
-        doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
-        doReturn(new NodeIdentifier(QName.create("test", "test2"))).when(mockedChildNode2).getIdentifier();
+        doReturn(mockedNormalizedNode).when(mockedChildNode2).dataAfter();
+        doReturn(new NodeIdentifier(QName.create("test", "test2"))).when(mockedChildNode2).name();
 
         final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).getModificationType();
+        doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).modificationType();
         final DataTreeCandidateNode mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
-        doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).getModificationType();
-        doReturn(new NodeIdentifier(QName.create("test", "test3"))).when(mockedChildNode3).getIdentifier();
-        doReturn(new NodeIdentifier(QName.create("test", "test4"))).when(mockedChildNode3ChildNode).getIdentifier();
-        doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).getChildNodes();
+        doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).modificationType();
+        doReturn(new NodeIdentifier(QName.create("test", "test3"))).when(mockedChildNode3).name();
+        doReturn(new NodeIdentifier(QName.create("test", "test4"))).when(mockedChildNode3ChildNode).name();
+        doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).childNodes();
 
         final List<DataTreeCandidateNode> childNodes = List.of(mockedChildNode1, mockedChildNode2, mockedChildNode3);
-        doReturn(childNodes).when(mockedDataTreeCandidateNode).getChildNodes();
+        doReturn(childNodes).when(mockedDataTreeCandidateNode).childNodes();
 
         DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
         verify(mockedModification, times(2)).delete(any(YangInstanceIdentifier.class));
@@ -187,7 +187,7 @@ public class DataTreeCandidatesTest {
         doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
         doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
 
-        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+        doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
 
         final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
             () -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
index 632517a1f0fcee8ed45448c472253d7640c9b631..2cfbc9794401c0f26c674a913bc8b18f19fea2ba 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.yangtools.yang.data.tree.spi;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
@@ -18,7 +20,6 @@ import static org.mockito.Mockito.mock;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -37,34 +38,33 @@ public class NormalizedNodeDataTreeCandidateNodeTest {
 
         final var mockedPathArgument = new NodeIdentifier(QName.create("test", "test"));
         doReturn(mockedPathArgument).when(mockedNormalizedNode).name();
-        assertSame(mockedPathArgument, normalizedNodeDataTreeCandidateNode.getIdentifier());
+        assertSame(mockedPathArgument, normalizedNodeDataTreeCandidateNode.name());
 
-        final Collection<DataTreeCandidateNode> childNodes = normalizedNodeDataTreeCandidateNode.getChildNodes();
+        final Collection<DataTreeCandidateNode> childNodes = normalizedNodeDataTreeCandidateNode.childNodes();
         assertTrue(childNodes instanceof List);
         assertTrue(childNodes.isEmpty());
 
-        assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getModifiedChild(mockedPathArgument));
+        assertNull(normalizedNodeDataTreeCandidateNode.modifiedChild(mockedPathArgument));
 
-        assertEquals(ModificationType.WRITE, normalizedNodeDataTreeCandidateNode.getModificationType());
-        assertEquals(Optional.of(mockedNormalizedNode), normalizedNodeDataTreeCandidateNode.getDataAfter());
-        assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getDataBefore());
+        assertEquals(ModificationType.WRITE, normalizedNodeDataTreeCandidateNode.modificationType());
+        assertEquals(mockedNormalizedNode, normalizedNodeDataTreeCandidateNode.dataAfter());
+        assertEquals(null, normalizedNodeDataTreeCandidateNode.dataBefore());
 
         final DistinctNodeContainer mockedNormalizedNodeContainer = mock(DistinctNodeContainer.class);
         final NormalizedNodeDataTreeCandidateNode normalizedNodeDataTreeCandidateNode2 = new
                 NormalizedNodeDataTreeCandidateNode(mockedNormalizedNodeContainer);
         final NormalizedNode mockedChildNormNode1 = mock(NormalizedNode.class);
         final NormalizedNode mockedChildNormNode2 = mock(NormalizedNode.class);
-        final Collection<NormalizedNode> mockedChildNodes = Arrays.asList(mockedChildNormNode1,
-                mockedChildNormNode2, null);
+        final var mockedChildNodes = Arrays.asList(mockedChildNormNode1, mockedChildNormNode2, null);
         doReturn(mockedChildNodes).when(mockedNormalizedNodeContainer).body();
-        final Collection<DataTreeCandidateNode> childNodes2 = normalizedNodeDataTreeCandidateNode2.getChildNodes();
+        final var childNodes2 = normalizedNodeDataTreeCandidateNode2.childNodes();
         assertEquals(3, childNodes2.size());
 
         doReturn(null).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
         doCallRealMethod().when(mockedNormalizedNodeContainer).findChildByArg(any(PathArgument.class));
-        assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument));
+        assertNull(normalizedNodeDataTreeCandidateNode2.modifiedChild(mockedPathArgument));
 
         doReturn(mockedChildNormNode1).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
-        assertTrue(normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument).isPresent());
+        assertNotNull(normalizedNodeDataTreeCandidateNode2.modifiedChild(mockedPathArgument));
     }
 }
index 6590304cdad88c76e4ede512b51ef4848c29b7bc..ffb475d942d9d3044541f6e0ab9fac2d622b61c7 100644 (file)
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doReturn;
 
 import java.util.List;
-import java.util.Optional;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -45,10 +44,10 @@ public class YT1455Test {
         assertEquals(1, delta.size());
 
         final var first = delta.iterator().next();
-        assertEquals(childId, first.getIdentifier());
-        assertEquals(ModificationType.DELETE, first.getModificationType());
-        assertEquals(Optional.of(child), first.getDataBefore());
-        assertEquals(Optional.empty(), first.getDataAfter());
-        assertEquals(0, first.getChildNodes().size());
+        assertEquals(childId, first.name());
+        assertEquals(ModificationType.DELETE, first.modificationType());
+        assertEquals(child, first.dataBefore());
+        assertEquals(null, first.dataAfter());
+        assertEquals(0, first.childNodes().size());
     }
 }