@Test public void testAsType() { assertEquals(1.0, Filters.asType(ff.literal("1"), double.class), DELTA); assertEquals(Color.BLUE, Filters.asType(ff.literal("#0000FF"), Color.class)); }
public static <T> T asType(Expression expr, Class<T> TYPE) { if (expr == null) { return null; } if( STRICT ){ return expr.evaluate(null, TYPE ); } else if (expr instanceof Literal) { Literal literal = (Literal) expr; return (T) literal.evaluate(null, TYPE ); } else if (expr instanceof Function) { Function function = (Function) expr; List<Expression> params = function.getParameters(); if ( params != null && params.size() != 0 ) { for (int i = 0; i < params.size(); i++) { Expression e = (Expression) params.get(i); T value = asType(e, TYPE); if (value != null) { return value; } } } } else { try { T value = expr.evaluate(null, TYPE ); if (TYPE.isInstance(value)) { return value; } } catch (NullPointerException expected) { return null; } catch (Throwable ignore) { } } return null; }
Filters { public static <T> T asType(Expression expr, Class<T> TYPE) { if (expr == null) { return null; } if( STRICT ){ return expr.evaluate(null, TYPE ); } else if (expr instanceof Literal) { Literal literal = (Literal) expr; return (T) literal.evaluate(null, TYPE ); } else if (expr instanceof Function) { Function function = (Function) expr; List<Expression> params = function.getParameters(); if ( params != null && params.size() != 0 ) { for (int i = 0; i < params.size(); i++) { Expression e = (Expression) params.get(i); T value = asType(e, TYPE); if (value != null) { return value; } } } } else { try { T value = expr.evaluate(null, TYPE ); if (TYPE.isInstance(value)) { return value; } } catch (NullPointerException expected) { return null; } catch (Throwable ignore) { } } return null; } }
Filters { public static <T> T asType(Expression expr, Class<T> TYPE) { if (expr == null) { return null; } if( STRICT ){ return expr.evaluate(null, TYPE ); } else if (expr instanceof Literal) { Literal literal = (Literal) expr; return (T) literal.evaluate(null, TYPE ); } else if (expr instanceof Function) { Function function = (Function) expr; List<Expression> params = function.getParameters(); if ( params != null && params.size() != 0 ) { for (int i = 0; i < params.size(); i++) { Expression e = (Expression) params.get(i); T value = asType(e, TYPE); if (value != null) { return value; } } } } else { try { T value = expr.evaluate(null, TYPE ); if (TYPE.isInstance(value)) { return value; } } catch (NullPointerException expected) { return null; } catch (Throwable ignore) { } } return null; } Filters();  Filters(org.opengis.filter.FilterFactory2 factory); }
Filters { public static <T> T asType(Expression expr, Class<T> TYPE) { if (expr == null) { return null; } if( STRICT ){ return expr.evaluate(null, TYPE ); } else if (expr instanceof Literal) { Literal literal = (Literal) expr; return (T) literal.evaluate(null, TYPE ); } else if (expr instanceof Function) { Function function = (Function) expr; List<Expression> params = function.getParameters(); if ( params != null && params.size() != 0 ) { for (int i = 0; i < params.size(); i++) { Expression e = (Expression) params.get(i); T value = asType(e, TYPE); if (value != null) { return value; } } } } else { try { T value = expr.evaluate(null, TYPE ); if (TYPE.isInstance(value)) { return value; } } catch (NullPointerException expected) { return null; } catch (Throwable ignore) { } } return null; } Filters();  Filters(org.opengis.filter.FilterFactory2 factory); void setFilterFactory(org.opengis.filter.FilterFactory2 factory); static Filter and( org.opengis.filter.FilterFactory ff, Filter filter1, Filter filter2 ); static Filter or( org.opengis.filter.FilterFactory ff, Filter filter1, Filter filter2 ); static void accept( org.opengis.filter.Filter filter, FilterVisitor visitor ); Filter duplicate( Filter filter ); static short getFilterType( org.opengis.filter.Filter filter ); static int asInt( Expression expr ); static String asString(Expression expr); static double asDouble(Expression expr); static T asType(Expression expr, Class<T> TYPE); static double number(Object value); static T gets(String text, Class<T> TYPE); static String puts(double number); static String puts(Object obj); static String puts(Color color); Filter remove(Filter baseFilter, Filter targetFilter); static Filter removeFilter( Filter baseFilter, Filter targetFilter ); Filter remove(Filter baseFilter, final Filter targetFilter, boolean recurse); static Filter removeFilter(Filter baseFilter, Filter targetFilter, boolean recurse); Set<String> attributeNames( Filter filter ); static String[] attributeNames(Filter filter, final SimpleFeatureType featureType); static Set<PropertyName> propertyNames(Filter filter, final SimpleFeatureType featureType); static Set<PropertyName> propertyNames(Filter filter); static Set<PropertyName> propertyNames(Expression expression,
            final SimpleFeatureType featureType); static Set<PropertyName> propertyNames(Expression expression); static boolean hasChildren( Filter filter ); static ArrayList<Filter> children( Filter filter ); static ArrayList<Filter> children( Filter filter, boolean all ); static T search(Filter filter, Class<T> filterType, String propertyName ); static String findPropertyName(Filter filter); }
