public Object visit(PropertyIsBetween filter, Object arg1) { Expression expression = filter.getExpression(); Expression lower = filter.getLowerBoundary(); Expression upper = filter.getUpperBoundary(); List expressions = (List) expression.accept(this, null); List lowerExpressions = (List) lower.accept(this, null); List upperExpressions = (List) upper.accept(this, null); final int combinedSize = expressions.size() * lowerExpressions.size() * upperExpressions.size(); List combinedFilters = new ArrayList(combinedSize); for (Iterator lowers = lowerExpressions.iterator(); lowers.hasNext(); ) { Expression floor = (Expression) lowers.next(); for (Iterator exprs = expressions.iterator(); exprs.hasNext(); ) { Expression prop = (Expression) exprs.next(); for (Iterator uppers = upperExpressions.iterator(); uppers.hasNext(); ) { Expression roof = (Expression) uppers.next(); Filter newFilter = ff.between(prop, floor, roof, filter.getMatchAction()); combinedFilters.add(newFilter); } } } Filter unrolled = combineOred(combinedFilters); return unrolled; }
/** * @see org.geotools.xml.schema.Type#getValue(org.geotools.xml.schema.Element, * org.geotools.xml.schema.ElementValue[], org.xml.sax.Attributes, java.util.Map) */ public Object getValue(Element element, ElementValue[] value, Attributes attrs, Map hints) throws SAXException { FilterFactory2 factory = FilterSchema.filterFactory(hints); try { Expression left = (Expression) value[1].getValue(); Expression middle = (Expression) value[0].getValue(); Expression right = (Expression) value[2].getValue(); return factory.between(middle, left, right); } catch (ClassCastException expressionRequired) { throw new SAXException("Illegal filter for " + element, expressionRequired); } catch (IllegalFilterException e) { throw new SAXException("Illegal filter for " + element); } }
/** * Test the between operator. * * @throws IllegalFilterException If the constructed filter is not valid. */ public void testBetween() throws IllegalFilterException { // Set up the integer Literal lower = fac.literal(1001); Literal upper = fac.literal(1003); PropertyName pint = fac.property("testInteger"); PropertyName plong = fac.property("testLong"); PropertyName pfloat = fac.property("testFloat"); assertAttributeName(fac.between(lower, lower, upper), new String[0]); assertAttributeName(fac.between(pint, lower, upper), "testInteger"); assertAttributeName(fac.between(pint, pint, pint), "testInteger"); assertAttributeName( fac.between(pint, plong, pfloat), new String[] {"testInteger", "testLong", "testFloat"}); }
static PropertyIsBetween propertyIsBetween() { return f.between(f.property("foo"), f.literal(1), f.literal(2)); }
public Object visit(PropertyIsBetween filter, Object extraData) { Expression expr = visit(filter.getExpression(), extraData); Expression lower = visit(filter.getLowerBoundary(), extraData); Expression upper = visit(filter.getUpperBoundary(), extraData); return getFactory(extraData).between(expr, lower, upper, filter.getMatchAction()); }
public void testGeometryFilter() throws IllegalFilterException { Disjoint geomFilter1 = ff.disjoint(testExp1, testExp4); Disjoint geomFilter2 = ff.disjoint(testExp2, testExp4); assertTrue(geomFilter1.equals(geomFilter2)); geomFilter2 = ff.disjoint(testExp2, new LiteralExpressionImpl(new Double(45))); assertTrue(!geomFilter1.equals(geomFilter2)); tFilter1 = ff.between(ff.literal(1), ff.literal(-1), ff.literal(3)); assertTrue(!geomFilter1.equals(tFilter1)); } }
public void testCompareFilter() throws IllegalFilterException { testExp1 = new LiteralExpressionImpl(Integer.valueOf(45)); testExp2 = new LiteralExpressionImpl(Integer.valueOf(45)); testExp3 = new AttributeExpressionImpl(testSchema, "testInteger"); testExp4 = new AttributeExpressionImpl(testSchema, "testInteger"); PropertyIsEqualTo cFilter1 = ff.equals(testExp1, testExp3); PropertyIsEqualTo cFilter2 = ff.equals(testExp1, testExp3); assertTrue(cFilter1.equals(cFilter2)); cFilter2 = ff.equals(testExp2, testExp4); assertTrue(cFilter1.equals(cFilter2)); // see if converters make this work cFilter2 = ff.equals(ff.literal(new Double(45.0)), testExp3); assertTrue(cFilter1.equals(cFilter2)); tFilter1 = ff.between(testExp1, testExp2, testExp3); assertTrue(!cFilter1.equals(tFilter1)); }
@Test public void testNonSpatialFilter() { Filter filter = ff.between(ff.property("someAtt"), ff.literal(2), ff.literal(4)); SpatialIndexFeatureCollection collection = null; try { collection = new SpatialIndexFeatureCollection(delegate); } catch (IOException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } SimpleFeatureCollection sub = collection.subCollection(filter); assertEquals(3, sub.size()); }
public void testBetweenStrings() throws IllegalFilterException { // Set up the integer Literal testLiteralLower = new LiteralExpressionImpl("blorg"); PropertyName testAttribute = new AttributeExpressionImpl(testSchema, "testString"); Literal testLiteralUpper = new LiteralExpressionImpl("tron"); // String tests PropertyIsBetween filter = fac.between(testAttribute, testLiteralLower, testLiteralUpper); assertTrue(filter.evaluate(testFeature)); // Test for false positive. testLiteralLower = new LiteralExpressionImpl("zebra"); testLiteralUpper = new LiteralExpressionImpl("zikes"); filter = fac.between(testAttribute, testLiteralLower, testLiteralUpper); assertFalse(filter.evaluate(testFeature)); }
public void testNullBetween() { Filter f = fac.between(fac.property("nullInt"), fac.literal(10), fac.literal(20)); Assert.assertFalse(f.evaluate(testFeature)); }
@Override public Object visit(PropertyIsBetween filter, Object extraData) { Class targetType = getTargetType( filter.getLowerBoundary(), filter.getExpression(), filter.getUpperBoundary()); Expression lb = optimize(filter.getLowerBoundary(), extraData, targetType); Expression ex = optimize(filter.getExpression(), extraData, targetType); Expression ub = optimize(filter.getUpperBoundary(), extraData, targetType); return getFactory(extraData).between(ex, lb, ub, filter.getMatchAction()); }
/** * Test the between operator. * * @throws IllegalFilterException If the constructed filter is not valid. */ public void testBetween() throws IllegalFilterException { // Set up the integer Literal testLiteralLower = fac.literal(1001); PropertyName testAttribute = fac.property("testInteger"); Literal testLiteralUpper = fac.literal(1003); // String tests PropertyIsBetween filter = fac.between(testAttribute, testLiteralLower, testLiteralUpper); assertTrue(filter.evaluate(testFeature)); // Test for false positive. testLiteralLower = fac.literal(1); testLiteralUpper = fac.literal(1000); filter = fac.between(testAttribute, testLiteralLower, testLiteralUpper); // LOGGER.finer( filter.toString()); // LOGGER.finer( "contains feature: " + filter.evaluate(testFeature)); assertFalse(filter.evaluate(testFeature)); }
public void testLogicFilter() throws IllegalFilterException { testExp1 = new LiteralExpressionImpl(Integer.valueOf(45)); testExp2 = new LiteralExpressionImpl(Integer.valueOf(45)); testExp3 = new AttributeExpressionImpl(testSchema, "testInteger"); testExp4 = new AttributeExpressionImpl(testSchema, "testInteger"); PropertyIsEqualTo cFilter1 = ff.equals(testExp1, testExp2); PropertyIsEqualTo cFilter2 = ff.equals(testExp2, testExp4); org.opengis.filter.Filter logFilter1 = ff.and(cFilter1, cFilter2); org.opengis.filter.Filter logFilter2 = ff.and(cFilter1, cFilter2); assertTrue(logFilter1.equals(logFilter2)); logFilter1 = ff.not(cFilter2); assertTrue(!logFilter1.equals(logFilter2)); cFilter1 = ff.equals(testExp1, testExp3); logFilter2 = ff.not(cFilter1); assertTrue(logFilter1.equals(logFilter2)); assertTrue(!logFilter1.equals(ff.between(testExp1, testExp2, testExp3))); Or logFilter3 = ff.or(logFilter1, logFilter2); Or logFilter4 = ff.or(logFilter1, logFilter2); assertTrue(logFilter3.equals(logFilter4)); // Questionable behavior. Is this what we want? Or logFilter5 = ff.or(cFilter1, logFilter3); // does not change structure of logFilter3 Or logFilter6 = ff.or(logFilter4, cFilter1); // different structure, but same result assertTrue(logFilter5.equals(logFilter6)); // do we want these equal? assertTrue(logFilter4.equals(logFilter3)); // shouldn't they be equal? }
@Test public void testBetween() { PropertyIsBetween between = ff.between(ff.property("a"), ff.property("b"), ff.property("c")); NullHandlingVisitor visitor = new NullHandlingVisitor(); Filter result = (Filter) between.accept(visitor, null); assertTrue(result instanceof And); Filter expected = ff.and( Arrays.asList( between, propertyNotNull("a"), propertyNotNull("b"), propertyNotNull("c"))); assertEquals(expected, result); between = ff.between(ff.property("a"), ff.property("b"), ff.literal(10)); result = (Filter) between.accept(visitor, null); assertTrue(result instanceof And); expected = ff.and(Arrays.asList(between, propertyNotNull("a"), propertyNotNull("b"))); assertEquals(expected, result); between = ff.between(ff.property("a"), ff.literal(5), ff.literal(10)); result = (Filter) between.accept(visitor, null); assertTrue(result instanceof And); expected = ff.and(Arrays.asList(between, propertyNotNull("a"))); assertEquals(expected, result); between = ff.between(ff.literal(7), ff.literal(5), ff.literal(10)); result = (Filter) between.accept(visitor, null); assertEquals(between, result); }
@Test public void testAndTemporalBetween() throws Exception { final Instant start = instant("2016-01-01T00:00:00.000-0500"); final Instant end = instant("2106-01-02T00:00:00.000-0500"); final Filter f = ff.and( ff.bbox("geom", -10, -10, 10, 10, null), ff.between(ff.literal("someDate"), ff.literal(start), ff.literal(end))); final Envelope env = (Envelope) f.accept(visitor, null); assertEquals(new Envelope(-10, 10, -10, 10), env); }
@Test public void testBetweenFilter() throws Exception { PropertyIsBetween bf = ff.between( ff.property("measurement/result"), ff.literal(1), ff.literal(2), MatchAction.ALL); PropertyIsBetween unrolled = (PropertyIsBetween) bf.accept(visitor, null); assertEquals(MatchAction.ALL, ((PropertyIsBetween) unrolled).getMatchAction()); Expression att = unrolled.getExpression(); assertTrue(att instanceof PropertyName); String propertyName = ((PropertyName) att).getPropertyName(); assertEquals("results_value", propertyName); }
public void testFullySupports() { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); try { logFilter = ff.and(gFilter, compFilter); assertTrue(capabilities.fullySupports(compFilter)); assertTrue(!(capabilities.fullySupports(gFilter))); assertTrue(!(capabilities.fullySupports(logFilter))); logFilter = ff.and( compFilter, ff.between(ff.property("sample"), ff.literal(1), ff.literal(2))); assertTrue(capabilities.fullySupports(logFilter)); logFilter = ff.or( logFilter, ff.between(ff.property("sample"), ff.literal(1), ff.literal(2))); assertTrue(capabilities.fullySupports(logFilter)); logFilter = ff.and(logFilter, gFilter); assertTrue(!(capabilities.fullySupports(logFilter))); } catch (IllegalFilterException e) { LOGGER.fine("Bad filter " + e); } } }
@Test public void testSimplifyRedundant() { PropertyIsBetween between = ff.between(ff.property("a"), ff.property("b"), ff.property("c")); PropertyIsEqualTo equal = ff.equal(ff.property("a"), ff.property("b"), false); And and = ff.and(between, equal); NullHandlingVisitor nh = new NullHandlingVisitor(); Filter nhResult = (Filter) and.accept(nh, null); SimplifyingFilterVisitor simplifier = new SimplifyingFilterVisitor(); Filter simplified = (Filter) nhResult.accept(simplifier, null); assertTrue(simplified instanceof And); Filter expected = ff.and( Arrays.asList( between, equal, propertyNotNull("a"), propertyNotNull("b"), propertyNotNull("c"))); assertEquals(expected, simplified); }
@Test public void testNullableAttributes() { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.nillable(true); tb.add("a", String.class); tb.nillable(false); tb.add("b", String.class); tb.nillable(true); tb.add("c", String.class); tb.setName("test"); SimpleFeatureType schema = tb.buildFeatureType(); PropertyIsBetween between = ff.between(ff.property("a"), ff.property("b"), ff.property("c")); NullHandlingVisitor visitor = new NullHandlingVisitor(schema); Filter result = (Filter) between.accept(visitor, null); assertTrue(result instanceof And); Filter expected = ff.and(Arrays.asList(between, propertyNotNull("a"), propertyNotNull("c"))); assertEquals(expected, result); }
public void testCapablities() { Capabilities capabilities = new Capabilities(); capabilities.addType(Beyond.class); // add to SpatialCapabilities capabilities.addType(After.class); // add to TemporalCapabilities capabilities.addType(PropertyIsEqualTo.class); // add to ScalarCapabilities capabilities.addName("NullCheck"); // will enable PropertyIsNull use capabilities.addName("Mul"); // will enable hasSimpleArithmatic capabilities.addName("random"); // a function returning a random number capabilities.addName("Length", 1); // single argument function capabilities.addName("toDegrees", "radians"); // single argument function capabilities.addName("length", "expression"); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); Filter filter = ff.between(ff.literal(0), ff.property("x"), ff.literal(2)); assertFalse("supports", capabilities.supports(filter)); filter = ff.equals(ff.property("x"), ff.literal(2)); assertTrue("supports", capabilities.supports(filter)); filter = ff.after(ff.property("x"), ff.literal("1970-01-01 00:00:00")); assertTrue("supports", capabilities.supports(filter)); assertTrue("fullySupports", capabilities.fullySupports(filter)); Capabilities capabilities2 = new Capabilities(); capabilities2.addAll(capabilities); capabilities2.addType(And.class); assertTrue(capabilities2.getContents().getScalarCapabilities().hasLogicalOperators()); assertFalse(capabilities.getContents().getScalarCapabilities().hasLogicalOperators()); }