/*
* This sample shows the basic usage of the JEval Evaluator class.
* Calling the default contructor will set he quoteCharater to single
* quote. This constructor will also load all math variables, math
* functions and string variables.
*/
Evaluator evaluator = new Evaluator();
/**
* This sample clears the variables. This call will not clear
* preloaded variables.
*/
evaluator.clearVariables();
/**
* 自定义变量.
*/
evaluator.setVariableResolver(new MockVariableResolver());
System.out.println(evaluator
.evaluate("#{MockVariable1} + #{MockVariable2}"));
/**
* This sample shows an invalid expression. The variables were just
* cleared, therefor the variable "a" no longer exists.
*/
System.out.println("An exception is expected in the "
+ "next evaluation.");
System.out.println(evaluator.evaluate("#{a}"));
} catch (EvaluationException ee) {
System.out.println(ee);
}
}