public class ExpressionEvaluator extends Object
ExpressionEvaluator
class is the logical entry point to the library.
// using default implementation
String expr = ...;
ExpressionEvaluator exprEval = new ExpressionEvaluator();
double result = exprEval.evaluate(expr);
// using dual stack evaluator
String expr = ...;
ExpressionEvaluator exprEval = new ExpressionEvaluator(Evaluator.DUAL_STACK);
double result = exprEval.evaluate(expr);
// using expression tree evaluator
String expr = ...;
ExpressionEvaluator exprEval = new ExpressionEvaluator(Evaluator.EXPRESSION_TREE);
double result = exprEval.evaluate(expr);
Modifier and Type | Class and Description |
---|---|
static class |
ExpressionEvaluator.Evaluator
The
Evaluator enum represents the Shunting Yard implementation to be used for evaluating expressions.It can be of two types: DUAL_STACK, and EXPRESSION_TREE. |
Modifier and Type | Field and Description |
---|---|
ShuntingYard |
SY
Shunting yard implementation instance to be used to evaluate expression.
|
Constructor and Description |
---|
ExpressionEvaluator()
No-argument constructor.
Use Dual Stack implementation of Shunting Yard as the default implementation. |
ExpressionEvaluator(ExpressionEvaluator.Evaluator evaluator)
Parameterized constructor.
Use the specified Shunting Yard implementation. |
Modifier and Type | Method and Description |
---|---|
double |
evaluate(String expr)
Method to evaluate an expression.
This method acts as the single point of access for expression evaluation. |
public final ShuntingYard SY
public ExpressionEvaluator()
public ExpressionEvaluator(ExpressionEvaluator.Evaluator evaluator)
evaluator
- Shunting Yard implementationpublic double evaluate(String expr)
expr
- Expression stringCopyright © 2019 Pratanu Mandal. All rights reserved.