Add SchemaInferenceStack.ofDataTreePath() 68/95168/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 14 Feb 2021 17:31:52 +0000 (18:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 14 Feb 2021 17:33:30 +0000 (18:33 +0100)
This method is useful at least for testing. Also fix a copy&paste
mistake -- a failure is in the 'data tree', not 'schema tree'.

JIRA: YANGTOOLS-1231
Change-Id: Ied1c25700744f8c6a616efc172808af96f4615fe
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaInferenceStack.java

index 7bae59a880fa947f8a64b33d9ca9e6412bc4393e..7e8ff081656e2486960b06c875afeadde2d56758 100644 (file)
@@ -191,6 +191,23 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
         return of(inference.getEffectiveModelContext(), inference.toSchemaNodeIdentifier());
     }
 
         return of(inference.getEffectiveModelContext(), inference.toSchemaNodeIdentifier());
     }
 
+    /**
+     * Create a new stack backed by an effective model and set up to point and specified data tree node.
+     *
+     * @param effectiveModel EffectiveModelContext to which this stack is attached
+     * @return A new stack
+     * @throws NullPointerException if any argument is null or path contains a null element
+     * @throws IllegalArgumentException if a path element cannot be found
+     */
+    public static @NonNull SchemaInferenceStack ofDataTreePath(final EffectiveModelContext effectiveModel,
+            final QName... path) {
+        final SchemaInferenceStack ret = new SchemaInferenceStack(effectiveModel);
+        for (QName qname : path) {
+            ret.enterDataTree(qname);
+        }
+        return ret;
+    }
+
     /**
      * Create a new stack backed by an effective model, pointing to specified schema node identified by an absolute
      * {@link SchemaPath} and its {@link SchemaPath#getPathFromRoot()}.
     /**
      * Create a new stack backed by an effective model, pointing to specified schema node identified by an absolute
      * {@link SchemaPath} and its {@link SchemaPath#getPathFromRoot()}.
@@ -517,7 +534,7 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
     private @NonNull DataTreeEffectiveStatement<?> pushData(final @NonNull DataTreeAwareEffectiveStatement<?, ?> parent,
             final @NonNull QName nodeIdentifier) {
         final DataTreeEffectiveStatement<?> ret = parent.findDataTreeNode(nodeIdentifier).orElseThrow(
     private @NonNull DataTreeEffectiveStatement<?> pushData(final @NonNull DataTreeAwareEffectiveStatement<?, ?> parent,
             final @NonNull QName nodeIdentifier) {
         final DataTreeEffectiveStatement<?> ret = parent.findDataTreeNode(nodeIdentifier).orElseThrow(
-            () -> new IllegalArgumentException("Schema tree child " + nodeIdentifier + " not present"));
+            () -> new IllegalArgumentException("Data tree child " + nodeIdentifier + " not present"));
         deque.push(ret);
         clean = false;
         return ret;
         deque.push(ret);
         clean = false;
         return ret;