public final class ExprUtils
extends java.lang.Object
Modifier and Type | Method and 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 {@code (exprs[0] && ...
|
static Node |
getDisjunction(Node... exprs)
Performs logical disjunction {@code (exprs[0] || ...
|
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 |
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 <T extends java.lang.Enum<? extends T>> |
isOperation(Node expr,
java.util.List<T> opIds)
Checks whether the expression is represented by one of the specified operations.
|
static <T extends java.lang.Enum<? extends T>> |
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.
|
public static boolean isType(DataTypeId typeId, Node... exprs)
DataTypeId
level).typeId
- Expected data type identifier.exprs
- Expressions to be checked.true
if all expression types match the type specified by
the typeId
argument or false
otherwise.java.lang.IllegalArgumentException
- if the expression array is empty;
if any expression in the array is null
.public static boolean isType(DataType type, Node... exprs)
DataType
level).type
- Expected data type.exprs
- Expressions to be checked.true
if all expression types match the type specified by
the type
argument or false
otherwise.java.lang.IllegalArgumentException
- if the expression array is empty;
if any expression in the array is null
.public static boolean isKind(Node.Kind kind, Node... exprs)
Node.Kind
).kind
- Expected expression kind.exprs
- Expressions to be checked.true
if all expressions are of the specified kind or
false
otherwise.java.lang.IllegalArgumentException
- if the expression array is empty;
if any expression in the array is null
.public static <T extends java.lang.Enum<? extends T>> boolean isOperation(Node expr, T opId)
expr
- Expression to be checked.opId
- Operation identifier.true
if the expression is represented by the specified operation
or false
otherwise.java.lang.IllegalArgumentException
- if any of the parameters is null
.public static <T extends java.lang.Enum<? extends T>> boolean isOperation(Node expr, java.util.List<T> opIds)
expr
- Expression to be checked.opIds
- List of operation identifiers.true
if the expression is represented by one of the specified operations
or false
otherwise.java.lang.IllegalArgumentException
- if any of the parameters is null
; if the list of
operation identifiers is empty.public static boolean isValue(Node expr)
expr
- Expression to be checked.true
if the expression is a value or false
otherwise.java.lang.IllegalArgumentException
- if the parameter is null
.public static boolean isVariable(Node expr)
expr
- Expression to be checked.true
if the expression is a variable or false
otherwise.java.lang.IllegalArgumentException
- if the parameter is null
.public static boolean isCondition(Node expr)
expr
- Expression to be checked.true
if the expression is logical (can be evaluated to boolean) or
false
otherwise.java.lang.IllegalArgumentException
- if the parameter is null
.public static boolean isAtomicCondition(Node expr)
expr
- Expression to be checked.true
if the expression is an atomic logical expression or false
otherwise.java.lang.IllegalArgumentException
- if the parameter is null
.public static boolean hasBindings(Node expr)
expr
- Expression to be checked.true
if the expression tree contains bindings (nodes of type BINDING) or
false
otherwise.java.lang.IllegalArgumentException
- if the parameter is null
.public static boolean isConstant(Node expr)
expr
- Expression to be checked.true
if the expression is a constant expression or false
otherwise.java.lang.IllegalArgumentException
- if the parameter is null
.public static Node getConjunction(Node... exprs)
(exprs[0] && ... && exprs[n-1])
of the specified
expressions and returns the resulting expression.exprs
- Expressions to be combined.java.lang.IllegalArgumentException
- if any argument in the array is null
;
if no arguments are provided; if an argument is not a logical expression.public static Node getDisjunction(Node... exprs)
(exprs[0] || ... || exprs[n-1])
of the specified
expressions and returns the resulting expression.exprs
- Expressions to be combined.java.lang.IllegalArgumentException
- if any argument in the array is null
;
if no arguments are provided; if an argument is not a logical expression.public static Node getNegation(Node... exprs)
(!getConjunction(exprs[0], ..., exprs[n-1]))
of the specified
expressions combined with conjunction and returns the resulting expression.exprs
- Expressions to be combined.java.lang.IllegalArgumentException
- if any argument in the array is null
; if no arguments
are provided; if an argument is not a logical expression.public static Node getComplement(Node... exprs)
!(getDisjunction(exprs[0], ..., exprs[n-1])
of
the specified expressions combined with disjunction and returns the resulting expression.exprs
- Expressions to be combined.java.lang.IllegalArgumentException
- if any argument in the array is null
; if no arguments are
provided; if an argument is not a logical expression.public static boolean areComplete(Node... exprs)
!(getComplement(exprs[0], ..., exprs[n-1]) is SAT)
. N.B. The method uses the default
constraint solver to perform the check.exprs
- Conditions (logical expressions) to be checked.true
if the conditions are complete or false
otherwise.java.lang.IllegalArgumentException
- if any argument in the array is null
;
if no arguments are provided; if an argument is not a logical expression.public static boolean areCompatible(Node... exprs)
(getConjunction(exprs[0], ..., exprs[n-1]) is SAT)
. N.B. The method uses the default
constraint solver to perform the check.exprs
- Conditions (logical expressions) to be checked.true
if the conditions are compatible or false
otherwise.java.lang.IllegalArgumentException
- if any argument in the array is null
; if no arguments are
provided; if an argument is not a logical expression.public static boolean isSAT(Node expr)
expr
- Expression to be checked.true
if the expression is satisfiable or false
otherwise.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.public static java.util.Collection<NodeVariable> getVariables(Node expr)
expr
- Expression to be processed.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.public static java.util.Collection<NodeVariable> getVariables(java.lang.Iterable<Node> exprs)
exprs
- Collection of expressions to be processed.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.