org.geotools.filter
Class Filters

java.lang.Object
  extended byorg.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(FilterFactory factory)
           
 
Method Summary
static double asDouble(Expression expr)
          Uses number( expr ), will turn result into an interger, or NaN.
static int asInt(Expression expr)
          Uses number( expr ), will turn result into an interger, or NOTFOUND
static java.lang.String asString(Expression expr)
          Uses string( expr ), will turn result into a String
static java.lang.Object asType(Expression expr, java.lang.Class TYPE)
          Navigate through the expression seaching for TYPE.
 Filter duplicate(Filter filter)
          Deep copy the filter.
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 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(FilterFactory 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(FilterFactory factory)
Method Detail

setFilterFactory

public void setFilterFactory(FilterFactory factory)

duplicate

public Filter duplicate(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.


asInt

public static int asInt(Expression expr)
Uses number( expr ), will turn result into an interger, or NOTFOUND

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

asString

public static java.lang.String asString(Expression expr)
Uses string( expr ), will turn result into a String

Parameters:
expr -
Returns:
value of first String

asDouble

public static double asDouble(Expression expr)
Uses number( expr ), will turn result into an interger, or NaN.

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

asType

public static java.lang.Object asType(Expression expr,
                                      java.lang.Class TYPE)
Navigate through the expression seaching for TYPE.

This will work even with dynamic expression that would normall 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 -
TYPE - DOCUMENT ME!
Returns:
First available color, or null.

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 -
Returns:
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 © GeoTools. All Rights Reserved.