Bug 6868 - [Yang 1.1] Argument of "If-feature" statement may be a boolean expression...
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / stmt / IfFeatureStatement.java
index 6604678d7b617fe935016ab477900c6efbb88a47..2ea8ab52dbe8e0e3eb5d83457fa5d2af42bf178a 100644 (file)
@@ -7,12 +7,47 @@
  */
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
+import com.google.common.annotations.Beta;
+import java.util.Set;
+import java.util.function.Predicate;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 
+/**
+ * Represents YANG if-feature statement.
+ *
+ * The "if-feature" statement makes its parent statement conditional.
+ */
+// FIXME: IfFeatureStatement should extend DeclaredStatement<Predicate<Set<QName>>> and
+// IfFeatureStatementImpl for Yang1.0 reworked to extend AbstractDeclaredStatement<Predicate<Set<QName>>>.
 public interface IfFeatureStatement extends DeclaredStatement<QName> {
 
+    /**
+     * Used in YANG 1.0 (RFC6020) implementation of IfFeatureStatement
+     * where the argument is the name of a feature
+     * as defined by a "feature" statement.
+     *
+     * To be replaced by {@link #getIfFeaturePredicate() getIfFeaturePredicate} method.
+     *
+     * @return QName object for the feature
+     */
+    @Deprecated
     @Nonnull QName getName();
-}
 
+    /**
+     * This method should be overridden for all Yang 1.1 implementation.
+     * The default implementation is only applicable for Yang 1.0 (RFC6020).
+     *
+     * In Yang 1.1 (RFC7950) implementation of IfFeatureStatement, the
+     * argument is a boolean expression over feature names defined by
+     * "feature" statements. Hence, add implementation to return a
+     * predicate on a collection of features against which to evaluate.
+     *
+     * @return Predicate on a collection of QNames against which to evaluate
+     */
+    @Beta
+    @Nonnull default Predicate<Set<QName>> getIfFeaturePredicate() {
+        return setQnames -> setQnames.contains(getName());
+    }
+}
\ No newline at end of file