public OrFeatureAllowNulls(BooleanFeature<T>... booleanFeatures) { super(); this.booleanFeatures = booleanFeatures; String name = ""; boolean firstFeature = true; for (BooleanFeature<T> booleanFeature : booleanFeatures) { if (!firstFeature) name += "|"; name += booleanFeature.getName(); firstFeature = false; } this.setName(name); }
@Override public FeatureResult<Boolean> checkInternal(T context, RuntimeEnvironment env) { FeatureResult<Boolean> featureResult = null; boolean booleanResult = false; for (BooleanFeature<T> booleanFeature : booleanFeatures) { FeatureResult<Boolean> result = booleanFeature.check(context, env); boolean value = false; if (result != null) { value = result.getOutcome(); } booleanResult = booleanResult || value; if (booleanResult) break; } featureResult = this.generateResult(booleanResult); return featureResult; }
public IfThenElseStringFeature( BooleanFeature<T> condition, StringFeature<T> thenFeature, StringFeature<T> elseFeature) { super(); this.condition = condition; this.thenFeature = thenFeature; this.elseFeature = elseFeature; this.setName( "IfThenElse(" + condition.getName() + "," + thenFeature.getName() + "," + elseFeature.getName() + ")"); }
public IfThenElseGenericFeature( BooleanFeature<T> condition, Feature<T, Y> thenFeature, Feature<T, Y> elseFeature) { super(); this.condition = condition; this.thenFeature = thenFeature; this.elseFeature = elseFeature; this.setName( "IfThenElse(" + condition.getName() + "," + thenFeature.getName() + "," + elseFeature.getName() + ")"); }
@Override protected FeatureResult<String> checkInternal(T context, RuntimeEnvironment env) { FeatureResult<String> featureResult = null; FeatureResult<Boolean> conditionResult = condition.check(context, env); if (conditionResult != null) { boolean conditionOutcome = conditionResult.getOutcome(); if (conditionOutcome) { FeatureResult<String> thenFeatureResult = thenFeature.check(context, env); if (thenFeatureResult != null) { String result = thenFeatureResult.getOutcome(); featureResult = this.generateResult(result); } } else { FeatureResult<String> elseFeatureResult = elseFeature.check(context, env); if (elseFeatureResult != null) { String result = elseFeatureResult.getOutcome(); featureResult = this.generateResult(result); } } } return featureResult; }