BUG-6972: Add OptionaBoolean utility
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 6c148f50a679c499b0e242c40de81479a3a5eb49..59982028024cac000cb768b4a320bbe6d35f741b 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.Optional;
 import java.util.Set;
 import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.util.OptionalBoolean;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
@@ -91,13 +92,15 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     private Collection<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.of();
     private StatementMap substatements = StatementMap.empty();
 
-    private Boolean supportedByFeatures = null;
     private boolean isSupportedToBuildEffective = true;
     private ModelProcessingPhase completedPhase = null;
     private D declaredInstance;
     private E effectiveInstance;
     private int order = 0;
 
+    // BooleanFields value
+    private byte supportedByFeatures;
+
     StatementContextBase(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference ref,
             final String rawArgument) {
         this.definition = Preconditions.checkNotNull(def);
@@ -145,15 +148,19 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
     @Override
     public boolean isSupportedByFeatures() {
-        if (supportedByFeatures == null) {
-            final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
-                SupportedFeatures.SUPPORTED_FEATURES);
-            // If the set of supported features has not been provided, all features are supported by default.
-            supportedByFeatures = supportedFeatures == null ? Boolean.TRUE
-                    : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+        if (OptionalBoolean.isPresent(supportedByFeatures)) {
+            return OptionalBoolean.get(supportedByFeatures);
         }
 
-        return supportedByFeatures.booleanValue();
+        // If the set of supported features has not been provided, all features are supported by default.
+        final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
+            SupportedFeatures.SUPPORTED_FEATURES);
+        final boolean ret = supportedFeatures == null ? true
+            : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+
+        supportedByFeatures = OptionalBoolean.of(ret);
+        return ret;
+
     }
 
     @Override