public class Filters extends Object
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.
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:
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.
Modifier and Type | Field and Description |
---|---|
static int |
NOTFOUND
NOTFOUND indicates int value was unavailable |
Constructor and Description |
---|
Filters()
Create Filters helper object using global FilterFactory provided by CommonFactoryFinder
|
Filters(FilterFactory2 factory)
Create a Filters helper using the provided FilterFactory
|
Modifier and Type | Method and Description |
---|---|
static 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 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 filters
|
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.
|
static <T> T |
asType(Expression expr,
Class<T> TYPE)
Deprecated.
This is not a good idea; use expr.evaulate( null, TYPE )
|
Set<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.
|
static ArrayList<Filter> |
children(Filter filter)
List of child filters.
|
static ArrayList<Filter> |
children(Filter filter,
boolean all)
List of child filters.
|
Filter |
duplicate(Filter filter)
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 short |
getFilterType(Filter filter)
Deprecated.
please use instanceof checks
|
static <T> T |
gets(String text,
Class<T> TYPE)
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 |
number(Object value)
Treat provided value as a Number, used for math opperations.
|
static 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 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 filters
|
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(Color color)
Inverse of eval, used to softly type supported types into Text for use as literals.
|
static String |
puts(double number)
Convert provided number to a suitable text representation
Examples:
Filters.puts( 3.14 ) => "3.14"
Filters.puts( 1.0 ) => "1"
|
static String |
puts(Object obj)
Inverse of eval, used to softly type supported types into Text for use as literals.
|
Filter |
remove(Filter baseFilter,
Filter targetFilter)
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.
|
Filter |
remove(Filter baseFilter,
Filter targetFilter,
boolean recurse)
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> |
search(Filter filter,
Class<T> filterType,
String propertyName)
Find the first child-filter (or the base filter itself) that is of the given type and uses
the specified property.
|
void |
setFilterFactory(FilterFactory2 factory) |
public static final int NOTFOUND
NOTFOUND
indicates int value was unavailablepublic Filters()
public Filters(FilterFactory2 factory)
public void setFilterFactory(FilterFactory2 factory)
public static Filter and(FilterFactory ff, List<Filter> filters)
ff
- The filter factory used to combine filtersfilters
- The list of filters to be combinedpublic static Filter and(FilterFactory ff, Filter filter1, Filter filter2)
ff
- filter1
- filter2
- public static Filter or(FilterFactory ff, List<Filter> filters)
ff
- The filter factory used to combine filtersfilters
- The list of filters to be combinedpublic static Filter or(FilterFactory ff, Filter filter1, Filter filter2)
ff
- filter1
- filter2
- public Filter duplicate(Filter filter)
Filter objects are mutable, when copying a rich data structure (like SLD) you will need to duplicate the Filters referenced therein.
public static short getExpressionType(Expression experssion)
BEFORE: expression.getType() == ExpressionType.MATH_ADD
QUICK: Filters.getExpressionType( expression ) == ExpressionType.MATH_ADD
AFTER: expression instanceof Add
experssion
- ExpressionType
public static short getFilterType(Filter filter)
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 filters (example temporal filters added for Filter 2.0 specification). Example:
BEFORE: filter.getFilterType() == FilterType.GEOMETRY_CONTAINS
QUICK: Filters.getFilterType( filter ) == FilterType.GEOMETRY_CONTAINS
AFTER: filter instanceof Contains
filter
- public static int asInt(Expression expr)
This method is quickly used to safely check Literal expressions.
expr
- public static String asString(Expression expr)
This method only reliably works when the Expression is a Literal.
expr
- public static double asDouble(Expression expr)
expr
- public static <T> T asType(Expression expr, Class<T> TYPE)
This will work even with dynamic expression that would normally require a feature. It works especially well when the Expression is a Literal literal (which is usually the case).
If you have a specific Feature, please do this:
Color value = expr.evaualte( feature, Color.class );
return value instanceof Color ? (Color) value : null;
expr
- This only really works for down casting literals to a valueTarget
- typepublic static double number(Object value)
This function allows for the non stongly typed Math Opperations favoured by the Expression standard.
Able to hanle:
value
- IllegalArgumentException
- For non numerical among us -- like Geometrypublic static <T> T gets(String text, Class<T> TYPE) throws Throwable
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:
text
- TYPE
- open
- set of Throwable reflection for TYPE( String )Throwable
public static String puts(double number)
Examples:
number
- public static String puts(Object obj)
This method has been superseeded by Converters which offers a more general and open ended solution.
public static String puts(Color color)
This method has been superseeded by Converters which offers a more general and open ended solution.
color
- public Filter remove(Filter baseFilter, Filter targetFilter)
baseFilter
- targetFilter
- public Filter remove(Filter baseFilter, Filter targetFilter, boolean recurse)
removeFilter(org.opengis.filter.Filter, org.opengis.filter.Filter)
for details,
except this method includes the option to not recurse into child filters.baseFilter
- targetFilter
- recurse
- true if the method should descend into child group filters looking for the
targetpublic static Filter removeFilter(Filter baseFilter, Filter targetFilter, boolean recurse)
public Set<String> attributeNames(Filter filter)
You can use this method to quickly build up the set of any mentioned attribute names.
filter
- public static String[] attributeNames(Filter filter, SimpleFeatureType featureType)
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.
public static Set<PropertyName> propertyNames(Filter filter, SimpleFeatureType featureType)
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.
public static Set<PropertyName> propertyNames(Filter filter)
public static Set<PropertyName> propertyNames(Expression expression, SimpleFeatureType featureType)
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.
public static Set<PropertyName> propertyNames(Expression expression)
public static boolean hasChildren(Filter filter)
Where a child filter is considered:
filter
- public static ArrayList<Filter> children(Filter filter)
Where a child filter is considered:
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.
filter
- public static ArrayList<Filter> children(Filter filter, boolean all)
Where a child filter is considered:
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.
filter
- all
- true to recurse into the filter and retrieve all children; false to only return
the top level childrenpublic static <T extends Filter> T search(Filter filter, Class<T> filterType, String propertyName)
filter
- filterType
- - class of the filter to look forproperty
- - name of the property to look forCopyright © 1996–2019 Geotools. All rights reserved.