Refine search
@Override public <T> T evaluate(Object object, Class<T> context) { // Selection of the first expression Expression clazzExpression = parameters.get(0); // Getting the defined class Class clazz = clazzExpression.evaluate(object, Class.class); // Checking the result boolean result = false; // If the input class is Object, the function always returns true if (clazz != null) { if (clazz == Object.class) { result = true; } else { // Otherwise the function checks if the class is an instance of the // input class result = clazz.isAssignableFrom(object.getClass()); } } // Finally the result is converted to the defined context class return Converters.convert(result, context); }
protected void doSDOFilter(Filter filter, Expression e1, Expression e2, Object extraData) throws IOException { out.write("SDO_FILTER("); e1.accept(this, extraData); out.write(", "); e2.accept(this, extraData); // for backwards compatibility with Oracle 9 we add the mask and querytypes params out.write(", 'mask=anyinteract querytype=WINDOW') = 'TRUE' "); }
protected Expression copyCqlExpression(Expression expression) { if (expression == null) return null; Expression simplified = null; if (expression instanceof Literal) { String value = expression.evaluate(null, String.class); if (value != null && value.startsWith("${")) { expression = ExpressionExtractor.extractCqlExpressions(value); } } simplified = (Expression) expression.accept(simplifier, ff); return simplified; }
protected Expression optimize(Expression expression, Object extraData, Class targetType) { if (expression instanceof Literal && targetType != null) { // perform the conversion and return the optimized literal Object converted = expression.evaluate(null, targetType); if (converted != null) { return ff.literal(converted); } } // in case we could not optimize, just duplicate return visit(expression, extraData); }
public void testEvaluateWithStrings() throws Exception { org.opengis.filter.expression.Expression function = ff.function("Quantile", ff.property("group"), ff.literal(2)); Classifier classifier = (Classifier) function.evaluate(featureCollection); assertNotNull(classifier); Classifier classifier2 = (Classifier) function.evaluate(featureCollection, Classifier.class); assertNotNull(classifier2); Integer number = (Integer) function.evaluate(featureCollection, Integer.class); assertNull(number); }
@Test public void testMoreClassesThanFeatures() throws SchemaException, IOException { ListFeatureCollection fc = getSimplifiedStatesCollection(); Expression areaFunction = EqualAreaFunction.getCartesianAreaFunction(); // twice as many classes org.opengis.filter.expression.Expression function = FF.function("EqualArea", PERSONS, FF.literal(fc.size() * 2)); RangedClassifier ranged = assertRangedClassifier(function.evaluate(fc)); // check the number of classes has been reduced (not 49 but 43, with high // number of classes it's likely that it's not possible to fill bins assertEquals(ranged.getSize(), 43); }
@Test public void testPreserveOriginalSRS() throws NoSuchAuthorityCodeException, FactoryException { String srs = "AUTO:42004,9001,0,33"; CoordinateReferenceSystem crs = CRS.decode(srs); BBOX bbox = ff.bbox(ff.property(""), 0, 1000, 2000, 3000, srs); Geometry geom = bbox.getExpression2().evaluate(null, Geometry.class); assertEquals(crs, geom.getUserData()); assertEquals(srs, bbox.getSRS()); } }
public Object visit(PropertyIsNull filter, Object arg1) { Expression nullCheck = filter.getExpression(); List sourceChecks = (List) nullCheck.accept(this, null); List combined = new ArrayList(sourceChecks.size()); for (Iterator it = sourceChecks.iterator(); it.hasNext(); ) { Expression sourceValue = (Expression) it.next(); Filter newFilter = ff.isNull(sourceValue); combined.add(newFilter); } Filter unrolled = combineOred(combined); return unrolled; }
@Test public void testDynamicStroke() throws Exception { Stroke original = sb.createStroke(Color.RED, 2); original.setDashArray(Arrays.asList((Expression) ff.literal("5 10"))); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals(4.0d, Double.valueOf((String) clone.getWidth().evaluate(null)), 0.001); assertNotNull(original.dashArray()); assertEquals(1, original.dashArray().size()); assertEquals("10.0 20.0", ((Expression) clone.dashArray().get(0)).evaluate(null)); }
@Test public void testEmptyCollection() throws SchemaException, IOException { ListFeatureCollection empty = new ListFeatureCollection(getSimplifiedStatesCollection().getSchema()); org.opengis.filter.expression.Expression function = FF.function("EqualArea", PERSONS, FF.literal(5)); assertNull(function.evaluate(empty)); }
@Override public void visit(Mark mark) { final Expression wellKnownName = mark.getWellKnownName(); if (wellKnownName instanceof Literal) { final String name = wellKnownName.evaluate(null, String.class); if (name.startsWith("resource:/")) { try { Resource r = resourceLoader.fromURL(name); if (r != null && r.getType() != Type.UNDEFINED) { resources.add(r); } } catch (IllegalArgumentException e) { GeoServerConfigPersister.LOGGER.log( Level.WARNING, "Error attemping to process SLD resource", e); } } } }
@Test public void testRescaleLocalUOM() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); original.setWidth(ff.literal("2m")); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals("4m", clone.getWidth().evaluate(null, String.class)); }
private Expression encodeJdbcMultipleValues(Expression expression, Writer out) { JdbcMultipleValueEncoder encoder = new JdbcMultipleValueEncoder(featureMapping, out); return (Expression) expression.accept(encoder, null); } }
private String evalToString(Expression exp, Object f, String fallback) { if (exp == null) { return fallback; } String s = exp.evaluate(f, String.class); if (s != null) { return s; } return fallback; }
@Test public void testRescalePerpendicularOffset() throws Exception { Stroke stroke = sb.createStroke(Color.RED, 2, new float[] {5, 10}); LineSymbolizer ls = sb.createLineSymbolizer(stroke); ls.setPerpendicularOffset(ff.literal(2)); ls.accept(visitor); LineSymbolizer clone = (LineSymbolizer) visitor.getCopy(); assertEquals("4", clone.getPerpendicularOffset().evaluate(null, String.class)); }
<T> Expression nullIf(Expression expr, T value, Class<T> clazz) { if (expr instanceof Literal) { T t = expr.evaluate(null, clazz); if (t != null && t.equals(value)) { return null; } } return expr; }
@Test public void testRescaleLocalPixelInPixelSymbolizer() throws Exception { Stroke stroke = sb.createStroke(Color.RED, 2, new float[] {5, 10}); stroke.setWidth(ff.literal("2px")); LineSymbolizer ls = sb.createLineSymbolizer(stroke); ls.accept(visitor); LineSymbolizer clone = (LineSymbolizer) visitor.getCopy(); assertEquals("4", clone.getStroke().getWidth().evaluate(null, String.class)); }