Fzzy Config contains a math expression evaluation engine. It can be used to evaluate a wide array of basic math expressions with variable support. See the documentation for an overview of every supported math expression. Expressions can be chained and nested, and variables are supported via the use of Character placeholders ('x', 'y', etc.)
Creating an Expression
The basis of an Expression
is a string representation of the math equation you want evaluated. This string is parsed into an Expression
with parse()
. Variable values are provided at evaluation time, see below.
String math = "(x + 5) ^ 2 + x";Expression mathExpression = Expression.parse(math);
Evaluating an Expression
Once you have your expression, outputs are evaluated by passing replacement values for each placeholder character, as applicable, into the eval
or evalSafe
(recommended) methods.
Map mathMap = Map.of('x', 2.5);double mathResult = mathExpression.evalSafe(mathMap, 20.0); // evalSafe fails soft with a fallback value. eval throws exceptions if there is a problem.