nxt.util

## Class BooleanExpression

- java.lang.Object
- - nxt.util.BooleanExpression

-     public class BooleanExpression
      extends java.lang.Object

  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 Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `BooleanExpression.BadSyntaxException`
    `static class` | `BooleanExpression.BooleanExpressionException`
    `static class` | `BooleanExpression.SemanticWarning`
    `static class` | `BooleanExpression.SemanticWarningType`
    `static class` | `BooleanExpression.SyntaxError`
    `static class` | `BooleanExpression.Value`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static char` | `CONJUNCTION_OPERATOR`
    `static char` | `DISJUNCTION_OPERATOR`
    `static char` | `NEGATION_OPERATOR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BooleanExpression(java.lang.String expression)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `BooleanExpression.Value` | `evaluate(java.util.Map<java.lang.String,BooleanExpression.Value> variableValues)` Evaluates the expression with the provided variable values.
    `static boolean` | `fastImplicationCheck(BooleanExpression antecedent, BooleanExpression consequent)` Performs fast check whether "antecedent -> consequent" evaluates to TRUE.
    `int` | `getLiteralsCount()`
    `java.util.List<BooleanExpression.SemanticWarning>` | `getSemanticWarnings()`
    `BooleanExpression.BadSyntaxException` | `getSyntaxException()`
    `java.util.Set<java.lang.String>` | `getVariables()` Returns the set of variables used is this expression
    `boolean` | `hasErrors(boolean treatWarningsAsErrors)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CONJUNCTION_OPERATOR

          public static final char CONJUNCTION_OPERATOR

      See Also:
        Constant Field Values

    - #### DISJUNCTION_OPERATOR

          public static final char DISJUNCTION_OPERATOR

      See Also:
        Constant Field Values

    - #### NEGATION_OPERATOR

          public static final char NEGATION_OPERATOR

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### BooleanExpression

          public BooleanExpression(java.lang.String expression)

      Parameters:
        `expression` - The expression string in disjunctive normal form

  - ### Method Detail

    - #### evaluate

          public BooleanExpression.Value evaluate(java.util.Map<java.lang.String,BooleanExpression.Value> variableValues)
                                           throws BooleanExpression.BadSyntaxException

      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.Value`s
      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 java.util.Set<java.lang.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 java.util.List<BooleanExpression.SemanticWarning> getSemanticWarnings()