Fzzy Config contains a math evaluation engine. It can be used to evaluate a wide array of basic math expressions with variable support, see the documentation 🗗 for details. 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 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.