Class Filters
To get the full benefit you will need to create an instanceof this Object (supports your own custom FilterFactory!). Additional methods to help create expressions are available.
Example use:
Filters filters = new Filters( factory );
filters.duplicate( original );
The above example creates a copy of the provided Filter, the factory provided will be used when creating the
duplicated content.
Expression
Expressions form an interesting little semi scripting language, intended for queries. A interesting Feature of Filter as a language is that it is not strongly typed. This utility class many helper methods that ease the transition from Strongly typed Java to the more relaxed setting of Expression where most everything can be a string.
double sum = Filters.number( Object ) + Filters.number( Object );
The above example will support the conversion of many things into a format suitable for addition - the complete list
is something like:
- Any instance of Number
- "1234" - aka Integer
- "#FFF" - aka Integer
- "123.0" - aka Double
We do our best to be forgiving, any Java class which takes a String as a constructor can be tried, and toString() assumed to be the inverse. This lets many things (like URL and Date) function without modification.
- Since:
- GeoTools 2.2
- Author:
- Jody Garnett (LISAsoft)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
NOTFOUND
indicates int value was unavailable -
Constructor Summary
ConstructorsConstructorDescriptionFilters()
Create Filters helper object using global FilterFactory provided by CommonFactoryFinderFilters
(FilterFactory factory) Create a Filters helper using the provided FilterFactory -
Method Summary
Modifier and TypeMethodDescriptionstatic Filter
and
(FilterFactory ff, List<Filter> filters) Safe and combiner for filters, will build an and filter around them only if there is at least two filtersstatic Filter
and
(FilterFactory ff, Filter filter1, Filter filter2) Safe version of FilterFactory *and* that is willing to combine filter1 and filter2 correctly in the even either of them is already an And filter.static double
asDouble
(Expression expr) Obtain the provided Expression as a double.static int
asInt
(Expression expr) Obtain the provided Expression as an integer.static String
asString
(Expression expr) Obtain the provided Expression as a String.attributeNames
(Filter filter) Uses FilterAttributeExtractor to return the list of all mentioned attribute names.static String[]
attributeNames
(Filter filter, SimpleFeatureType featureType) Traverses the filter and returns any encountered property names.List of child filters.List of child filters.Deep copy the filter.static String
findPropertyName
(Filter filter) Given a filter which contains a term which is a PropertyName, returns the name of the property.static short
getExpressionType
(Expression experssion) Convert expression to a constant for use in switch statements.static <T> T
Used to upcovnert a "Text Value" into the provided TYPE.static boolean
hasChildren
(Filter filter) Check if the provided filter has child filters of some sort.static double
Treat provided value as a Number, used for math opperations.static Filter
or
(FilterFactory ff, List<Filter> filters) Safe or combiner for filters, will build an and filter around them only if there is at least two filtersstatic Filter
or
(FilterFactory ff, Filter filter1, Filter filter2) Safe version of FilterFactory *or* that is willing to combine filter1 and filter2 correctly in the even either of them is already an Or filter.static Set<PropertyName>
propertyNames
(Expression expression) Traverses the expression and returns any encountered property names.static Set<PropertyName>
propertyNames
(Expression expression, SimpleFeatureType featureType) Traverses the expression and returns any encountered property names.static Set<PropertyName>
propertyNames
(Filter filter) Traverses the filter and returns any encountered property names.static Set<PropertyName>
propertyNames
(Filter filter, SimpleFeatureType featureType) Traverses the filter and returns any encountered property names.static String
puts
(double number) Convert provided number to a suitable text representationstatic String
Inverse of eval, used to softly type supported types into Text for use as literals.static String
Inverse of eval, used to softly type supported types into Text for use as literals.Removes the targetFilter from the baseFilter if the baseFilter is a group filter (And or Or),recursing into any sub-logic filters to find the targetFilter if necessary.Removes the targetFilter from the baseFilter if the baseFilter is a group filter (And or Or).static Filter
removeFilter
(Filter baseFilter, Filter targetFilter) static Filter
removeFilter
(Filter baseFilter, Filter targetFilter, boolean recurse) static <T extends Filter>
TFind the first child-filter (or the base filter itself) that is of the given type and uses the specified property.void
setFilterFactory
(FilterFactory factory)
-
Field Details
-
NOTFOUND
public static final int NOTFOUNDNOTFOUND
indicates int value was unavailable- See Also:
-
-
Constructor Details
-
Filters
public Filters()Create Filters helper object using global FilterFactory provided by CommonFactoryFinder -
Filters
Create a Filters helper using the provided FilterFactory
-
-
Method Details
-
setFilterFactory
-
and
Safe and combiner for filters, will build an and filter around them only if there is at least two filters- Parameters:
ff
- The filter factory used to combine filtersfilters
- The list of filters to be combined- Returns:
- The combination in AND of the filters, or Filter.EXCLUDE if filters is null or empty, or the one filter found in the list, in case it has only one element
-
and
Safe version of FilterFactory *and* that is willing to combine filter1 and filter2 correctly in the even either of them is already an And filter.- Returns:
- And
-
or
Safe or combiner for filters, will build an and filter around them only if there is at least two filters- Parameters:
ff
- The filter factory used to combine filtersfilters
- The list of filters to be combined- Returns:
- The combination in OR of the filters, or Filter.EXCLUDE if filters is null or empty, or the one filter found in the list, in case it has only one element
-
or
Safe version of FilterFactory *or* that is willing to combine filter1 and filter2 correctly in the even either of them is already an Or filter. -
duplicate
Deep copy the filter.Filter objects are mutable, when copying a rich data structure (like SLD) you will need to duplicate the Filters referenced therein.
-
getExpressionType
Convert expression to a constant for use in switch statements. This is an alternative to performing instanceof checks. p> This utility method for those upgrading to a newer version of GeoTools, instance of checks are preferred as they will take into account new kinds of expressions as the filter specification grows over time. Example:BEFORE: expression.getType() == ExpressionType.MATH_ADD QUICK: Filters.getExpressionType( expression ) == ExpressionType.MATH_ADD AFTER: expression instanceof Add
- Returns:
- ExpressionType constant.
- See Also:
-
asInt
Obtain the provided Expression as an integer.This method is quickly used to safely check Literal expressions.
- Returns:
- int value of first Number, or NOTFOUND
-
asString
Obtain the provided Expression as a String.This method only reliably works when the Expression is a Literal.
- Returns:
- Expression as a String, or null
-
asDouble
Obtain the provided Expression as a double.- Returns:
- int value of first Number, or Double.NaN
-
number
Treat provided value as a Number, used for math opperations.This function allows for the non stongly typed Math Opperations favoured by the Expression standard.
Able to hanle:
- null - to NaN
- Number
- String - valid Integer and Double encodings
- Returns:
- double or Double.NaN;
- Throws:
IllegalArgumentException
- For non numerical among us -- like Geometry
-
gets
Used to upcovnert a "Text Value" into the provided TYPE.Used to tread softly on the Java typing system, because Filter/Expression is not strongly typed. Values in in Expression land are often not the the real Java Objects we wish they were - it is reall a small, lax, query language and Java objects need a but of help getting through.
A couple notes:
- Usual trick of reflection for a Constructors that supports a String parameter is used as a last ditch effort.
- will do its best to turn Object into the indicated Class
- will be used for ordering literals against attribute values are calculated at runtime (like Date.)
- Throws:
open
- set of Throwable reflection for TYPE( String )Throwable
-
puts
Convert provided number to a suitable text representationExamples:
- Filters.puts( 3.14 ) => "3.14"
- Filters.puts( 1.0 ) => "1"
- Returns:
- text representation
-
puts
Inverse of eval, used to softly type supported types into Text for use as literals.This method has been superseeded by Converters which offers a more general and open ended solution.
- Returns:
- String representation of provided object
-
puts
Inverse of eval, used to softly type supported types into Text for use as literals.This method has been superseeded by Converters which offers a more general and open ended solution.
- Returns:
- String representation of provided color.
-
remove
Removes the targetFilter from the baseFilter if the baseFilter is a group filter (And or Or),recursing into any sub-logic filters to find the targetFilter if necessary.- If the targetFilter equals the baseFilter, then Filter.INCLUDE is returned to indicate that no filters are left.
- If the targetFilter does not equal the base filter, no change is made and the baseFilter is returned.
- If removing the targetFilter would leave only a single term within the baseFilter, then the single remaining term is returned instead of the (now invalid) baseFilter. If the last item is removed from an Or statement then Filter.EXCLUDE is return If the last item is removed from an And statement then Filter.INCLUDE is returned
-
removeFilter
-
remove
Removes the targetFilter from the baseFilter if the baseFilter is a group filter (And or Or). SeeremoveFilter(org.geotools.api.filter.Filter, org.geotools.api.filter.Filter)
for details, except this method includes the option to not recurse into child filters.- Parameters:
recurse
- true if the method should descend into child group filters looking for the target
-
removeFilter
-
attributeNames
Uses FilterAttributeExtractor to return the list of all mentioned attribute names.You can use this method to quickly build up the set of any mentioned attribute names.
- Returns:
- Set of propertyNames
-
attributeNames
Traverses the filter and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
propertyNames
Traverses the filter and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
propertyNames
Traverses the filter and returns any encountered property names. -
propertyNames
Traverses the expression and returns any encountered property names.The feature type is supplied as contexts used to lookup expressions in cases where the attributeName does not match the actual name of the type.
-
propertyNames
Traverses the expression and returns any encountered property names. -
hasChildren
Check if the provided filter has child filters of some sort.Where a child filter is considered:
- Not: has a single child filter being negated
- And: has a list of child filters
- Or: has a list of child filters
- Returns:
- list of child filters
-
children
List of child filters.Where a child filter is considered:
- Not: has a single child filter being negated
- And: has a list of child filters
- Or: has a list of child filters
This represents the space covered by a number of the search functions.
The returned list is a mutable copy that can be used with filter factory to construct a new filter when you are ready. To make that explicit I am returning an ArrayList so it is clear that the result can be modified.
- Returns:
- are belong to us
-
children
List of child filters.Where a child filter is considered:
- Not: has a single child filter being negated
- And: has a list of child filters
- Or: has a list of child filters
This represents the space covered by a number of the search functions, if *all* is true this function will recursively search for additional child filters beyond those directly avaialble from your filter.
The returned list is a mutable copy that can be used with filter factory to construct a new filter when you are ready. To make that explicit I am returning an ArrayList so it is clear that the result can be modified.
- Parameters:
all
- true to recurse into the filter and retrieve all children; false to only return the top level children- Returns:
- are belong to us
-
search
Find the first child-filter (or the base filter itself) that is of the given type and uses the specified property.- Parameters:
filterType
- - class of the filter to look forpropertyName
- - name of the property to look for
-
findPropertyName
Given a filter which contains a term which is a PropertyName, returns the name of the property. Returns null if no PropertyName is passed
-