Add Inference.of() 29/109129/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Nov 2023 19:15:53 +0000 (20:15 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Nov 2023 19:16:20 +0000 (20:16 +0100)
Improve documentation and a shortcut method to create an empty
Inference.

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

index f42464450f117af22ebf19e105b877120b8c629e..2a71b1e9a6d3ab6e2d55c1b974b1252544f2e900 100644 (file)
@@ -96,17 +96,29 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
         }
 
         /**
-         * Create a new stack backed by an effective model and set up to point and specified data tree node.
+         * Create a new {@link Inference} backed by an effective model.
          *
-         * @param effectiveModel EffectiveModelContext to which this stack is attached
+         * @param modelContext {@link EffectiveModelContext} to which the inference is attached
+         * @return A new @link Inference}
+         * @throws NullPointerException if {@code modelContext} is {@code null}
+         */
+        public static @NonNull Inference of(final EffectiveModelContext modelContext) {
+            return new Inference(modelContext, new ArrayDeque<>(), null, 0, true);
+        }
+
+        /**
+         * Create a new {@link Inference} backed by an effective model and set up to point and specified data tree node.
+         *
+         * @param modelContext {@link EffectiveModelContext} to which the inference is attached
          * @param qnames Data tree path qnames
-         * @return A new stack
+         * @return A new @link Inference}
          * @throws NullPointerException if any argument is {@code null} or path contains a {@code null} element
          * @throws IllegalArgumentException if a path element cannot be found
          */
-        public static @NonNull Inference ofDataTreePath(final EffectiveModelContext effectiveModel,
+        public static @NonNull Inference ofDataTreePath(final EffectiveModelContext modelContext,
                 final QName... qnames) {
-            return SchemaInferenceStack.ofDataTreePath(effectiveModel, qnames).toInference();
+            return qnames.length == 0 ? of(modelContext)
+                : SchemaInferenceStack.ofDataTreePath(modelContext, qnames).toInference();
         }
 
         @Override