public class TLcdOGCFilterEvaluator extends Object implements ILcdOGCFilterEvaluator
TLcdOGCFilter
into an ILcdDynamicFilter
which can be used to determine whether
objects pass the filter or not. It supports all filter expressions, logic operators, comparison operators.
It supports all spatial operators when the "Advanced GIS Engine component" is available
on the class path. When this component is not available, only the BBOX
operator can be evaluated.
List<Object> elementsToEvaluate = ...;
TLcdOGCFilter ogcFilter = ...;
TLcdOGCFilterEvaluator evaluator = new TLcdOGCFilterEvaluator();
TLcdOGCFilterContext filterContext = new TLcdOGCFilterContext();
ILcdDynamicFilter filter = evaluator.buildFilter(ogcFilter, filterContext);
for(Object element : elementsToEvaluate){
if(filter.accept(element)){
//Do something
}
}
Number
instances.
When not using numbers, the following conversions are done:
Long
instances: e.g. "123"Double
instances: e.g. "123.45" or "123e3"Long
value when both operands are integer numbers (longs or ints) (except for divisions, see below).Double
value for all divisions.Double
value when at least one operand is not an integer number.null
when at least one operand is null
, or at least one operand cannot be converted to a number.Number
instancesComparable
instances, including booleans and strings.equality
and not equality
operators.
For those operators, the evaluation will happen in the following order:
null
, they are considered equal. When only one of the arguments is null
, the
arguments are considered not-equal.Double.compareTo(Double)
is used.Boolean.compareTo(java.lang.Boolean)
logic is used. Comparable
interface, the Comparable.compareTo(Object)
logic is used.greater
, greater or equal
,
less
, less or equal
).
For those operators, the evaluation will happen in the following order:
null
, null
is returned as no comparison can be done.Double.compareTo(Double)
is used.Comparable
interface, the Comparable.compareTo(Object)
logic is used.is between
operator which checks whether a value lies between a
lower and upper boundary.
This check is an inclusive check at the boundaries: lowerBoundary <= value <= upperBoundary
.
The evaluation will:
null
, the operator will evaluate to null
.true
as soon as one element of the collection lies between the lower and upper boundary.is like
operator which checks whether a string value matches a
regular expression.
The evaluation will:
null
, the operator will evaluate to null
.true
as soon as one of the entries in the collection is a match.AND
, OR
and NOT
operations uses the traditional definitions:
AND
only evaluates to true
when all conditions are true,
OR
evaluates to true
as soon as one condition is true and
NOT
evaluates to true
when the condition is false
.
It is possible that one of the conditions evaluates to null
.
In that case, it is possible that the binary logic operation also evaluates to null
.
The following list shows the different combinations and their result after evaluation:
false AND null
evaluates to false
true AND null
evaluates to null
false OR null
evaluates to null
true OR null
evaluates to true
NOT null
evaluates to null
Modifier and Type | Field and Description |
---|---|
static Integer |
CONTEXT
Deprecated.
This constant is no longer used.
|
static Integer |
CURRENT_OBJECT
Deprecated.
This constant is no longer used.
|
Constructor and Description |
---|
TLcdOGCFilterEvaluator()
Creates a new
TLcdOGCFilterEvaluator instance. |
Modifier and Type | Method and Description |
---|---|
ILcdDynamicFilter |
buildFilter(TLcdOGCFilter aFilter,
TLcdOGCFilterContext aContext)
Builds an
ILcdDynamicFilter instance for a given OGC filter. |
ILcdPropertyRetriever |
buildPropertyRetriever(ILcdOGCExpression aExpression,
TLcdOGCFilterContext aContext)
Builds an
ILcdPropertyRetriever instance for a given OGC expression. |
protected ILcdEvaluatorFactory |
createEvaluatorFactory(TLcdOGCFilterContext aContext)
Deprecated.
In order to add support for custom OGC functions to a
TLcdOGCFilterEvaluator , you should
create an ILcdEvaluatorFunction and register it either globally (using registerDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction) )
or on a specific TLcdOGCFilterEvaluator instance (using registerFunction(TLcdXMLName, ILcdEvaluatorFunction) ).
Consult the class javadoc of ILcdEvaluatorFunction for more information and example code. |
TLcdOGCFilterCapabilities |
getFilterCapabilities()
Returns the filter capabilities for this evaluator.
|
static void |
registerDefaultFunction(TLcdXMLName aXMLName,
ILcdEvaluatorFunction aFunction)
Registers a custom function which will be available on all
TLcdOGCFilterEvaluator instances which are created
in the future. |
void |
registerFunction(TLcdXMLName aXMLName,
ILcdEvaluatorFunction aFunction)
Registers a custom function on this evaluator.
|
@Deprecated public static final Integer CONTEXT
@Deprecated public static final Integer CURRENT_OBJECT
public TLcdOGCFilterEvaluator()
TLcdOGCFilterEvaluator
instance.
The instance will already support all custom functions which were registered earlier
by calling the registerDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
method.public static void registerDefaultFunction(TLcdXMLName aXMLName, ILcdEvaluatorFunction aFunction)
TLcdOGCFilterEvaluator
instances which are created
in the future.
If you want to register a custom function on a single evaluator, use registerFunction(TLcdXMLName, ILcdEvaluatorFunction)
instead.
An OGC filter allows to define your own functions (modeled by an TLcdOGCFunction
).
When such a filter must be evaluated, the evaluator must be able to match the name of that custom function to
an ILcdEvaluatorFunction
.
Calling this method for a custom function will ensure that all future evaluators will support it.aXMLName
- The name of the function. The namespace should be the empty string.aFunction
- The implementation of the function behavior.public ILcdDynamicFilter buildFilter(TLcdOGCFilter aFilter, TLcdOGCFilterContext aContext)
Builds an ILcdDynamicFilter
instance for a given OGC filter. This ILcdDynamicFilter
instance can be invoked for a given object to check whether the given OGC
filter accepts it or not.
The returned ILcdFilter
instance must be thread-safe.
This implementation calls createEvaluatorFactory
to create an evaluator factory that can handle all elements in the TLcdOGCFilter
passed.
buildFilter
in interface ILcdOGCFilterEvaluator
aFilter
- the OGC filter to create an ILcdDynamicFilter
for.aContext
- the context in which to create the filter. The context defines amongst others
how a property is retrieved from an (OGC) feature and how feature IDs are
retrieved.ILcdDynamicFilter
that will only accept those objects that comply to
the description as given by the OGC filter passed.
The returned filter can throw IllegalArgumentException
s when called with unsupported objects,
or when aFilter
does not return a boolean value when evaluated.IllegalArgumentException
- When it's impossible to create a filter for aFilter
and aContext
@Deprecated protected ILcdEvaluatorFactory createEvaluatorFactory(TLcdOGCFilterContext aContext)
TLcdOGCFilterEvaluator
, you should
create an ILcdEvaluatorFunction
and register it either globally (using registerDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
)
or on a specific TLcdOGCFilterEvaluator
instance (using registerFunction(TLcdXMLName, ILcdEvaluatorFunction)
).
Consult the class javadoc of ILcdEvaluatorFunction
for more information and example code.buildFilter
.
To support extensions of OGC filters override this method. The recommended way to do this is by creating a factory
that filters out and handles the extensions and delegates to the factory created by this implementation for all
other elements of an OGC filter.
Note that the buildFilter method will throw an exception
when ILcdEvaluatorFactory.canBuildEvaluator(ILcdGenericExpression)
returns false
for the filter.aContext
- the context in which the filter will be evaluated.TLcdOGCFilter
.public ILcdPropertyRetriever buildPropertyRetriever(ILcdOGCExpression aExpression, TLcdOGCFilterContext aContext)
ILcdOGCFilterEvaluator
ILcdPropertyRetriever
instance for a given OGC expression. This ILcdPropertyRetriever
instance can be invoked for a given object to obtain the value of the
given OGC filter expression.buildPropertyRetriever
in interface ILcdOGCFilterEvaluator
aExpression
- the given OGC expression.aContext
- a filter context.public void registerFunction(TLcdXMLName aXMLName, ILcdEvaluatorFunction aFunction)
registerDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
for functions which should be available on all evaluators.
An OGC filter allows to define your own functions (modeled by an TLcdOGCFunction
).
When such a filter must be evaluated, the evaluator must be able to match the name of that custom function to
an ILcdEvaluatorFunction
.
This is done by calling this method for each of the custom functions the evaluator must support.aXMLName
- The name of the function. The namespace should be the empty string.aFunction
- The implementation of the function behavior.registerDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
public TLcdOGCFilterCapabilities getFilterCapabilities()
ILcdOGCFilterEvaluator
getFilterCapabilities
in interface ILcdOGCFilterEvaluator