public Object visit(Function expression, Object data) { if (expression.getParameters() != null) { for (Expression parameter : expression.getParameters()) { data = parameter.accept(this, data); } } return data; }
public Object visit(Function expression, Object extraData) { String type = (String) "Function"; AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "name", "name", "", expression.getName()); start(type, atts); for (org.opengis.filter.expression.Expression parameter : expression.getParameters()) { parameter.accept(this, extraData); } end(type); return extraData; }
@Override public Object visit(Function f, Object extraData) { FunctionName fn = f.getFunctionName(); if (fn != null && fn.getReturn() != null && fn.getReturn().getType() != Object.class) { return fn.getReturn().getType(); } else if (f instanceof FilterFunction_Convert) { // special case for the convert function, which has the return type as // a parameter return f.getParameters().get(1).evaluate(null, Class.class); } return null; }
public FunctionBuilder reset(Function original) { name = original.getName(); args.clear(); args.addAll(original.getParameters()); literal.reset(original.getFallbackValue()); return this; }
public void testToLowerCase() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Function f = ff.function("strToLowerCase", ff.literal("UPCASE")); assertEquals("upcase", f.evaluate(null)); }
public void testIntersectsFilterFunctionUnreferencedGeometry() throws Exception { GeometryFactory gf = new GeometryFactory(); LineString ls = gf.createLineString( new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)}); Function intersects = ff.function("intersects", ff.property("geom"), ff.literal(ls)); Function clone = (Function) intersects.accept(reprojector, null); assertNotSame(intersects, clone); assertEquals(clone.getParameters().get(0), intersects.getParameters().get(0)); assertEquals(clone.getParameters().get(1), intersects.getParameters().get(1)); }
/** * Return {@link #DAY} formatted according to {@link #PATTERN} in a time zone. * * @param timezone in one of the formats supported by {@link TimeZone} * @return the formatted day */ private String formatTimezone(String timezone) { return (String) ff.function( FormatDateTimezoneFunction.NAME.getFunctionName(), ff.literal(PATTERN), ff.literal(TIME), ff.literal(timezone)) .evaluate(null); }
public void testNestedVolatile() { EnvFunction.setLocalValue("power", 3); Function f = ff.function("pow", ff.function("random"), ff.function("env", ff.literal("power"))); Function result = (Function) f.accept(simpleVisitor, null); // main function not simplified out assertEquals("pow", result.getName()); // first argument not simplified out Function param1 = (Function) result.getParameters().get(0); assertEquals("random", param1.getName()); // second argument simplified out Expression param2 = result.getParameters().get(1); assertTrue(param2 instanceof Literal); assertEquals(Integer.valueOf(3), param2.evaluate(null, Integer.class)); }
public void testCatenateTwo() { Literal l = ff.literal("http://test?param="); PropertyName pn = ff.property("intAttribute"); Expression cat = ExpressionExtractor.catenateExpressions(Arrays.asList(l, pn)); assertTrue(cat instanceof Function); Function f = (Function) cat; assertEquals("Concatenate", f.getName()); assertEquals(l, f.getParameters().get(0)); assertEquals(pn, f.getParameters().get(1)); }
@Test public void testNoVocabFunction() { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); Function function = ff.function("Vocab", ff.literal("a"), ff.literal("urn:1234")); try { function.evaluate(null); fail("Should not be able to get this far"); } catch (Exception expected) { } }
public void testChainIntersection() { Function innerBuffer1 = ff.function("buffer", ff.property("the_geom"), ff.literal(3)); Function innerBuffer2 = ff.function("buffer", ff.property("other_geom"), ff.literal(2)); Function geomTx = ff.function("intersection", innerBuffer1, innerBuffer2); ReferencedEnvelope re = new ReferencedEnvelope(0, 2, 0, 2, null); GeometryTransformationVisitor visitor = new GeometryTransformationVisitor(); ReferencedEnvelope result = (ReferencedEnvelope) geomTx.accept(visitor, re); ReferencedEnvelope expected = new ReferencedEnvelope(-3, 5, -3, 5, null); assertEquals(expected, result); } }
Function min_4Function = ff.function("min_4", literal_1, literal_m1); assertEquals( "min of (1.0,-1.0):", (long) Math.min(1.0, -1.0), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001); min_4Function = ff.function("min_4", literal_m1, literal_2); assertEquals( "min of (-1.0,2.0):", (long) Math.min(-1.0, 2.0), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001); "min of (2.0,-2.0):", (long) Math.min(2.0, -2.0), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001); "min of (-2.0,3.141592653589793):", (long) Math.min(-2.0, 3.141592653589793), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001); "min of (3.141592653589793,1.5707963267948966):", (long) Math.min(3.141592653589793, 1.5707963267948966), ((Integer) min_4Function.evaluate(null)).intValue(), 0.00001);
public void testCountFunctionDescription() throws Exception { // Create instance of function to get hold of the filter capabilities PropertyName exp = ff.property("foo"); Function func = ff.function("Collection_Count", exp); // Expecting one function parameter assertEquals(func.getParameters().size(), 1); // Test return parameter assertEquals(func.getFunctionName().getReturn().toString(), "count:Number"); }
public Object visit(org.opengis.filter.expression.Function function, Object extraData) { // can't optimize out volatile functions if (isVolatileFunction(function)) { return super.visit(function, extraData); } // stable function, is it using attributes? if (attributeExtractor == null) { attributeExtractor = new FilterAttributeExtractor(); } else { attributeExtractor.clear(); } function.accept(attributeExtractor, null); // if so we can replace it with a literal if (attributeExtractor.isConstantExpression()) { Object result = function.evaluate(null); return ff.literal(result); } else { return super.visit(function, extraData); } }
@Override public Object visit(Function expression, Object extraData) { List old = expression.getParameters(); FunctionName functionName = expression.getFunctionName(); List<Parameter<?>> arguments = null; if (functionName != null) { arguments = functionName.getArguments(); } Expression[] args = new Expression[old.size()]; for (int i = 0; i < old.size(); i++) { Expression exp = (Expression) old.get(i); if (arguments != null && i < arguments.size()) { args[i] = optimize(exp, extraData, arguments.get(i).getType()); } else { args[i] = visit(exp, extraData); } } Function duplicate; if (expression instanceof InternalFunction) { duplicate = ((InternalFunction) expression).duplicate(args); } else { duplicate = getFactory(extraData).function(expression.getName(), args); } return duplicate; }