Package com.luciad.ogc.filter.evaluator
Class TLcdOGCFilterEvaluator
java.lang.Object
com.luciad.ogc.filter.evaluator.TLcdOGCFilterEvaluator
- All Implemented Interfaces:
ILcdOGCFilterEvaluator
- Direct Known Subclasses:
TLcdOGCFilterSpatialEvaluator
This class allows to convert a
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.
Example usage
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
}
}
Arithmetic operations
All arithmetic operations (addition, subtraction, multiplication and division) can operate onNumber
instances.
When not using numbers, the following conversions are done:
- String values containing only numbers will be converted to
Long
instances: e.g. "123" - String values containing a decimal separator (".") or using exponential notation (using an "e" or "E") will
be converted to
Double
instances: e.g. "123.45" or "123e3"
- A
Long
value when both operands are integer numbers (longs or ints) (except for divisions, see below). - A
Double
value for all divisions. - A
Double
value when at least one operand is not an integer number. null
when at least one operand isnull
, or at least one operand cannot be converted to a number.
Binary comparison operations
All the binary comparison operations can operate onNumber
instancesComparable
instances, including booleans and strings.
Equality checks
This section covers theequality
and not equality
operators.
For those operators, the evaluation will happen in the following order:
- When both arguments are
null
, they are considered equal. When only one of the arguments isnull
, the arguments are considered not-equal. - When one of the arguments is a collection, the collection is considered equal to the other argument if the collection contains a value to the other argument.
- When both arguments can be interpreted as numbers, the numbers are converted to doubles and
Double.compareTo(Double)
is used. - When both arguments can be interpreted as booleans, the
Boolean.compareTo(java.lang.Boolean)
logic is used. - When both arguments implement the
Comparable
interface, theComparable.compareTo(Object)
logic is used.
Mathematical comparison checks
This section covers the mathematical operators (greater
, greater or equal
,
less
, less or equal
).
For those operators, the evaluation will happen in the following order:
- When the mathematical comparison check includes an equal check (for example "greater or equal"), an equality check will be done first following the rules described in the "Equality checks" section.
- When any of the arguments is
null
,null
is returned as no comparison can be done. - When both arguments can be interpreted as numbers, the numbers are converted to doubles and
Double.compareTo(Double)
is used. - When both arguments implement the
Comparable
interface, theComparable.compareTo(Object)
logic is used.
Is between check
This section covers theis 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:
- When either the value or any of the boundaries is
null
, the operator will evaluate tonull
. - When the value is a collection, the operator will evaluate to
true
as soon as one element of the collection lies between the lower and upper boundary. - The comparison between the value and the bounds follows the rules described in the "Equality checks" and "Mathematical comparison checks" sections above.
- The is between operator also supports dates. This allows to check whether the value is included in a certain time range.
Is like check
This section covers theis like
operator which checks whether a string value matches a
regular expression.
The evaluation will:
- When either the regular expression or the string value to evaluate are
null
, the operator will evaluate tonull
. - When the value is a collection, the operator will evaluate to
true
as soon as one of the entries in the collection is a match.
Binary logic operations
The evaluation of theAND
, 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 tofalse
true AND null
evaluates tonull
false OR null
evaluates tonull
true OR null
evaluates totrue
NOT null
evaluates tonull
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuildFilter
(TLcdOGCFilter aFilter, TLcdOGCFilterContext aContext) Builds anILcdDynamicFilter
instance for a given OGC filter.buildPropertyRetriever
(ILcdOGCExpression aExpression, TLcdOGCFilterContext aContext) Builds anILcdPropertyRetriever
instance for a given OGC expression.protected ILcdEvaluatorFactory
createEvaluatorFactory
(TLcdOGCFilterContext aContext) Deprecated.In order to add support for custom OGC functions to aTLcdOGCFilterEvaluator
, you should create anILcdEvaluatorFunction
and register it either globally (usingregisterDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
) or on a specificTLcdOGCFilterEvaluator
instance (usingregisterFunction(TLcdXMLName, ILcdEvaluatorFunction)
).Returns the filter capabilities for this evaluator.static void
registerDefaultFunction
(TLcdXMLName aXMLName, ILcdEvaluatorFunction aFunction) Registers a custom function which will be available on allTLcdOGCFilterEvaluator
instances which are created in the future.void
registerFunction
(TLcdXMLName aXMLName, ILcdEvaluatorFunction aFunction) Registers a custom function on this evaluator.
-
Field Details
-
CONTEXT
Deprecated.This constant is no longer used. -
CURRENT_OBJECT
Deprecated.This constant is no longer used.
-
-
Constructor Details
-
TLcdOGCFilterEvaluator
public TLcdOGCFilterEvaluator()Creates a newTLcdOGCFilterEvaluator
instance. The instance will already support all custom functions which were registered earlier by calling theregisterDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
method.
-
-
Method Details
-
registerDefaultFunction
Registers a custom function which will be available on allTLcdOGCFilterEvaluator
instances which are created in the future. If you want to register a custom function on a single evaluator, useregisterFunction(TLcdXMLName, ILcdEvaluatorFunction)
instead. An OGC filter allows to define your own functions (modeled by anTLcdOGCFunction
). When such a filter must be evaluated, the evaluator must be able to match the name of that custom function to anILcdEvaluatorFunction
. Calling this method for a custom function will ensure that all future evaluators will support it.- Parameters:
aXMLName
- The name of the function. The namespace should be the empty string.aFunction
- The implementation of the function behavior.- Since:
- 2017.0
-
buildFilter
Builds an
ILcdDynamicFilter
instance for a given OGC filter. ThisILcdDynamicFilter
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 theTLcdOGCFilter
passed.- Specified by:
buildFilter
in interfaceILcdOGCFilterEvaluator
- Parameters:
aFilter
- the OGC filter to create anILcdDynamicFilter
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.- Returns:
- an
ILcdDynamicFilter
that will only accept those objects that comply to the description as given by the OGC filter passed. The returned filter can throwIllegalArgumentException
s when called with unsupported objects, or whenaFilter
does not return a boolean value when evaluated. - Throws:
IllegalArgumentException
- When it's impossible to create a filter foraFilter
andaContext
-
createEvaluatorFactory
Deprecated.In order to add support for custom OGC functions to aTLcdOGCFilterEvaluator
, you should create anILcdEvaluatorFunction
and register it either globally (usingregisterDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
) or on a specificTLcdOGCFilterEvaluator
instance (usingregisterFunction(TLcdXMLName, ILcdEvaluatorFunction)
). Consult the class javadoc ofILcdEvaluatorFunction
for more information and example code.Creates the evaluator factory that will be used to create evaluators for every expression and condition that can be part of an OGC filter. This method is called frombuildFilter
. 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 whenILcdEvaluatorFactory.canBuildEvaluator(ILcdGenericExpression)
returnsfalse
for the filter.- Parameters:
aContext
- the context in which the filter will be evaluated.- Returns:
- an evaluator factory that is capable of handling all types of expressions and conditions that can appear in
a
TLcdOGCFilter
.
-
buildPropertyRetriever
public ILcdPropertyRetriever buildPropertyRetriever(ILcdOGCExpression aExpression, TLcdOGCFilterContext aContext) Description copied from interface:ILcdOGCFilterEvaluator
Builds anILcdPropertyRetriever
instance for a given OGC expression. ThisILcdPropertyRetriever
instance can be invoked for a given object to obtain the value of the given OGC filter expression.- Specified by:
buildPropertyRetriever
in interfaceILcdOGCFilterEvaluator
- Parameters:
aExpression
- the given OGC expression.aContext
- a filter context.- Returns:
- the value of the expression.
-
registerFunction
Registers a custom function on this evaluator. The custom function will only be available on this instance. UseregisterDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
for functions which should be available on all evaluators. An OGC filter allows to define your own functions (modeled by anTLcdOGCFunction
). When such a filter must be evaluated, the evaluator must be able to match the name of that custom function to anILcdEvaluatorFunction
. This is done by calling this method for each of the custom functions the evaluator must support.- Parameters:
aXMLName
- The name of the function. The namespace should be the empty string.aFunction
- The implementation of the function behavior.- See Also:
-
getFilterCapabilities
Description copied from interface:ILcdOGCFilterEvaluator
Returns the filter capabilities for this evaluator.- Specified by:
getFilterCapabilities
in interfaceILcdOGCFilterEvaluator
- Returns:
- the filter capabilities for this evaluator.
-