Add Inference.isEmpty() 37/107437/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 16 Aug 2023 08:48:38 +0000 (10:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 16 Aug 2023 08:50:43 +0000 (10:50 +0200)
Downstreams need logic to adjust the inference unless it is empty.
Expose an isEmpty() method, which efficiently indicates whether the
inference is empty.

Change-Id: Ief6df4d8c2e1db34ea65bb6bdbd7e47525683dad
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 e05d2e32556c1bd8ce1d6c9ff15f74943542d89b..c5cde35a9dc8b109c27fff8818ca6e1b63da50ce 100644 (file)
@@ -119,6 +119,16 @@ public final class SchemaInferenceStack implements Mutable, EffectiveModelContex
             return ImmutableList.copyOf(deque);
         }
 
+        /**
+         * Return {@code true} if this inference is empty. This is a more efficient alternative to
+         * {@code statementPath().isEmpty()}.
+         *
+         * @return {@code true} if {@link #statementPath()} returns an empty list
+         */
+        public boolean isEmpty() {
+            return deque.isEmpty();
+        }
+
         /**
          * Convert this inference into a {@link SchemaInferenceStack}.
          *