public class ExpressionEvaluator extends Object
In this way you can easily evaluate JoSQL expressions against objects.
Usage:
Use the static methods to evaluate the expression in one call, for instance to find out details about a file:
String exp = "path + ', size: ' + formatNumber(length) + ', last modified: ' + formatDate(lastModified)
String details = ExpressionEvaluator.getValue (exp, new File ('/home/me/myfile.txt'));
Constructor and Description |
---|
ExpressionEvaluator(String exp,
Class cl)
Create a new expression evaluator.
|
ExpressionEvaluator(String exp,
Class cl,
List fhs)
Create a new expression evaluator.
|
Modifier and Type | Method and Description |
---|---|
Query |
getQuery()
Get the query associated with the expression, use this to setup
bind variables, function handlers and so on, which of course must
be setup prior to evaluating the expression.
|
Object |
getValue(Object o)
Evaluate the expression against the object passed in and return the
value.
|
static Object |
getValue(String exp,
Object o)
Evaluate the expression against the object passed in and return the
value.
|
List |
getValues(List l)
Evaluate the expression against the list of objects passed in and
return the value.
|
static List |
getValues(String exp,
List l)
Evaluate the expression against the list of objects passed in and
return the value.
|
boolean |
isTrue(Object o)
Evaluate the expression against the object passed in.
|
static boolean |
isTrue(String exp,
Object o)
Evaluate the expression against the object passed in.
|
public ExpressionEvaluator(String exp, Class cl) throws QueryParseException
exp
- The expression to be evaluated.cl
- The class of the object(s) that the expression will be
evaluated against.QueryParseException
- If the expression cannot be parsed.public ExpressionEvaluator(String exp, Class cl, List fhs) throws QueryParseException
exp
- The expression to be evaluated.cl
- The class of the object(s) that the expression will be
evaluated against.fhs
- A list of function handlers that contain functions that will
be used by the expression, can be null.QueryParseException
- If the expression cannot be parsed.public Query getQuery()
public boolean isTrue(Object o) throws QueryExecutionException
o
- The object to evaluate the expression against.QueryExecutionException
- If the expression cannot be executed.public List getValues(List l) throws QueryExecutionException
l
- The list of objects to evaluate the expression against.QueryExecutionException
- If the expression cannot be executed.public Object getValue(Object o) throws QueryExecutionException
o
- The object to evaluate the expression against.QueryExecutionException
- If the expression cannot be executed.public static boolean isTrue(String exp, Object o) throws QueryParseException, QueryExecutionException
exp
- A string representation of the expression to evaluate.o
- The object to evaluate the expression against.QueryParseException
- If the expression cannot be parsed.QueryExecutionException
- If the expression cannot be executed.public static List getValues(String exp, List l) throws QueryParseException, QueryExecutionException
exp
- A string representation of the expression to evaluate.l
- The list of objects to evaluate the expression against.QueryParseException
- If the expression cannot be parsed.QueryExecutionException
- If the expression cannot be executed.public static Object getValue(String exp, Object o) throws QueryParseException, QueryExecutionException
exp
- A string representation of the expression to evaluate.o
- The object to evaluate the expression against.QueryParseException
- If the expression cannot be parsed.QueryExecutionException
- If the expression cannot be executed.