|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
Defines an interface to provide the data types and the values of the symbols.
The objects of the classes that implement this interface can be introduced to
Expression class to say that call My Symbol MScriptResolver for the
symbols existing in the expression.
Example:
import org.moremotion.evaluator.SymbolResolver;
public class MySymbolResolver implements org.moremotion.evaluator.SymbolResolver {
int age = 0;
boolean retired = false;
String name = "John Coombes";
public MySymbolResolver() {
}
public double getNumberValue(String symbol) throws Exception {
if (symbol.equals("AGE")) return age;
return 0;
}
public boolean getBoolValue(String symbol) throws Exception {
if (symbol.equals("RETIRED")) return retired;
return false;
}
public String getStringValue(String symbol) throws Exception {
if (symbol.equals("NAME")) return name;
return "";
}
public int getType(String symbol) throws Exception {
if (symbol.equals("AGE")) return DT_NUMBER;
if (symbol.equals("RETIRED")) return DT_BOOL;
return DT_STRING;
}
public String getValue(String symbol) throws Exception {
if (symbol.equals("AGE")) return "" + age;
if (symbol.equals("RETIRED")) return "" + retired;
if (symbol.equals("NAME")) return name;
return "";
}
public void setValue(String symbol, String value) throws Exception {
}
}
Usage Example
MySymbolResolver msr = new MySymbolResolver();
Expression expr = new Expression("A + (B / 3) - 2", msr);
String result = expr.eval();
| Field Summary | |
static byte |
DT_BOOL
|
static byte |
DT_NUMBER
|
static byte |
DT_STRING
|
| Method Summary | |
boolean |
getBoolValue(java.lang.String symbol)
Returns the value of the given symbol as boolean. |
double |
getNumberValue(java.lang.String symbol)
Returns the value of the given symbol as double. |
java.lang.String |
getStringValue(java.lang.String symbol)
Returns the value of the given symbol as String. |
int |
getType(java.lang.String symbol)
Returns the type of the given symbol. |
java.lang.String |
getValue(java.lang.String symbol)
Returns the value of the given symbol as String. |
void |
setValue(java.lang.String symbol,
java.lang.String value)
Although this method takes place in this interface it will not be called by Expression class. |
| Field Detail |
public static final byte DT_STRING
public static final byte DT_NUMBER
public static final byte DT_BOOL
| Method Detail |
public int getType(java.lang.String symbol)
throws EvaluationException
EvaluationException
public java.lang.String getValue(java.lang.String symbol)
throws EvaluationException
String.
This method will be called when type of the symbol is undefined.
EvaluationException
public java.lang.String getStringValue(java.lang.String symbol)
throws EvaluationException
String.
This method will be called when type of the symbol is String.
EvaluationException
public double getNumberValue(java.lang.String symbol)
throws EvaluationException
double.
This method will be called when type of the symbol is either int or double.
EvaluationException
public boolean getBoolValue(java.lang.String symbol)
throws EvaluationException
boolean.
This method will be called when type of the symbol is boolean.
EvaluationException
public void setValue(java.lang.String symbol,
java.lang.String value)
throws EvaluationException
EvaluationException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||