The org.geolatte.core.expressions package contains a set of expression classes that allow to build complex expressions at runtime that can be evaluated against any Java object. Basic expressions include:
- Comparison
> < <= >= = <> - String wildcard comparison
like, not-like - Boolean combination
and, or, not - Date comparison
before, after, between - Property existence
exists, does-not-exist - Arithmetic
Add - Property Value (java getter/field), Constant Value
We concisely explain how expressions can be constructed and evaluated agains java objects below.
Building Expressions
There are two ways to build an Expression: via API or indirectly via CQL.
Building an expression via API
To build an expression, you usually use the Expressions factory class and expression concatenation methods.
The following code builds this expression: MyProperty < 42 AND YourProperty > 72
Building an expression via CQL
A CQL string can be parsed to a Filter object. Such an object encapsulates a boolean expression and exposes an evaluate(Object) method. For more details, see CQL.
Using Expressions
Once we have constructed an expression, we can use its evaluate(Object) method to evaluate the expression against an object. Suppose we have constructed this expression TopSpeed > 180. We can evaluate this expression against an object of the class below.
The following snippet shows how the expression is constructed and evaluated against objects of Car.