Add SchemaInferenceStack.Inference.ofDataTreePath() 78/95178/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 15 Feb 2021 18:15:48 +0000 (19:15 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 15 Feb 2021 19:02:35 +0000 (19:02 +0000)
SchemaInferenceStack.ofDataTreePath() is very useful for testing
yang-data contracts -- and it is then coupled with .toInference().

Inference.ofDataTreePath() does the same thing, providing a more
ergonomic use.

JIRA: YANGTOOLS-1231
Change-Id: Id9512630b282ed9a3c091325d5e3164ee9a7b15f
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 7e8ff081656e2486960b06c875afeadde2d56758..caef0311acd7c4723bf9f56fb72d58941306f3c9 100644 (file)
@@ -78,6 +78,20 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
             this.clean = clean;
         }
 
+        /**
+         * 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
+         * @param qnames Data tree path qnames
+         * @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 Inference ofDataTreePath(final EffectiveModelContext effectiveModel,
+                final QName... qnames) {
+            return SchemaInferenceStack.ofDataTreePath(effectiveModel, qnames).toInference();
+        }
+
         @Override
         public List<EffectiveStatement<?, ?>> statementPath() {
             return ImmutableList.copyOf(deque.descendingIterator());