org.geotools.filter
Class Filters

java.lang.Object
  extended by org.geotools.filter.Filters

public class Filters
extends java.lang.Object

Utility class for working with Filters & Expression.

To get the full benifit 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( origional );
 
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 languge, 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: A few things (like Geometry and "ABC") will not be considered addative.

In general the scope of these functions should be similar to that allowed by the XML Atomic Types, aka those that can be seperated by whitespace to form a list.

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.M3
Author:
Jody Garnett, Refractions Research

Field Summary
static int NOTFOUND
          NOTFOUND indicates int value was unavailable
 
Constructor Summary
Filters()
           
Filters(org.opengis.filter.FilterFactory2 factory)
           
 
Method Summary
static void accept(org.opengis.filter.Filter filter, FilterVisitor visitor)
          Deprecated. Please update your code to a org.opengis.filter.FilterVisitor
static org.opengis.filter.Filter and(org.opengis.filter.FilterFactory ff, org.opengis.filter.Filter filter1, org.opengis.filter.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(org.opengis.filter.expression.Expression expr)
          Obtain the provided Expression as a double.
static int asInt(org.opengis.filter.expression.Expression expr)
          Obtain the provided Expression as an integer.
static java.lang.String asString(org.opengis.filter.expression.Expression expr)
          Obtain the provided Expression as a String.
static
<T> T
asType(org.opengis.filter.expression.Expression expr, java.lang.Class<T> TYPE)
          Deprecated. This is not a good idea; use expr.evaulate( null, TYPE )
 org.opengis.filter.Filter duplicate(org.opengis.filter.Filter filter)
          Deep copy the filter.
static short getFilterType(org.opengis.filter.Filter filter)
          Deprecated. please use instanceof checks
static java.lang.Object gets(java.lang.String text, java.lang.Class TYPE)
          Used to upcovnert a "Text Value" into the provided TYPE.
static double number(java.lang.Object value)
          Treat provided value as a Number, used for math opperations.
static org.opengis.filter.Filter or(org.opengis.filter.FilterFactory ff, org.opengis.filter.Filter filter1, org.opengis.filter.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 java.lang.String puts(java.awt.Color color)
           
static java.lang.String puts(double number)
           
static java.lang.String puts(java.lang.Object obj)
          Inverse of eval, used to softly type supported types into Text for use as literals.
 void setFilterFactory(org.opengis.filter.FilterFactory2 factory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOTFOUND

public static final int NOTFOUND
NOTFOUND indicates int value was unavailable

See Also:
Constant Field Values
Constructor Detail

Filters

public Filters()

Filters

public Filters(org.opengis.filter.FilterFactory2 factory)
Method Detail

setFilterFactory

public void setFilterFactory(org.opengis.filter.FilterFactory2 factory)

and

public static org.opengis.filter.Filter and(org.opengis.filter.FilterFactory ff,
                                            org.opengis.filter.Filter filter1,
                                            org.opengis.filter.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.

Parameters:
ff -
filter1 -
filter2 -
Returns:
And

or

public static org.opengis.filter.Filter or(org.opengis.filter.FilterFactory ff,
                                           org.opengis.filter.Filter filter1,
                                           org.opengis.filter.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.

Parameters:
ff -
filter1 -
filter2 -
Returns:

accept

public static void accept(org.opengis.filter.Filter filter,
                          FilterVisitor visitor)
Deprecated. Please update your code to a org.opengis.filter.FilterVisitor

Safely visit the provided filter.

This method handles the case of:

Please note that when called with a strict *org.opengis.filter.Filter* this method will fail with a ClassCastException

Parameters:
filter -
visitor -

duplicate

public org.opengis.filter.Filter duplicate(org.opengis.filter.Filter filter)
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.


getFilterType

public static short getFilterType(org.opengis.filter.Filter filter)
Deprecated. please use instanceof checks

Utility method used to transition to geoapi filter.

This utility method is designed to help people port their code quickly, an instanceof check is much preferred.

Example:

 BEFORE: filter.getFilterType() == FilterType.GEOMETRY_CONTAINS
 QUICK:  Filters.getFilterType( filter ) == FilterType.GEOMETRY_CONTAINS
 AFTER: filter instanceof Contains
 

Parameters:
filter -

asInt

public static int asInt(org.opengis.filter.expression.Expression expr)
Obtain the provided Expression as an integer.

This method is quickly used to safely check Literal expressions.

Parameters:
expr -
Returns:
int value of first Number, or NOTFOUND

asString

public static java.lang.String asString(org.opengis.filter.expression.Expression expr)
Obtain the provided Expression as a String.

This method only reliably works when the Expression is a Literal.

Parameters:
expr -
Returns:
Expression as a String, or null

asDouble

public static double asDouble(org.opengis.filter.expression.Expression expr)
Obtain the provided Expression as a double.

Parameters:
expr -
Returns:
int value of first Number, or Double.NaN

asType

public static <T> T asType(org.opengis.filter.expression.Expression expr,
                           java.lang.Class<T> TYPE)
Deprecated. This is not a good idea; use expr.evaulate( null, TYPE )

Navigate through the expression searching for something that can be a 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:


 Object value = expr.getValue( feature );
 return value instanceof Color ? (Color) value : null;
 

Parameters:
expr - This only really works for down casting literals to a value
Target - type
Returns:
expr smunched into indicated type

number

public static double number(java.lang.Object value)
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:

Parameters:
value -
Returns:
double or Double.NaN;
Throws:
java.lang.IllegalArgumentException - For non numerical among us -- like Geometry

gets

public static java.lang.Object gets(java.lang.String text,
                                    java.lang.Class TYPE)
                             throws java.lang.Throwable
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: Remember Strong typing is for whimps who know what they are doing ahead of time. Real programmers let their program learn at runtime... :-)

Parameters:
text -
TYPE -
Throws:
open - set of Throwable reflection for TYPE( String )
java.lang.Throwable

puts

public static java.lang.String puts(double number)

puts

public static java.lang.String puts(java.lang.Object obj)
Inverse of eval, used to softly type supported types into Text for use as literals.


puts

public static java.lang.String puts(java.awt.Color color)


Copyright © 1996-2010 Geotools. All Rights Reserved.