Add OrderedByAwareEffectiveStatement 01/99701/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Feb 2022 22:16:07 +0000 (23:16 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 12 Feb 2022 09:05:43 +0000 (10:05 +0100)
Add OrderedByAwareEffectiveStatement and UserOrderedAware interfaces to
capture inquiries about how child data nodes are to be ordered.

JIRA: YANGTOOLS-1399
Change-Id: I52e4da6bc86593730f7927e8b5435dd9a80e4677
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/LeafListSchemaNode.java
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ListSchemaNode.java
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/UserOrderedAware.java [new file with mode: 0644]
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/LeafListEffectiveStatement.java
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ListEffectiveStatement.java
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/OrderedByAwareEffectiveStatement.java [new file with mode: 0644]
model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/stmt/impl/eff/AbstractLeafListEffectiveStatement.java
model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/stmt/impl/eff/AbstractListEffectiveStatement.java
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/EffectiveStatementMixins.java

index 68a8f01ad0c7ddba67b0f607ec6d20a855cab0e4..f4ac0a103ee48aa12bde6ef0ba577c17632c3d92 100644 (file)
@@ -15,15 +15,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement
  * Interface describing YANG 'leaf-list' statement.
  */
 public interface LeafListSchemaNode extends TypedDataSchemaNode, MustConstraintAware, ElementCountConstraintAware,
-        EffectiveStatementEquivalent<LeafListEffectiveStatement> {
-    /**
-     * YANG 'ordered-by' statement. It defines whether the order of entries
-     * within this leaf-list are determined by the user or the system. If not
-     * present, default is false.
-     *
-     * @return true if ordered-by argument is "user", false otherwise
-     */
-    boolean isUserOrdered();
+        UserOrderedAware<LeafListEffectiveStatement> {
 
     /**
      * Return the default value of this leaf-list, as per the rules outlined in
index 48dd9b79943b5d0bc131861737fd119d1b45f2b7..7b27eaece202203f9ed9b3cae60beac3be5c980b 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.UniqueEffectiveStatement;
  */
 public interface ListSchemaNode extends DataNodeContainer, AugmentationTarget, DataSchemaNode, ActionNodeContainer,
         NotificationNodeContainer, ElementCountConstraintAware, MustConstraintAware,
-        EffectiveStatementEquivalent<ListEffectiveStatement> {
+        UserOrderedAware<ListEffectiveStatement> {
     /**
      * Returns the list of leaf identifiers.
      *
@@ -31,14 +31,6 @@ public interface ListSchemaNode extends DataNodeContainer, AugmentationTarget, D
      */
     @NonNull List<@NonNull QName> getKeyDefinition();
 
-    /**
-     * YANG 'ordered-by' statement. It defines whether the order of entries within a list are determined by the user
-     * or the system. If not present, default is false.
-     *
-     * @return true if ordered-by argument is "user", false otherwise
-     */
-    boolean isUserOrdered();
-
     /**
      * Returns unique constraints.
      *
diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/UserOrderedAware.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/UserOrderedAware.java
new file mode 100644 (file)
index 0000000..96d625b
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.common.Ordering;
+import org.opendaylight.yangtools.yang.model.api.stmt.OrderedByAwareEffectiveStatement;
+
+/**
+ * Common interface for {@link DataSchemaNode}s which can have an {@code ordered-by} substatement.
+ *
+ * @param <E> Effective representation of the underlying YANG statement
+ */
+@Beta
+public interface UserOrderedAware<E extends OrderedByAwareEffectiveStatement<?, ?>>
+        extends EffectiveStatementEquivalent<E> {
+    /**
+     * YANG {@code ordered-by} statement. It defines whether the order of entries within this node are determined by the
+     * user or the system. If not present, default is false.
+     *
+     * @return true if ordered-by argument is {@code user}, false otherwise
+     */
+    default boolean isUserOrdered() {
+        return asEffectiveStatement().ordering() == Ordering.USER;
+    }
+}
index 27bf292efde9a2303c885dd583a99cd728cb613e..4d67fe35fc7f4981570053522b2ac8499ecce0be 100644 (file)
@@ -8,11 +8,18 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
+/**
+ * {@link EffectiveStatement} representation of a {@code leaf-list} statement as defined by
+ * <a href="https://datatracker.ietf.org/doc/html/rfc7950#section-7.7">RFC7950</a>.
+ */
 @Beta
-public interface LeafListEffectiveStatement extends DataTreeEffectiveStatement<LeafListStatement> {
+public interface LeafListEffectiveStatement extends DataTreeEffectiveStatement<LeafListStatement>,
+        OrderedByAwareEffectiveStatement<QName, LeafListStatement> {
     @Override
     default  StatementDefinition statementDefinition() {
         return YangStmtMapping.LEAF_LIST;
index eb717ac896dfeef82a1a8d3a339da5f215424041..157a44888e7503b0d8876e08cbe27f06c86f1b87 100644 (file)
@@ -10,11 +10,16 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 import com.google.common.annotations.Beta;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
+/**
+ * {@link EffectiveStatement} representation of a {@code list} statement as defined by
+ * <a href="https://datatracker.ietf.org/doc/html/rfc7950#section-7.8">RFC7950</a>.
+ */
 @Beta
 public interface ListEffectiveStatement extends DataTreeEffectiveStatement<ListStatement>,
-        DataTreeAwareEffectiveStatement<QName, ListStatement> {
+        DataTreeAwareEffectiveStatement<QName, ListStatement>, OrderedByAwareEffectiveStatement<QName, ListStatement> {
     @Override
     default  StatementDefinition statementDefinition() {
         return YangStmtMapping.LIST;
diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/OrderedByAwareEffectiveStatement.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/OrderedByAwareEffectiveStatement.java
new file mode 100644 (file)
index 0000000..2784004
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api.stmt;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.Ordering;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+/**
+ * An {@link EffectiveStatement} which can contain an {@link OrderedByEffectiveStatement}, controlling ordering of
+ * data elements. Absence of an {@code ordered-by} statement implies {@link Ordering#SYSTEM}. YANG statements using
+ * this interface are {@link LeafListEffectiveStatement} and {@link ListEffectiveStatement}.
+ *
+ * @param <A> Argument type ({@link Empty} if statement does not have argument.)
+ * @param <D> Class representing declared version of this statement.
+ */
+@Beta
+public interface OrderedByAwareEffectiveStatement<A, D extends DeclaredStatement<A>> extends EffectiveStatement<A, D> {
+    /**
+     * Return the effective {@link Ordering} of this statement.
+     *
+     * @return Effective ordering
+     */
+    default @NonNull Ordering ordering() {
+        return findFirstEffectiveSubstatementArgument(OrderedByEffectiveStatement.class).orElse(Ordering.SYSTEM);
+    }
+}
index b57e5b96fe49d77c8ca3ea5682a0f64a051c6ee4..d9458c7ce2763ce13469379cdc702dded46fa397 100644 (file)
@@ -21,11 +21,12 @@ import org.opendaylight.yangtools.yang.model.ri.type.ConcreteTypes;
 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.DataSchemaNodeMixin;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.MustConstraintMixin;
-import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.UserOrderedMixin;
+import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.UserOrderedAwareMixin;
 
 abstract class AbstractLeafListEffectiveStatement
         extends AbstractDeclaredEffectiveStatement.Default<QName, LeafListStatement>
-        implements LeafListEffectiveStatement, LeafListSchemaNode, UserOrderedMixin<QName, LeafListStatement>,
+        implements LeafListEffectiveStatement, LeafListSchemaNode,
+            UserOrderedAwareMixin<QName, LeafListStatement, LeafListEffectiveStatement>,
             DataSchemaNodeMixin<LeafListStatement>, MustConstraintMixin<QName, LeafListStatement> {
     private static final VarHandle TYPE;
 
@@ -67,11 +68,6 @@ abstract class AbstractLeafListEffectiveStatement
         return flags;
     }
 
-    @Override
-    public final boolean isUserOrdered() {
-        return userOrdered();
-    }
-
     @Override
     public final LeafListEffectiveStatement asEffectiveStatement() {
         return this;
index 05742d7dfe24547f5bb9d637ba5b2b91e9a7d11d..3b33f694cfa40463b85266f63d4ae6b64f2c7199 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.D
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.DataSchemaNodeMixin;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.MustConstraintMixin;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.NotificationNodeContainerMixin;
-import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.UserOrderedMixin;
+import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.UserOrderedAwareMixin;
 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.WhenConditionMixin;
 
 abstract class AbstractListEffectiveStatement
@@ -35,7 +35,7 @@ abstract class AbstractListEffectiveStatement
         implements ListEffectiveStatement, ListSchemaNode,
             ActionNodeContainerCompat<QName, ListStatement, ListEffectiveStatement>,
             NotificationNodeContainerCompat<QName, ListStatement, ListEffectiveStatement>,
-            DataSchemaNodeMixin<ListStatement>, UserOrderedMixin<QName, ListStatement>,
+            DataSchemaNodeMixin<ListStatement>, UserOrderedAwareMixin<QName, ListStatement, ListEffectiveStatement>,
             DataNodeContainerMixin<QName, ListStatement>, WhenConditionMixin<QName, ListStatement>,
             AugmentationTargetMixin<QName, ListStatement>, NotificationNodeContainerMixin<QName, ListStatement>,
             ActionNodeContainerMixin<QName, ListStatement>, MustConstraintMixin<QName, ListStatement> {
@@ -61,11 +61,6 @@ abstract class AbstractListEffectiveStatement
         return flags;
     }
 
-    @Override
-    public final boolean isUserOrdered() {
-        return userOrdered();
-    }
-
     @Override
     public final List<QName> getKeyDefinition() {
         return unmaskList(keyDefinition, QName.class);
index b0b0e6780b143a8070afd6d665384c0a4fa85561..0d8cbf53067ac3b86f177554d59f5f2b3875c3dd 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UserOrderedAware;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.api.WhenConditionAware;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
@@ -51,6 +52,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatem
 import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OrderedByAwareEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
@@ -336,9 +338,15 @@ public final class EffectiveStatementMixins {
      *
      * @param <A> Argument type ({@link Empty} if statement does not have argument.)
      * @param <D> Class representing declared version of this statement.
+     * @param <E> Class representing effective version of this statement.
      */
-    public interface UserOrderedMixin<A, D extends DeclaredStatement<A>> extends EffectiveStatementWithFlags<A, D> {
-        default boolean userOrdered() {
+    // FIXME: 9.0.0: remove this mixin once we have a properly-cached DataTree and JSON/XML codec tree and the speed
+    //               of isUserOrdered() is not really critical.
+    public interface UserOrderedAwareMixin<A, D extends DeclaredStatement<A>,
+            E extends OrderedByAwareEffectiveStatement<A, D>>
+            extends EffectiveStatementWithFlags<A, D>, UserOrderedAware<E> {
+        @Override
+        default boolean isUserOrdered() {
             return (flags() & FlagsBuilder.USER_ORDERED) != 0;
         }
     }