Class ExprUtils


  • public final class ExprUtils
    extends java.lang.Object
    The ExprUtils class provides utility methods to work with logical expressions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areCompatible​(Node... exprs)
      Checks whether the specified logical conditions are compatible (getConjunction(exprs[0], ..., exprs[n-1]) is SAT).
      static boolean areComplete​(Node... exprs)
      Checks whether the specified logical conditions are complete !(getComplement(exprs[0], ..., exprs[n-1]) is SAT).
      static Node getComplement​(Node... exprs)
      Performs logical complement (negation) !(getDisjunction(exprs[0], ..., exprs[n-1]) of the specified expressions combined with disjunction and returns the resulting expression.
      static Node getConjunction​(Node... exprs)
      Performs logical conjunction (exprs[0] && ... && exprs[n-1]) of the specified expressions and returns the resulting expression.
      static Node getDisjunction​(Node... exprs)
      Performs logical disjunction (exprs[0] || ... || exprs[n-1]) of the specified expressions and returns the resulting expression.
      static Node getNegation​(Node... exprs)
      Performs logical negation (!getConjunction(exprs[0], ..., exprs[n-1])) of the specified expressions combined with conjunction and returns the resulting expression.
      static java.util.Collection<NodeVariable> getVariables​(java.lang.Iterable<Node> exprs)
      Returns all variables used in the specified expressions.
      static java.util.Collection<NodeVariable> getVariables​(Node expr)
      Returns all variables used in the specified expression.
      static boolean hasBindings​(Node expr)
      Checks whether the specified expression tree contains bindings (nodes of type BINDING).
      static boolean isAtomicCondition​(Node expr)
      Checks whether the specified expression is an atomic logical expression (can be evaluated to boolean and does not include logical operations to combine expressions such as: AND, OR, NOT, XOR and IMPL).
      static boolean isBinding​(Node expr)
      Checks whether the specified expression is represented by a binding.
      static boolean isCondition​(Node expr)
      Checks whether the specified expression is a logical expression (can be evaluated to boolean).
      static boolean isConstant​(Node expr)
      Checks whether the given expression is a constant expression (can be evaluated to a constant value).
      static boolean isKind​(Node.Kind kind, Node... exprs)
      Checks whether all of the specified expressions are of the specified kind (see Node.Kind).
      static boolean isOperation​(Node expr)
      Checks whether the expression is represented by an operation.
      static boolean isOperation​(Node expr, java.lang.Enum<?>... opIds)
      Checks whether the expression is represented by one of the specified operations.
      static <T extends java.lang.Enum<? extends T>>
      boolean
      isOperation​(Node expr, java.util.Collection<T> opIds)
      Checks whether the expression is represented by one of the specified operations.
      static <T extends java.lang.Enum<? extends T>>
      boolean
      isOperation​(Node expr, T opId)
      Checks whether the expression is represented by the specified operation.
      static boolean isSat​(Node expr)
      Checks whether the specified expression is satisfiable.
      static boolean isType​(DataTypeId typeId, Node... exprs)
      Checks whether all of the specified expressions have the specified type (types are compared on the DataTypeId level).
      static boolean isType​(DataType type, Node... exprs)
      Checks whether all of the specified expressions have the specified type (types are compared on the DataType level).
      static boolean isValue​(Node expr)
      Checks whether the specified expression is represented by a constant value.
      static boolean isVariable​(Node expr)
      Checks whether the specified expression is represented by a variable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isType

        public static boolean isType​(DataTypeId typeId,
                                     Node... exprs)
        Checks whether all of the specified expressions have the specified type (types are compared on the DataTypeId level).
        Parameters:
        typeId - Expected data type identifier.
        exprs - Expressions to be checked.
        Returns:
        true if all expression types match the type specified by the typeId argument or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the expression array is empty; if any expression in the array is null.
      • isType

        public static boolean isType​(DataType type,
                                     Node... exprs)
        Checks whether all of the specified expressions have the specified type (types are compared on the DataType level).
        Parameters:
        type - Expected data type.
        exprs - Expressions to be checked.
        Returns:
        true if all expression types match the type specified by the type argument or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the expression array is empty; if any expression in the array is null.
      • isKind

        public static boolean isKind​(Node.Kind kind,
                                     Node... exprs)
        Checks whether all of the specified expressions are of the specified kind (see Node.Kind).
        Parameters:
        kind - Expected expression kind.
        exprs - Expressions to be checked.
        Returns:
        true if all expressions are of the specified kind or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the expression array is empty; if any expression in the array is null.
      • isOperation

        public static boolean isOperation​(Node expr)
        Checks whether the expression is represented by an operation.
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is represented by an operation or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the argument is null.
      • isOperation

        public static <T extends java.lang.Enum<? extends T>> boolean isOperation​(Node expr,
                                                                                  T opId)
        Checks whether the expression is represented by the specified operation.
        Type Parameters:
        T - Operation identifier type.
        Parameters:
        expr - Expression to be checked.
        opId - Operation identifier.
        Returns:
        true if the expression is represented by the specified operation or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • isOperation

        public static <T extends java.lang.Enum<? extends T>> boolean isOperation​(Node expr,
                                                                                  java.util.Collection<T> opIds)
        Checks whether the expression is represented by one of the specified operations.
        Type Parameters:
        T - Operation identifier type.
        Parameters:
        expr - Expression to be checked.
        opIds - Collection of operation identifiers.
        Returns:
        true if the expression is represented by one of the specified operations or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null; if the list of operation identifiers is empty.
      • isOperation

        public static boolean isOperation​(Node expr,
                                          java.lang.Enum<?>... opIds)
        Checks whether the expression is represented by one of the specified operations.
        Parameters:
        expr - Expression to be checked.
        opIds - List of operation identifiers.
        Returns:
        true if the expression is represented by one of the specified operations or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null; if the list of operation identifiers is empty.
      • isValue

        public static boolean isValue​(Node expr)
        Checks whether the specified expression is represented by a constant value.
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is a value or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • isVariable

        public static boolean isVariable​(Node expr)
        Checks whether the specified expression is represented by a variable.
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is a variable or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • isBinding

        public static boolean isBinding​(Node expr)
        Checks whether the specified expression is represented by a binding.
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is a binding or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • isCondition

        public static boolean isCondition​(Node expr)
        Checks whether the specified expression is a logical expression (can be evaluated to boolean).
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is logical (can be evaluated to boolean) or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • isAtomicCondition

        public static boolean isAtomicCondition​(Node expr)
        Checks whether the specified expression is an atomic logical expression (can be evaluated to boolean and does not include logical operations to combine expressions such as: AND, OR, NOT, XOR and IMPL).
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is an atomic logical expression or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • hasBindings

        public static boolean hasBindings​(Node expr)
        Checks whether the specified expression tree contains bindings (nodes of type BINDING).
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression tree contains bindings (nodes of type BINDING) or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • isConstant

        public static boolean isConstant​(Node expr)
        Checks whether the given expression is a constant expression (can be evaluated to a constant value). An expression is considered constant as long as it does not contain unassigned variables (bindings are taken into consideration).
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is a constant expression or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • getConjunction

        public static Node getConjunction​(Node... exprs)
        Performs logical conjunction (exprs[0] && ... && exprs[n-1]) of the specified expressions and returns the resulting expression.
        Parameters:
        exprs - Expressions to be combined.
        Returns:
        A logical conjunction of the specified expressions.
        Throws:
        java.lang.IllegalArgumentException - if any argument in the array is null; if no arguments are provided; if an argument is not a logical expression.
      • getDisjunction

        public static Node getDisjunction​(Node... exprs)
        Performs logical disjunction (exprs[0] || ... || exprs[n-1]) of the specified expressions and returns the resulting expression.
        Parameters:
        exprs - Expressions to be combined.
        Returns:
        A logical disjunction of the specified expressions.
        Throws:
        java.lang.IllegalArgumentException - if any argument in the array is null; if no arguments are provided; if an argument is not a logical expression.
      • getNegation

        public static Node getNegation​(Node... exprs)
        Performs logical negation (!getConjunction(exprs[0], ..., exprs[n-1])) of the specified expressions combined with conjunction and returns the resulting expression.
        Parameters:
        exprs - Expressions to be combined.
        Returns:
        A logical negation of the specified expressions.
        Throws:
        java.lang.IllegalArgumentException - if any argument in the array is null; if no arguments are provided; if an argument is not a logical expression.
      • getComplement

        public static Node getComplement​(Node... exprs)
        Performs logical complement (negation) !(getDisjunction(exprs[0], ..., exprs[n-1]) of the specified expressions combined with disjunction and returns the resulting expression.
        Parameters:
        exprs - Expressions to be combined.
        Returns:
        A logical complement of the specified expressions.
        Throws:
        java.lang.IllegalArgumentException - if any argument in the array is null; if no arguments are provided; if an argument is not a logical expression.
      • areComplete

        public static boolean areComplete​(Node... exprs)
        Checks whether the specified logical conditions are complete !(getComplement(exprs[0], ..., exprs[n-1]) is SAT). N.B. The method uses the default constraint solver to perform the check.
        Parameters:
        exprs - Conditions (logical expressions) to be checked.
        Returns:
        true if the conditions are complete or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if any argument in the array is null; if no arguments are provided; if an argument is not a logical expression.
      • areCompatible

        public static boolean areCompatible​(Node... exprs)
        Checks whether the specified logical conditions are compatible (getConjunction(exprs[0], ..., exprs[n-1]) is SAT). N.B. The method uses the default constraint solver to perform the check.
        Parameters:
        exprs - Conditions (logical expressions) to be checked.
        Returns:
        true if the conditions are compatible or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if any argument in the array is null; if no arguments are provided; if an argument is not a logical expression.
      • isSat

        public static boolean isSat​(Node expr)
        Checks whether the specified expression is satisfiable. N.B. The method uses the default constraint solver to perform the check.
        Parameters:
        expr - Expression to be checked.
        Returns:
        true if the expression is satisfiable or false otherwise.
        Throws:
        java.lang.IllegalArgumentException - (1) if the parameter is null; (2) if the expression description contains errors that prevent the solver engine from solving it in a correct way; (3) if the solver is unable to solve a constraint based on the given expression due to limitations of its implementation.
        java.lang.IllegalStateException - if the solver engine returned results with an unknown status.
      • getVariables

        public static java.util.Collection<NodeVariable> getVariables​(Node expr)
        Returns all variables used in the specified expression.
        Parameters:
        expr - Expression to be processed.
        Returns:
        A collection of all variables used in the specified expression.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
        java.lang.IllegalStateException - if the method finds nodes that refer to different variables that have the same name.
      • getVariables

        public static java.util.Collection<NodeVariable> getVariables​(java.lang.Iterable<Node> exprs)
        Returns all variables used in the specified expressions.
        Parameters:
        exprs - Collection of expressions to be processed.
        Returns:
        A collection of all variables used in the specified expressions.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
        java.lang.IllegalStateException - if the method finds nodes that refer to different variables that have the same name.