public Object accept(ExpressionVisitor visitor, Object extraData) { return delegate.accept(visitor, extraData); }
public void testVolatileFunction() { Function f = ff.function("random"); Expression result = (Expression) f.accept(simpleVisitor, null); assertTrue(result instanceof FilterFunction_random); }
function.accept(testVisitor, extraData); Object[] functionVisited = testVisitor.functionVisited; if (Boolean.TRUE != functionVisited[0] || extraData != functionVisited[1]) {
@Test public void testFunction() { Function func = ff.function(("abs"), ff.literal(10)); assertEquals(Integer.class, func.accept(visitor, null)); }
public void testChainBuffer() { // check buffer chaining Function innerBuffer = ff.function("buffer", ff.property("the_geom"), ff.literal(3)); Function geomTx = ff.function("buffer", innerBuffer, ff.literal(2)); ReferencedEnvelope re = new ReferencedEnvelope(0, 2, 0, 2, null); GeometryTransformationVisitor visitor = new GeometryTransformationVisitor(); ReferencedEnvelope result = (ReferencedEnvelope) geomTx.accept(visitor, re); ReferencedEnvelope expected = new ReferencedEnvelope(-5, 7, -5, 7, null); assertEquals(expected, result); }
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); } }
@Test public void testFunction() throws Exception { Function fe = ff.function( "strIndexOf", ff.property("/measurement/determinand_description"), ff.literal("determinand_description_1")); List unrolledExpressions = (List) fe.accept(visitor, null); Expression unmapped = (Expression) unrolledExpressions.get(0); assertTrue(unmapped instanceof Function); List params = ((Function) unmapped).getParameters(); assertEquals(2, params.size()); assertTrue(params.get(0) instanceof PropertyName); assertEquals("determinand_description", ((PropertyName) params.get(0)).getPropertyName()); }
public Object accept(ExpressionVisitor visitor, Object extraData) { return delegate.accept( visitor, extraData ); }
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); } }
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)); }
public void testStableFunction() { EnvFunction.setLocalValue("var", "123"); Function f = ff.function("env", ff.literal("var")); Expression result = (Expression) f.accept(simpleVisitor, null); assertTrue(result instanceof Literal); assertEquals("123", result.evaluate(null, String.class)); }
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 testIntersectsFilterFunctionReferencedGeometry() throws Exception { GeometryFactory gf = new GeometryFactory(); LineString ls = gf.createLineString( new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)}); ls.setUserData(CRS.decode("urn:x-ogc:def:crs:EPSG:6.11.2:4326")); 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)); assertFalse(clone.getParameters().get(1).equals(intersects.getParameters().get(1))); LineString clonedLs = (LineString) ((Literal) clone.getParameters().get(1)).getValue(); assertTrue(15 == clonedLs.getCoordinateN(0).x); assertTrue(10 == clonedLs.getCoordinateN(0).y); assertTrue(25 == clonedLs.getCoordinateN(1).x); assertTrue(20 == clonedLs.getCoordinateN(1).y); assertEquals(CRS.decode("EPSG:4326"), clonedLs.getUserData()); }
public Object visit(org.opengis.filter.expression.Function function, Object extraData) { // can't optimize out volatile functions if (function instanceof VolatileFunction) { 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); } }
@Test public void testFunction() throws Exception { Function fe = ff.function("strIndexOf", ff.property("/measurement/determinand_description"), ff .literal("determinand_description_1")); List unrolledExpressions = (List) fe.accept(visitor, null); Expression unmapped = (Expression) unrolledExpressions.get(0); assertTrue(unmapped instanceof Function); List params = ((Function) unmapped).getParameters(); assertEquals(2, params.size()); assertTrue(params.get(0) instanceof PropertyName); assertEquals("determinand_description", ((PropertyName) params.get(0)).getPropertyName()); }