Filters { public static <T> T asType(Expression expr, Class<T> TYPE) { if (expr == null) { return null; } if( STRICT ){ return expr.evaluate(null, TYPE ); } else if (expr instanceof Literal) { Literal literal = (Literal) expr; return (T) literal.evaluate(null, TYPE ); } else if (expr instanceof Function) { Function function = (Function) expr; List<Expression> params = function.getParameters(); if ( params != null && params.size() != 0 ) { for (int i = 0; i < params.size(); i++) { Expression e = (Expression) params.get(i); T value = asType(e, TYPE); if (value != null) { return value; } } } } else { try { T value = expr.evaluate(null, TYPE ); if (TYPE.isInstance(value)) { return value; } } catch (NullPointerException expected) { return null; } catch (Throwable ignore) { } } return null; } Filters();  Filters(org.opengis.filter.FilterFactory2 factory); void setFilterFactory(org.opengis.filter.FilterFactory2 factory); static Filter and( org.opengis.filter.FilterFactory ff, Filter filter1, Filter filter2 ); static Filter or( org.opengis.filter.FilterFactory ff, Filter filter1, Filter filter2 ); static void accept( org.opengis.filter.Filter filter, FilterVisitor visitor ); Filter duplicate( Filter filter ); static short getFilterType( org.opengis.filter.Filter filter ); static int asInt( Expression expr ); static String asString(Expression expr); static double asDouble(Expression expr); static T asType(Expression expr, Class<T> TYPE); static double number(Object value); static T gets(String text, Class<T> TYPE); static String puts(double number); static String puts(Object obj); static String puts(Color color); Filter remove(Filter baseFilter, Filter targetFilter); static Filter removeFilter( Filter baseFilter, Filter targetFilter ); Filter remove(Filter baseFilter, final Filter targetFilter, boolean recurse); static Filter removeFilter(Filter baseFilter, Filter targetFilter, boolean recurse); Set<String> attributeNames( Filter filter ); static String[] attributeNames(Filter filter, final SimpleFeatureType featureType); static Set<PropertyName> propertyNames(Filter filter, final SimpleFeatureType featureType); static Set<PropertyName> propertyNames(Filter filter); static Set<PropertyName> propertyNames(Expression expression,
            final SimpleFeatureType featureType); static Set<PropertyName> propertyNames(Expression expression); static boolean hasChildren( Filter filter ); static ArrayList<Filter> children( Filter filter ); static ArrayList<Filter> children( Filter filter, boolean all ); static T search(Filter filter, Class<T> filterType, String propertyName ); static String findPropertyName(Filter filter); static final int NOTFOUND; }