Package nxt.util

Class BooleanExpression

java.lang.Object
nxt.util.BooleanExpression

public class BooleanExpression extends Object
A boolean expression in disjunctive normal form - i.e. a disjunction of one or more conjunctions of one or more literals
  • Field Details

  • Constructor Details

    • BooleanExpression

      public BooleanExpression(String expression)
      Parameters:
      expression - The expression string in disjunctive normal form
  • Method Details

    • evaluate

      Evaluates the expression with the provided variable values. If for some of the expression variables (see getVariables()), there is no value in the variableValues map (or the value is null), the value is considered BooleanExpression.Value.UNKNOWN. In that case, the result may also be BooleanExpression.Value.UNKNOWN - meaning that currently we cannot evaluate the expression to neither BooleanExpression.Value.TRUE or BooleanExpression.Value.FALSE. But it is not necessary BooleanExpression.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 boolean BooleanExpression.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 conditional
      consequent - 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

      public Set<String> 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

      public BooleanExpression.BadSyntaxException getSyntaxException()
    • getSemanticWarnings

      public List<BooleanExpression.SemanticWarning> getSemanticWarnings()