Update StoreTreeNode methods 07/93907/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Nov 2020 10:13:16 +0000 (11:13 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Nov 2020 12:28:02 +0000 (13:28 +0100)
StoreTreeNode.getChild() is forcing users to work on optional,
which is introducing no small amount of complexity. Furthermore it
is not inline with our naming -- that method should be findChild()
at the very least.

JIRA: YANGTOOLS-1181
Change-Id: Ie1c69664c46a9f83154730835d42dcb93778b4a6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
25 files changed:
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/StoreTreeNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/StoreTreeNodes.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/AbstractContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/LazyContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/LazyMutableContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/MaterializedContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/MaterializedMutableContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/SimpleContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/ValueNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractModifiedNodeBasedCandidateNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractNodeContainerModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractReadyIterator.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractValidation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataNodeContainerModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModificationCursor.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafSetModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MapModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationApplyOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModifiedNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OperationWithModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaAwareApplyOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ValueNodeModificationStrategy.java

index b163c834dc2813597642bfbd2bdf67ced872c5b5..0671cf5bd9bfb7480b2f61dffee321b897b1f702 100644 (file)
@@ -7,8 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema.tree;
 
+import static com.google.common.base.Verify.verifyNotNull;
+
+import com.google.common.base.VerifyException;
 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;
 
 /**
@@ -21,9 +25,32 @@ public interface StoreTreeNode<C extends StoreTreeNode<C>> {
     /**
      * Returns a direct child of the node.
      *
-     * @param child Identifier of child
-     * @return Optional with node if the child is existing, {@link Optional#empty()} otherwise.
+     * @param arg Identifier of child
+     * @return A node if the child is existing, {@code null} otherwise.
+     * @throws NullPointerException when {@code child} is null
+     */
+    @Nullable C childByArg(PathArgument arg);
+
+    /**
+     * Returns a direct child of the node.
+     *
+     * @param arg Identifier of child
+     * @return A child node
+     * @throws NullPointerException when {@code child} is null
+     * @throws VerifyException if the child does not exist
+     */
+    default @NonNull C getChildByArg(final PathArgument arg) {
+        return verifyNotNull(childByArg(arg), "Child %s does not exist");
+    }
+
+    /**
+     * Returns a direct child of the node.
+     *
+     * @param arg Identifier of child
+     * @return Optional with node if the child exists, {@link Optional#empty()} otherwise.
      * @throws NullPointerException when {@code child} is null
      */
-    @NonNull Optional<? extends C> getChild(PathArgument child);
+    @NonNull default Optional<C> findChildByArg(final PathArgument arg) {
+        return Optional.ofNullable(childByArg(arg));
+    }
 }
