Package nxt.util
Class BooleanExpression
java.lang.Object
nxt.util.BooleanExpression
A boolean expression in disjunctive normal form - i.e. a disjunction of one or more conjunctions of one or more literals
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic enumstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charstatic final charstatic final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(Map<String, BooleanExpression.Value> variableValues) Evaluates the expression with the provided variable values.static booleanfastImplicationCheck(BooleanExpression antecedent, BooleanExpression consequent) Performs fast check whether "antecedent -> consequent" evaluates to TRUE.intReturns the set of variables used is this expressionbooleanhasErrors(boolean treatWarningsAsErrors)
-
Field Details
-
CONJUNCTION_OPERATOR
public static final char CONJUNCTION_OPERATOR- See Also:
-
DISJUNCTION_OPERATOR
public static final char DISJUNCTION_OPERATOR- See Also:
-
NEGATION_OPERATOR
public static final char NEGATION_OPERATOR- See Also:
-
-
Constructor Details
-
BooleanExpression
- Parameters:
expression- The expression string in disjunctive normal form
-
-
Method Details
-
evaluate
public BooleanExpression.Value evaluate(Map<String, BooleanExpression.Value> variableValues) throws BooleanExpression.BadSyntaxExceptionEvaluates the expression with the provided variable values. If for some of the expression variables (seegetVariables()), there is no value in the variableValues map (or the value is null), the value is consideredBooleanExpression.Value.UNKNOWN. In that case, the result may also beBooleanExpression.Value.UNKNOWN- meaning that currently we cannot evaluate the expression to neitherBooleanExpression.Value.TRUEorBooleanExpression.Value.FALSE. But it is not necessaryBooleanExpression.Value.UNKNOWN- the available values may still be enough to return a definitive result- Parameters:
variableValues- The keys are variable names, the values are the respective booleanBooleanExpression.Values- Returns:
- The result from evaluating the expression
- Throws:
BooleanExpression.BadSyntaxException- in case of error in the expression syntax
-
fastImplicationCheck
public static boolean fastImplicationCheck(BooleanExpression antecedent, BooleanExpression consequent) throws BooleanExpression.BadSyntaxException Performs fast check whether "antecedent -> consequent" evaluates to TRUE. The implication "antecedent -> consequent" evaluates to TRUE when the antecedent is more restrictive than the consequent, i.e. when in no case the antecedent will be TRUE if the consequent is FALSE. In other words, if consequent is FALSE, then antecedent must also be FALSE. The current implementation only uses the boolean algebra laws and does not create the full truth table of the expression. So if this method returns true, this means that "antecedent -> consequent" evaluates to TRUE, but if the method returns false, it is still possible that "antecedent -> consequent" evaluates to TRUE - e.g. if the antecedent is always equal to FALSE, or the consequent is always equal to TRUE- Parameters:
antecedent- The antecedent of the conditionalconsequent- The consequent of the conditional- Returns:
- true if the boolean expression "antecedent -> consequent" evaluates to TRUE
- Throws:
BooleanExpression.BadSyntaxException- in case of error in the expressions syntax
-
getVariables
Returns the set of variables used is this expression- Returns:
- the set of variables used is this expression
-
getLiteralsCount
public int getLiteralsCount() -
hasErrors
public boolean hasErrors(boolean treatWarningsAsErrors) -
getSyntaxException
-
getSemanticWarnings
-