|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectFilters
public class Filters
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.
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:
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.
Field Summary | |
---|---|
static int |
NOTFOUND
NOTFOUND indicates int value was unavailable |
Constructor Summary | |
---|---|
Filters()
|
|
Filters(FilterFactory factory)
|
Method Summary | ||
---|---|---|
static void |
accept(Filter filter,
FilterVisitor visitor)
Deprecated. Please update your code to a org.opengis.filter.FilterVisitor |
|
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 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
|
asType(Expression expr,
Class<T> TYPE)
Deprecated. This is not a good idea; use expr.evaulate( null, TYPE ) |
|
Filter |
duplicate(Filter filter)
Deep copy the filter. |
|
static short |
getFilterType(Filter filter)
Deprecated. please use instanceof checks |
|
static Object |
gets(String text,
Class TYPE)
Used to upcovnert a "Text Value" into the provided TYPE. |
|
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 String |
puts(Color color)
|
|
static String |
puts(double number)
|
|
static String |
puts(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 Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NOTFOUND
NOTFOUND
indicates int value was unavailable
Constructor Detail |
---|
public Filters()
public Filters(FilterFactory factory)
Method Detail |
---|
public void setFilterFactory(FilterFactory factory)
public static Filter and(FilterFactory ff, Filter filter1, Filter filter2)
ff
- filter1
- filter2
-
public static Filter or(FilterFactory ff, Filter filter1, Filter filter2)
ff
- filter1
- filter2
-
public static void accept(Filter filter, FilterVisitor visitor)
This method handles the case of:
filter
- visitor
- 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 getFilterType(Filter 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
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:
Object value = expr.getValue( feature );
return value instanceof Color ? (Color) value : null;
expr
- This only really works for down casting literals to a valueTarget
- type
public 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 Object gets(String text, Class 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)
public static String puts(Object obj)
public static String puts(Color color)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |