public class Expression
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Expression.ExpressionException
The expression evaluators exception class.
|
class |
Expression.Function
Abstract definition of a supported expression function.
|
class |
Expression.LazyFunction |
static interface |
Expression.LazyNumber
LazyNumber interface created for lazily evaluated functions
|
class |
Expression.Operator
Abstract definition of a supported operator.
|
class |
Expression.UnaryOperator |
| Modifier and Type | Field and Description |
|---|---|
static java.math.BigDecimal |
e
Definition of e: "Euler's number" as a constant, can be used in expressions as variable.
|
static int |
OPERATOR_PRECEDENCE_ADDITIVE
Additive operators precedence: + and -
|
static int |
OPERATOR_PRECEDENCE_AND
And operator precedence: &&
|
static int |
OPERATOR_PRECEDENCE_COMPARISON
Comparative operators precedence: <,>,<=,>=
|
static int |
OPERATOR_PRECEDENCE_EQUALITY
Equality operators precedence: =, ==, !=.
|
static int |
OPERATOR_PRECEDENCE_MULTIPLICATIVE
Multiplicative operators precedence: *,/,%
|
static int |
OPERATOR_PRECEDENCE_OR
Or operator precedence: ||
|
static int |
OPERATOR_PRECEDENCE_POWER
Power operator precedence: ^
|
static int |
OPERATOR_PRECEDENCE_UNARY
Unary operators precedence: + and - as prefix
|
static java.math.BigDecimal |
PI
Definition of PI as a constant, can be used in expressions as variable.
|
| Constructor and Description |
|---|
Expression(java.lang.String expression)
Creates a new expression instance from an expression string with a given default match context of
MathContext.DECIMAL32. |
Expression(java.lang.String expression,
java.math.MathContext defaultMathContext)
Creates a new expression instance from an expression string with a given default match context.
|
| Modifier and Type | Method and Description |
|---|---|
Function |
addFunction(Function function)
Adds a function to the list of supported functions
|
LazyFunction |
addLazyFunction(LazyFunction function)
Adds a lazy function function to the list of supported functions
|
<OPERATOR extends LazyOperator> |
addOperator(OPERATOR operator)
Adds an operator to the list of supported operators.
|
Expression |
and(java.lang.String variable,
java.math.BigDecimal value)
Sets a variable value.
|
Expression |
and(java.lang.String variable,
Expression.LazyNumber value)
Sets a variable value.
|
Expression |
and(java.lang.String variable,
java.lang.String value)
Sets a variable value.
|
boolean |
equals(java.lang.Object o) |
java.lang.Number |
eval()
Evaluates the expression.
|
java.lang.Number |
eval(boolean stripTrailingZeros)
Evaluates the expression.
|
java.util.Set<java.lang.String> |
getDeclaredFunctions()
Exposing declared functions.
|
java.util.Set<java.lang.String> |
getDeclaredOperators()
Exposing declared operators in the expression.
|
java.util.Set<java.lang.String> |
getDeclaredVariables()
Exposing declared variables in the expression.
|
java.lang.String |
getExpression() |
java.util.Iterator<net.sourceforge.plantuml.evalex.Expression.Token> |
getExpressionTokenizer()
Get an iterator for this expression, allows iterating over an expression token by token.
|
java.lang.String |
getOriginalExpression()
The original expression used to construct this expression, without variables substituted.
|
java.util.List<java.lang.String> |
getUsedVariables()
Returns a list of the variables in the expression.
|
int |
hashCode() |
boolean |
isBoolean()
Checks whether the expression is a boolean expression.
|
Expression |
setFirstVariableCharacters(java.lang.String chars)
Sets the characters other than letters and digits that are valid as the first character of a variable.
|
Expression |
setPrecision(int precision)
Sets the precision for expression evaluation.
|
Expression |
setRoundingMode(java.math.RoundingMode roundingMode)
Sets the rounding mode for expression evaluation.
|
Expression |
setVariable(java.lang.String variable,
java.math.BigDecimal value)
Sets a variable value.
|
Expression |
setVariable(java.lang.String variable,
Expression.LazyNumber value)
Sets a variable value.
|
Expression |
setVariable(java.lang.String variable,
java.lang.String value)
Sets a variable value.
|
Expression |
setVariableCharacters(java.lang.String chars)
Sets the characters other than letters and digits that are valid as the second and subsequent characters of a
variable.
|
java.lang.String |
toRPN()
Get a string representation of the RPN (Reverse Polish Notation) for this expression.
|
java.lang.String |
toString() |
Expression |
with(java.lang.String variable,
java.math.BigDecimal value)
Sets a variable value.
|
Expression |
with(java.lang.String variable,
Expression.LazyNumber value)
Sets a variable value.
|
Expression |
with(java.lang.String variable,
java.lang.String value)
Sets a variable value.
|
public static final int OPERATOR_PRECEDENCE_UNARY
public static final int OPERATOR_PRECEDENCE_EQUALITY
public static final int OPERATOR_PRECEDENCE_COMPARISON
public static final int OPERATOR_PRECEDENCE_OR
public static final int OPERATOR_PRECEDENCE_AND
public static final int OPERATOR_PRECEDENCE_POWER
public static final int OPERATOR_PRECEDENCE_MULTIPLICATIVE
public static final int OPERATOR_PRECEDENCE_ADDITIVE
public static final java.math.BigDecimal PI
public static final java.math.BigDecimal e
public Expression(java.lang.String expression)
MathContext.DECIMAL32.expression - The expression. E.g. "2.4*sin(3)/(2-4)" or "sin(y)>0 & max(z, 3)>3"public Expression(java.lang.String expression,
java.math.MathContext defaultMathContext)
expression - The expression. E.g. "2.4*sin(3)/(2-4)" or "sin(y)>0 & max(z, 3)>3"defaultMathContext - The MathContext to use by default.public java.lang.Number eval()
public java.lang.Number eval(boolean stripTrailingZeros)
stripTrailingZeros - If set to true trailing zeros in the result are stripped.public Expression setPrecision(int precision)
precision - The new precision.public Expression setRoundingMode(java.math.RoundingMode roundingMode)
roundingMode - The new rounding mode.public Expression setFirstVariableCharacters(java.lang.String chars)
chars - The new set of variable characters.public Expression setVariableCharacters(java.lang.String chars)
chars - The new set of variable characters.public <OPERATOR extends LazyOperator> OPERATOR addOperator(OPERATOR operator)
operator - The operator to add.null if there was none.public Function addFunction(Function function)
function - The function to add.null if there was none.public LazyFunction addLazyFunction(LazyFunction function)
function - The function to add.null if there was none.public Expression setVariable(java.lang.String variable, java.math.BigDecimal value)
variable - The variable name.value - The variable value.public Expression setVariable(java.lang.String variable, Expression.LazyNumber value)
variable - The variable name.value - The variable value.public Expression setVariable(java.lang.String variable, java.lang.String value)
variable - The variable to set.value - The variable value.public Expression with(java.lang.String variable, java.math.BigDecimal value)
variable - The variable to set.value - The variable value.public Expression with(java.lang.String variable, Expression.LazyNumber value)
variable - The variable to set.value - The variable value.public Expression and(java.lang.String variable, java.lang.String value)
variable - The variable to set.value - The variable value.public Expression and(java.lang.String variable, java.math.BigDecimal value)
variable - The variable to set.value - The variable value.public Expression and(java.lang.String variable, Expression.LazyNumber value)
variable - The variable to set.value - The variable value.public Expression with(java.lang.String variable, java.lang.String value)
variable - The variable to set.value - The variable value.public java.util.Iterator<net.sourceforge.plantuml.evalex.Expression.Token> getExpressionTokenizer()
public java.lang.String toRPN()
public java.util.Set<java.lang.String> getDeclaredVariables()
public java.util.Set<java.lang.String> getDeclaredOperators()
public java.util.Set<java.lang.String> getDeclaredFunctions()
public java.lang.String getExpression()
public java.util.List<java.lang.String> getUsedVariables()
public java.lang.String getOriginalExpression()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean isBoolean()
true if the last operator/function was a boolean.