Java Reference
In-Depth Information
// Get operation
temp = m.group(4);
if (temp != null && !temp.equals("")) {
this.operation = temp.charAt(0);
}
// Get operand-2
temp = m.group(6);
if (temp != null && !temp.equals("")) {
this.op2Sign = temp.charAt(0);
}
this.op2 = m.group(7);
}
private String getErrorString() {
return "Invalid expression[" + exp + "]" +
"\nSupported expression syntax is: op1 operation op2" +
"\n where op1 and op2 can be a number or a bind variable" +
" , and operation can be +, -, *, and /.";
}
@Override
public String toString() {
return "Expression: " + this.exp + ", op1 Sign = " +
op1Sign + ", op1 = " + op1 + ", op2 Sign = " +
op2Sign + ", op2 = " + op2 + ", operation = " +
operation;
}
}
The Expression class is designed to parse and evaluate an arithmetic expression of
the form:
op1 operation op2
Here, op1 and op2 are two operands that can be numbers in decimal format or
variables, and operation can be + , - , * , or / .
The suggested use of the Expression class is:
Expression exp = new Expression(expression, scriptContext);
Double value = exp.eval();
Let's discuss important components of the Expression class in detail.
Search WWH ::




Custom Search