Refactor ContainerEffectiveStatementImpl
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / EffectiveStatementMixins.java
index 1584c90d12d7ac45f6cf5506d06e05857c0ed71b..b87da7e799ae67bccb3f28e124ae3160bbb26dc3 100644 (file)
@@ -263,6 +263,18 @@ public final class EffectiveStatementMixins {
         }
     }
 
+    /**
+     * Bridge between {@link EffectiveStatementWithFlags} and {@code presence} statement.
+     *
+     * @param <A> Argument type ({@link Void} if statement does not have argument.)
+     * @param <D> Class representing declared version of this statement.
+     */
+    public interface PresenceMixin<A, D extends DeclaredStatement<A>> extends EffectiveStatementWithFlags<A, D> {
+        default boolean presence() {
+            return (flags() & FlagsBuilder.PRESENCE) != 0;
+        }
+    }
+
     /**
      * Bridge between {@link EffectiveStatementWithFlags} and {@link SchemaNode}.
      *
@@ -320,7 +332,7 @@ public final class EffectiveStatementMixins {
 
         @NonNullByDefault
         final class FlagsBuilder implements Mutable {
-            // We still have 25 flags remaining
+            // We still have 24 flags remaining
             static final int STATUS_CURRENT       = 0x0001;
             static final int STATUS_DEPRECATED    = 0x0002;
             static final int STATUS_OBSOLETE      = 0x0003;
@@ -334,6 +346,7 @@ public final class EffectiveStatementMixins {
             private static final int MASK_HISTORY = 0x0030;
 
             static final int USER_ORDERED         = 0x0040;
+            static final int PRESENCE             = 0x0080;
 
             private int flags;
 
@@ -373,6 +386,15 @@ public final class EffectiveStatementMixins {
                 return this;
             }
 
+            public FlagsBuilder setPresence(final boolean presence) {
+                if (presence) {
+                    flags |= PRESENCE;
+                } else {
+                    flags &= ~PRESENCE;
+                }
+                return this;
+            }
+
             public FlagsBuilder setStatus(final Status status) {
                 final int bits;
                 switch (status) {