index d68faa14f3b0cc0e2780c25388971504b70c9da9..8417179bcaa538cd5a3c0abadd794dd381b5ddc6 100644 (file)
@@ -38,12 +38,12 @@ public final class StoreTreeNodes {
      */
     public static <T extends StoreTreeNode<T>> Optional<? extends T> findNode(final T tree,
             final YangInstanceIdentifier path) {
-        Optional<? extends T> current = Optional.of(tree);
+        T current = tree;
         Iterator<PathArgument> pathIter = path.getPathArguments().iterator();
-        while (current.isPresent() && pathIter.hasNext()) {
-            current = current.get().getChild(pathIter.next());
+        while (current != null && pathIter.hasNext()) {
+            current = current.childByArg(pathIter.next());
         }
-        return current;
+        return Optional.ofNullable(current);
     }
 
     public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final YangInstanceIdentifier path) {
@@ -51,12 +51,11 @@ public final class StoreTreeNodes {
 
         int depth = 1;
         for (PathArgument pathArg : path.getPathArguments()) {
-            Optional<? extends T> potential = current.getChild(pathArg);
-            if (potential.isEmpty()) {
+            current = current.childByArg(pathArg);
+            if (current == null) {
                 throw new IllegalArgumentException(String.format("Child %s is not present in tree.",
                         path.getAncestor(depth)));
             }
-            current = potential.get();
             ++depth;
         }
         return current;
@@ -78,19 +77,19 @@ public final class StoreTreeNodes {
 
     public static <T extends StoreTreeNode<T>> Entry<YangInstanceIdentifier, T> findClosestsOrFirstMatch(final T tree,
             final YangInstanceIdentifier path, final Predicate<T> predicate) {
-        Optional<? extends T> parent = Optional.of(tree);
-        Optional<? extends T> current = Optional.of(tree);
+        T parent = tree;
+        T current = tree;
 
         int nesting = 0;
         Iterator<PathArgument> pathIter = path.getPathArguments().iterator();
-        while (current.isPresent() && pathIter.hasNext() && !predicate.test(current.get())) {
+        while (current != null && pathIter.hasNext() && !predicate.test(current)) {
             parent = current;
-            current = current.get().getChild(pathIter.next());
+            current = current.childByArg(pathIter.next());
             nesting++;
         }
-        if (current.isPresent()) {
+        if (current != null) {
             final YangInstanceIdentifier currentPath = path.getAncestor(nesting);
-            return new SimpleImmutableEntry<>(currentPath, current.get());
+            return new SimpleImmutableEntry<>(currentPath, current);
         }
 
         /*
@@ -100,13 +99,13 @@ public final class StoreTreeNodes {
          * present. At any rate we verify state just to be on the safe side.
          */
         verify(nesting > 0);
-        return new SimpleImmutableEntry<>(path.getAncestor(nesting - 1), parent.get());
+        return new SimpleImmutableEntry<>(path.getAncestor(nesting - 1), parent);
     }
 
     public static <T extends StoreTreeNode<T>> Optional<? extends T> getChild(final Optional<T> parent,
             final PathArgument child) {
         if (parent.isPresent()) {
-            return parent.get().getChild(child);
+            return parent.get().findChildByArg(child);
         }
         return Optional.empty();
     }
index 74e5746bccc2070f86790cbdd59d1b9d98e35c5d..bd2a01698f5404eb1a8419767b09879789631d23 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import java.util.Optional;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
@@ -26,9 +27,9 @@ abstract class AbstractContainerNode extends AbstractTreeNode {
         return (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) getData();
     }
 
-    protected final Optional<TreeNode> getChildFromData(final PathArgument childId) {
+    protected final @Nullable TreeNode getChildFromData(final PathArgument childId) {
         // We do not cache the instantiated node as it is dirt cheap
-        return Optional.ofNullable(getChildFromData(castData(), childId, getVersion()));
+        return getChildFromData(castData(), childId, getVersion());
     }
 
     static TreeNode getChildFromData(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data,
index 6c877dce218bacdbda8926e2366f1cce44f2487a..511b2975ba77964d39e17403844d7a89964a5173 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.Collections2;
 import java.util.Map;
-import java.util.Optional;
 import org.opendaylight.yangtools.util.MapAdaptor;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -39,9 +38,9 @@ final class LazyContainerNode extends AbstractModifiedContainerNode {
     }
 
     @Override
-    public Optional<TreeNode> getChild(final PathArgument childId) {
+    public TreeNode childByArg(final PathArgument arg) {
         final TreeNode modified;
-        return (modified = getModifiedChild(childId)) == null ? getChildFromData(childId) : Optional.of(modified);
+        return (modified = getModifiedChild(arg)) == null ? getChildFromData(arg) : modified;
     }
 
     @Override
index 437edeed8a324852bd8fc46489fb4bcd4caa1cb3..e0b3e0198e3fd7c21b2ee861107717b110b9237b 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import java.util.Map;
-import java.util.Optional;
 import org.opendaylight.yangtools.util.MapAdaptor;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
@@ -26,12 +25,8 @@ final class LazyMutableContainerNode extends AbstractMutableContainerNode {
     }
 
     @Override
-    public Optional<TreeNode> getChild(final PathArgument childId) {
-        final TreeNode modified = getModifiedChild(childId);
-        if (modified != null) {
-            return Optional.of(modified);
-        }
-
-        return Optional.ofNullable(AbstractContainerNode.getChildFromData(getData(), childId, getVersion()));
+    public TreeNode childByArg(final PathArgument arg) {
+        final TreeNode modified = getModifiedChild(arg);
+        return modified != null ? modified : AbstractContainerNode.getChildFromData(getData(), arg, getVersion());
     }
 }
index 7ce74dbd8b10a25109ccd7b4cff2c2c573b64c3a..d7c5fa7d6d287bb54e75aacc60e639b457511898 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import java.util.Map;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -22,8 +21,8 @@ final class MaterializedContainerNode extends AbstractModifiedContainerNode {
     }
 
     @Override
-    public Optional<TreeNode> getChild(final PathArgument childId) {
-        return Optional.ofNullable(getModifiedChild(childId));
+    public TreeNode childByArg(final PathArgument arg) {
+        return getModifiedChild(arg);
     }
 
     @Override
index c787e470479c09486f76671fd410c395d396f4b1..8d325526ce8c0259fd4ce8372b851a178731e9fe 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import java.util.Map;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 final class MaterializedMutableContainerNode extends AbstractMutableContainerNode {
@@ -17,7 +16,7 @@ final class MaterializedMutableContainerNode extends AbstractMutableContainerNod
     }
 
     @Override
-    public Optional<TreeNode> getChild(final PathArgument child) {
-        return Optional.ofNullable(getModifiedChild(child));
+    public TreeNode childByArg(final PathArgument arg) {
+        return getModifiedChild(arg);
     }
 }
index ba152bf6c69f9567f06b7d085b4722b8db8b5b01..d5a7c581f9530f27784cb1a39a43eff9333f3e13 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -26,8 +25,8 @@ final class SimpleContainerNode extends AbstractContainerNode {
     }
 
     @Override
-    public Optional<TreeNode> getChild(final PathArgument child) {
-        return getChildFromData(child);
+    public TreeNode childByArg(final PathArgument arg) {
+        return getChildFromData(arg);
     }
 
     @Override
index a2b750d2b2784406f4367c058f8a0a56b99914db..c2180b8ec9d4b296c0d6e91aaed79f82a4e7c828 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -27,9 +26,9 @@ final class ValueNode extends AbstractTreeNode {
     }
 
     @Override
-    public Optional<TreeNode> getChild(final PathArgument childId) {
-        LOG.warn("Attempted to access child {} of value-node {}", childId, this);
-        return Optional.empty();
+    public TreeNode childByArg(final PathArgument arg) {
+        LOG.warn("Attempted to access child {} of value-node {}", arg, this);
+        return null;
     }
 
     @Override
index 25e44a74fe66935791c2d792f24811abc2633511..64dab708849a42462c534f1bf04bd8dda41252a3 100644 (file)
@@ -49,7 +49,7 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
     }
 
     private static TreeNode childMeta(final TreeNode parent, final PathArgument id) {
-        return parent == null ? null : parent.getChild(id).orElse(null);
+        return parent == null ? null : parent.childByArg(id);
     }
 
     private static boolean canHaveChildren(final @Nullable TreeNode oldMeta, final @Nullable TreeNode newMeta) {
@@ -127,7 +127,8 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
             case APPEARED:
             case DISAPPEARED:
             case SUBTREE_MODIFIED:
-                return mod.getChild(identifier).map(this::childNode);
+                final ModifiedNode child = mod.childByArg(identifier);
+                return child == null ? Optional.empty() : Optional.of(childNode(child));
             case UNMODIFIED:
                 if (!canHaveChildren(oldMeta, newMeta)) {
                     return Optional.empty();
index 50ef3b0b7edc93b2c13ea1285c82d5bee6f7def5..36a22a0064a2a4e4a095397b23c9eec5edc46089 100644 (file)
@@ -49,8 +49,8 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
             return entryStrategy.getSchema();
         }
 
-        final Optional<ModificationApplyOperation> entryStrategy() {
-            return Optional.of(entryStrategy);
+        final @NonNull ModificationApplyOperation entryStrategy() {
+            return entryStrategy;
         }
 
         @Override
@@ -112,14 +112,13 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
         if (verifyChildrenStructure) {
             final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) writtenValue;
             for (final NormalizedNode<?, ?> child : container.getValue()) {
-                final Optional<ModificationApplyOperation> childOp = getChild(child.getIdentifier());
-                if (childOp.isPresent()) {
-                    childOp.get().fullVerifyStructure(child);
-                } else {
+                final ModificationApplyOperation childOp = childByArg(child.getIdentifier());
+                if (childOp == null) {
                     throw new SchemaValidationFailedException(String.format(
-                            "Node %s is not a valid child of %s according to the schema.",
-                            child.getIdentifier(), container.getIdentifier()));
+                        "Node %s is not a valid child of %s according to the schema.",
+                        child.getIdentifier(), container.getIdentifier()));
                 }
+                childOp.fullVerifyStructure(child);
             }
 
             optionalVerifyValueChildren(writtenValue);
@@ -151,14 +150,14 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
     protected final void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
         final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) value;
         for (final NormalizedNode<?, ?> child : container.getValue()) {
-            final Optional<ModificationApplyOperation> childOp = getChild(child.getIdentifier());
-            if (!childOp.isPresent()) {
+            final ModificationApplyOperation childOp = childByArg(child.getIdentifier());
+            if (childOp == null) {
                 throw new SchemaValidationFailedException(
                     String.format("Node %s is not a valid child of %s according to the schema.",
                         child.getIdentifier(), container.getIdentifier()));
             }
 
-            childOp.get().recursivelyVerifyStructure(child);
+            childOp.recursivelyVerifyStructure(child);
         }
     }
 
@@ -214,7 +213,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
 
         for (final ModifiedNode mod : modifications) {
             final PathArgument id = mod.getIdentifier();
-            final Optional<? extends TreeNode> cm = meta.getChild(id);
+            final Optional<? extends TreeNode> cm = meta.findChildByArg(id);
 
             final Optional<? extends TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
             if (result.isPresent()) {
@@ -410,7 +409,7 @@ abstract class AbstractNodeContainerModificationStrategy<T extends WithStatus>
             final TreeNode current, final Version version) throws DataValidationFailedException {
         for (final NodeModification childMod : modification.getChildren()) {
             final PathArgument childId = childMod.getIdentifier();
-            final Optional<? extends TreeNode> childMeta = current.getChild(childId);
+            final Optional<? extends TreeNode> childMeta = current.findChildByArg(childId);
 
             path.push(childId);
             try {
index 160ce6609dc3855f682f50f6afa4225d83cab2a0..ad3913251e1e0c2a62d85b1d7d7caf7dd7722329 100644 (file)
@@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull;
 
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 
 abstract class AbstractReadyIterator {
@@ -37,10 +36,9 @@ abstract class AbstractReadyIterator {
         // through it via re-entering this method on the child iterator.
         while (children.hasNext()) {
             final ModifiedNode child = children.next();
-            final Optional<ModificationApplyOperation> childOperation = op.getChild(child.getIdentifier());
-            checkState(childOperation.isPresent(), "Schema for child %s is not present.", child.getIdentifier());
+            final ModificationApplyOperation childOp = op.childByArg(child.getIdentifier());
+            checkState(childOp != null, "Schema for child %s is not present.", child.getIdentifier());
             final Collection<ModifiedNode> grandChildren = child.getChildren();
-            final ModificationApplyOperation childOp = childOperation.get();
 
             if (grandChildren.isEmpty()) {
                 // The child is empty, seal it
index 98ff474db5cf5b5edb49a33661f42e78692dae89..d72b17a87862b4eca13d4dffc0fcde68332fd832 100644 (file)
@@ -35,8 +35,8 @@ abstract class AbstractValidation extends ModificationApplyOperation {
     }
 
     @Override
-    public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
-        return delegate.getChild(child);
+    public final ModificationApplyOperation childByArg(final PathArgument arg) {
+        return delegate.childByArg(arg);
     }
 
     @Override
index b79371f48dbc71150cbfe1f21099c92a3805d038..a5ba03432e0c5a2d0c63dbb8f2ec45e1658cf039 100644 (file)
@@ -101,8 +101,8 @@ final class ChoiceModificationStrategy extends Visible<ChoiceSchemaNode> {
     }
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
-        return Optional.ofNullable(childNodes.get(child));
+    public ModificationApplyOperation childByArg(final PathArgument arg) {
+        return childNodes.get(arg);
     }
 
     @Override
index 4fde21bdd0400a826f6ba1a57dfd3d94f35ab650..f3c08e9e44894a6958175b249050c9c2fb942346 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.collect.ImmutableMap.Builder;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -50,15 +51,15 @@ class DataNodeContainerModificationStrategy<T extends DataNodeContainer & WithSt
     }
 
     @Override
-    public final Optional<ModificationApplyOperation> getChild(final PathArgument identifier) {
+    public final ModificationApplyOperation childByArg(final PathArgument arg) {
         final ImmutableMap<PathArgument, ModificationApplyOperation> local = children;
-        final ModificationApplyOperation existing = local.get(identifier);
+        final ModificationApplyOperation existing = local.get(arg);
         if (existing != null) {
-            return Optional.of(existing);
+            return existing;
         }
 
-        final ModificationApplyOperation childOperation = resolveChild(identifier);
-        return childOperation != null ? appendChild(local, identifier, childOperation) : Optional.empty();
+        final ModificationApplyOperation childOperation = resolveChild(arg);
+        return childOperation != null ? appendChild(local, arg, childOperation) : null;
     }
 
     private ModificationApplyOperation resolveChild(final PathArgument identifier) {
@@ -85,7 +86,7 @@ class DataNodeContainerModificationStrategy<T extends DataNodeContainer & WithSt
         }
     }
 
-    private Optional<ModificationApplyOperation> appendChild(
+    private @Nullable ModificationApplyOperation appendChild(
             final ImmutableMap<PathArgument, ModificationApplyOperation> initial, final PathArgument identifier,
             final ModificationApplyOperation computed) {
 
@@ -100,14 +101,14 @@ class DataNodeContainerModificationStrategy<T extends DataNodeContainer & WithSt
 
             // Attempt to install the updated map
             if (UPDATER.compareAndSet(this, previous, updated)) {
-                return Optional.of(computed);
+                return computed;
             }
 
             // We have raced, acquire a new snapshot, recheck presence and retry if needed
             previous = children;
             final ModificationApplyOperation raced = previous.get(identifier);
             if (raced != null) {
-                return Optional.of(raced);
+                return raced;
             }
         }
     }
index a34614d074e57a0c68f23e8b20c92a536b7fa3a4..6f0d92d25174e65d5f60f814d1371cc3dcb6ad91 100644 (file)
@@ -177,12 +177,11 @@ final class InMemoryDataTreeModification extends AbstractCursorAware implements
 
         int depth = 1;
         for (final PathArgument pathArg : path.getPathArguments()) {
-            final Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
-            if (!potential.isPresent()) {
+            operation = operation.childByArg(pathArg);
+            if (operation == null) {
                 throw new SchemaValidationFailedException(String.format("Child %s is not present in schema tree.",
                         path.getAncestor(depth)));
             }
-            operation = potential.get();
             ++depth;
 
             modification = modification.modifyChild(pathArg, operation, version);
index ff926179bcb3d3493be2d0ae3258a349bec8ff75..34eb3425be33ba75f3c1408f8fc54ee869b67a92 100644 (file)
@@ -35,9 +35,8 @@ final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDa
         getParent().upgradeIfPossible();
 
         final OperationWithModification op = stack.peek();
-        final Optional<ModificationApplyOperation> potential = op.getApplyOperation().getChild(child);
-        if (potential.isPresent()) {
-            final ModificationApplyOperation operation = potential.get();
+        final ModificationApplyOperation operation = op.getApplyOperation().childByArg(child);
+        if (operation != null) {
             final ModifiedNode modification = op.getModification().modifyChild(child, operation,
                 getParent().getVersion());
 
index 0ff785aa07719d33a076ac185d4a6a6036f5caf3..6e3f15d3f8eaa1c65dbe5109d65516bce927843f 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -38,7 +37,7 @@ final class LeafSetModificationStrategy extends Invisible<LeafListSchemaNode> {
     }
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument identifier) {
-        return identifier instanceof NodeWithValue ? entryStrategy() : Optional.empty();
+    public ModificationApplyOperation childByArg(final PathArgument arg) {
+        return arg instanceof NodeWithValue ? entryStrategy() : null;
     }
 }
\ No newline at end of file
index b311687dea1cf59092314932c94b82e3429dd46d..a13d004756d4a0648ffd4cbb91b1693d7fc830ce 100644 (file)
@@ -107,7 +107,7 @@ final class ListModificationStrategy extends SchemaAwareApplyOperation<ListSchem
 
         for (final ModifiedNode mod : modifications) {
             final PathArgument id = mod.getIdentifier();
-            final Optional<? extends TreeNode> cm = meta.getChild(id);
+            final Optional<? extends TreeNode> cm = meta.findChildByArg(id);
 
             final Optional<? extends TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
             if (result.isPresent()) {
@@ -125,8 +125,8 @@ final class ListModificationStrategy extends SchemaAwareApplyOperation<ListSchem
     }
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
-        return child instanceof NodeIdentifier ? Optional.of(entryStrategy) : Optional.empty();
+    public ModificationApplyOperation childByArg(final PathArgument arg) {
+        return arg instanceof NodeIdentifier ? entryStrategy : null;
     }
 
     @Override
index 25f508c4be70f30e9cc677d7559c30170eb7e995..62826dac26a639ee47fed9447de3a4d342a62952 100644 (file)
@@ -11,9 +11,9 @@ import static java.util.Objects.requireNonNull;
 
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
@@ -55,8 +55,8 @@ final class MapModificationStrategy extends Invisible<ListSchemaNode> {
     }
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
-        return identifier instanceof NodeIdentifierWithPredicates ? entryStrategy() : Optional.empty();
+    public ModificationApplyOperation childByArg(final PathArgument arg) {
+        return arg instanceof NodeIdentifierWithPredicates ? entryStrategy() : null;
     }
 
     @Override
index 75d4ae93f0fadaf6f22ba5dc9a8b98a86b74ce50..5147357848e9d26379e00626f265a522dd49a1f4 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  * <b>Implementation notes</b>
  * <ul>
  *   <li>Implementations MUST expose all nested suboperations which operates on child nodes expose via
- *       {@link #getChild(PathArgument)} method.</li>
+ *       {@link #findChildByArg(PathArgument)} method.</li>
  *   <li>Same suboperations SHOULD be used when invoked via {@link #apply(ModifiedNode, Optional, Version)},
  *       if applicable.</li>
  *   <li>There are exactly two base implementations:
@@ -114,13 +114,13 @@ abstract class ModificationApplyOperation implements StoreTreeNode<ModificationA
     abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
 
     /**
-     * Returns a suboperation for specified tree node.
+     * {@inheritDoc}
      *
-     * @return Reference to suboperation for specified tree node, {@link Optional#empty()}
-     *         if suboperation is not supported for specified tree node.
+     * @return Reference to suboperation for specified tree node, {@code null} if suboperation is not supported for
+     *         specified tree node.
      */
     @Override
-    public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
+    public abstract ModificationApplyOperation childByArg(PathArgument arg);
 
     abstract void recursivelyVerifyStructure(NormalizedNode<?, ?> value);
 
index b666eed4f8893cbe9b27628835546abca6773784..969d2e8253928ce2ff5912dd8ddab0877a09a10a 100644 (file)
@@ -114,12 +114,12 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
      * @return Child modification if direct child or it's subtree was modified.
      */
     @Override
-    public Optional<ModifiedNode> getChild(final PathArgument child) {
-        return Optional.ofNullable(children.get(child));
+    public ModifiedNode childByArg(final PathArgument arg) {
+        return children.get(arg);
     }
 
     private Optional<? extends TreeNode> metadataFromSnapshot(final @NonNull PathArgument child) {
-        return original.isPresent() ? original.get().getChild(child) : Optional.empty();
+        return original.isPresent() ? original.get().findChildByArg(child) : Optional.empty();
     }
 
     private Optional<? extends TreeNode> metadataFromData(final @NonNull PathArgument child, final Version modVersion) {
@@ -130,7 +130,7 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
             writtenOriginal = TreeNodeFactory.createTreeNode(value, modVersion);
         }
 
-        return writtenOriginal.getChild(child);
+        return writtenOriginal.findChildByArg(child);
     }
 
     /**
index 363f2499e2d35f85001b1715fb1d2b5bcc6e28d3..fba41a63b28f1b174de83090a7e37ca7f3d252e8 100644 (file)
@@ -56,14 +56,12 @@ final class OperationWithModification {
      * view, one will we instantiated with specified version.
      */
     Optional<NormalizedNode<?, ?>> read(final PathArgument child, final Version version) {
-        final Optional<ModifiedNode> maybeChild = modification.getChild(child);
-        if (maybeChild.isPresent()) {
-            final ModifiedNode childNode = maybeChild.get();
-
+        final ModifiedNode childNode = modification.childByArg(child);
+        if (childNode != null) {
             Optional<? extends TreeNode> snapshot = childNode.getSnapshot();
             if (snapshot == null) {
                 // Snapshot is not present, force instantiation
-                snapshot = applyOperation.getChild(child).get().apply(childNode, childNode.getOriginal(), version);
+                snapshot = applyOperation.getChildByArg(child).apply(childNode, childNode.getOriginal(), version);
             }
 
             return snapshot.map(TreeNode::getData);
@@ -75,7 +73,7 @@ final class OperationWithModification {
         }
 
         if (snapshot.isPresent()) {
-            return snapshot.get().getChild(child).map(TreeNode::getData);
+            return snapshot.get().findChildByArg(child).map(TreeNode::getData);
         }
 
         return Optional.empty();
index 9531d837ac5b4f5d17897dd0d75572cf031d825c..bc7dd85056dd979aad5c39798ccd550c47ece7a3 100644 (file)
@@ -115,10 +115,10 @@ abstract class SchemaAwareApplyOperation<T extends WithStatus> extends Modificat
                 "Node children was modified by other transaction");
     }
 
-    protected final ModificationApplyOperation resolveChildOperation(final PathArgument child) {
-        final Optional<ModificationApplyOperation> potential = getChild(child);
-        checkArgument(potential.isPresent(), "Operation for child %s is not defined.", child);
-        return potential.get();
+    protected final @NonNull ModificationApplyOperation resolveChildOperation(final PathArgument child) {
+        final ModificationApplyOperation potential = childByArg(child);
+        checkArgument(potential != null, "Operation for child %s is not defined.", child);
+        return potential;
     }
 
     @Override
index 0251d535ba3d4090f1eed4e4b02aaf8f960d811a..75fb5cdc75c038df7ef9ac81bb41ca8be6b17a16 100644 (file)
@@ -38,7 +38,7 @@ final class ValueNodeModificationStrategy<T extends DataSchemaNode, V extends No
     }
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
+    public ModificationApplyOperation childByArg(final PathArgument arg) {
         throw new UnsupportedOperationException("Node " + schema + " is leaf type node. Child nodes not allowed");
     }