/** * @return PropertyIsLessThanOrEqualTo * @throws CQLException */ public PropertyIsLessThanOrEqualTo buildLessOrEqual() throws CQLException { Expression right = this.resultStack.popExpression(); Expression left = this.resultStack.popExpression(); return filterFactory.lessOrEqual(left, right); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { Expression e1 = (Expression) node.getChildValue(0); Expression e2 = (Expression) node.getChildValue(1); return filterfactory.lessOrEqual(e1, e2); } }
/** * @return PropertyIsLessThanOrEqualTo * @throws CQLException */ public PropertyIsLessThanOrEqualTo buildPropertyIsLTELastDate() throws CQLException { PeriodNode period = this.resultStack.popPeriodNode(); org.opengis.filter.expression.Literal date = period.getEnding(); org.opengis.filter.expression.Expression property = this.resultStack.popExpression(); PropertyIsLessThanOrEqualTo filter = filterFactory.lessOrEqual(property, date); return filter; }
Filter lowerBound = ff.lessOrEqual(localMin, localMax); Filter upperBound; if (upperBoundClosed) { upperBound = ff.lessOrEqual(attrib, localMax); } else { upperBound = ff.less(attrib, localMax);
/** Helper method to create a "length" filter. */ protected Filter lengthRestriction(int length) { if (length < 0) { return null; } LengthFunction lengthFunction = (LengthFunction) ff.function("LengthFunction", new Expression[] {ff.property(".")}); if (lengthFunction == null) { return null; } Filter cf = null; try { cf = ff.lessOrEqual(lengthFunction, ff.literal(length)); } catch (IllegalFilterException e) { // TODO something } return cf == null ? Filter.EXCLUDE : cf; } }
/** * Create an AND filter with property between dates of period. (firstDate<= property <= * lastDate) * * @return And filter * @throws CQLException */ public And buildPropertyBetweenDates() throws CQLException { // retrieves date and duration of expression Result node = this.resultStack.popResult(); PeriodNode period = (PeriodNode) node.getBuilt(); Literal begin = period.getBeginning(); Literal end = period.getEnding(); // creates and filter firstDate<= property <= lastDate Expression property = this.resultStack.popExpression(); And filter = filterFactory.and( filterFactory.lessOrEqual(begin, property), filterFactory.lessOrEqual(property, end)); return filter; }
private Filter toLessFilter(FilterFactory ff, Expression variable, Range<T> range) { if (range.isMaxIncluded()) { return ff.lessOrEqual(variable, ff.literal(range.getMaxValue())); } else { return ff.less(variable, ff.literal(range.getMaxValue())); } }
public void testFiltersByDate() throws Exception { setup.setUpData(); FilterFactory ff = dataStore.getFilterFactory(); DateFormat df = new SimpleDateFormat("yyyy-dd-MM"); ContentFeatureSource fs = dataStore.getFeatureSource(tname("dates")); Filter f = ff.lessOrEqual(ff.property(aname("d")), ff.literal(df.parse("2009-28-06"))); assertEquals( "wrong number of records for " + TimeZone.getDefault().getDisplayName(), 2, fs.getCount(new Query(tname("dates"), f))); TimeZone.setDefault(originalTimeZone); setup.setUpData(); } }
ff.lessOrEqual(ff.property(aname("d")), ff.literal(df.parse("2009-28-06")));
private <T> void testOrPseudoBetween(Class<T> type, T min, T max) throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "a:" + type.getName()); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); visitor.setFeatureType(schema); // (a > min && a <= max) or (a <= min) Filter original = ff.or( Arrays.asList( // ff.and( ff.greater(ff.property("a"), ff.literal(min)), // ff.lessOrEqual(ff.property("a"), ff.literal(max))), // ff.lessOrEqual(ff.property("a"), ff.literal(min)))); Filter simplified = (Filter) original.accept(visitor, null); assertEquals(ff.lessOrEqual(ff.property("a"), ff.literal(max)), simplified); }
private <T> void testOrTouchingRanges(Class<T> type, T value) throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "a:" + type.getName()); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); visitor.setFeatureType(schema); Filter original = ff.or( ff.greaterOrEqual(ff.property("a"), ff.literal(value)), ff.lessOrEqual(ff.property("a"), ff.literal(value))); Filter simplified = (Filter) original.accept(visitor, null); assertEquals(Filter.INCLUDE, simplified); }
public void testNegateGreater() { Filter f = ff.not(ff.greater(ff.property("prop"), ff.literal(10))); Filter result = (Filter) f.accept(simpleVisitor, null); assertEquals(ff.lessOrEqual(ff.property("prop"), ff.literal(10)), result); // not simplified for complex features result = (Filter) f.accept(complexVisitor, null); assertEquals(f, result); }
private <T> void testAndTouchingRanges(Class<T> type, T value) throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "a:" + type.getName()); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); visitor.setFeatureType(schema); Filter original = ff.and( ff.greaterOrEqual(ff.property("a"), ff.literal(value)), ff.lessOrEqual(ff.property("a"), ff.literal(value))); Filter simplified = (Filter) original.accept(visitor, null); assertEquals(ff.equal(ff.property("a"), ff.literal(value), false), simplified); }
public void testNegateLessOrEqual() { Filter f = ff.not(ff.lessOrEqual(ff.property("prop"), ff.literal(10))); Filter result = (Filter) f.accept(simpleVisitor, null); assertEquals(ff.greater(ff.property("prop"), ff.literal(10)), result); // not simplified for complex features result = (Filter) f.accept(complexVisitor, null); assertEquals(f, result); }
Filter lessFilter = ff.lessOrEqual(ff.property(attribute), ff.literal(targetValue)); qBelow.setFilter(ff.and(query.getFilter(), lessFilter)); MaxVisitor max = new MaxVisitor(attribute);
private <T> void testAndOverlappingRangesToBetween(Class<T> type, T min, T mid, T max) throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "a:" + type.getName()); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); visitor.setFeatureType(schema); // excluding extrema, not possible to turn it into a between filter Filter original = ff.and( Arrays.asList( // (Filter) ff.greaterOrEqual(ff.property("a"), ff.literal(min)), // ff.less(ff.property("a"), ff.literal(max)), // ff.lessOrEqual(ff.property("a"), ff.literal(mid)))); Filter simplified = (Filter) original.accept(visitor, null); assertEquals(ff.between(ff.property("a"), ff.literal(min), ff.literal(mid)), simplified); }
public void testRangeExpression() throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "pop:String"); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); visitor.setFeatureType(schema); Function func = ff.function("parseLong", ff.property("pop")); Filter f1 = ff.less(func, ff.literal(20000)); Filter f2 = ff.between(func, ff.literal(20000), ff.literal(50000)); Filter or = ff.or(f1, f2); Filter simplified = (Filter) or.accept(visitor, null); assertEquals(ff.lessOrEqual(func, ff.literal(50000)), simplified); }
public void testSimplifyStaticExclude() { assertEquals(Filter.EXCLUDE, simplify(ff.greater(ff.literal(3), ff.literal(5)))); assertEquals(Filter.EXCLUDE, simplify(ff.greaterOrEqual(ff.literal(3), ff.literal(5)))); assertEquals(Filter.EXCLUDE, simplify(ff.less(ff.literal(5), ff.literal(3)))); assertEquals(Filter.EXCLUDE, simplify(ff.lessOrEqual(ff.literal(5), ff.literal(3)))); assertEquals(Filter.EXCLUDE, simplify(ff.equal(ff.literal(5), ff.literal(3), true))); assertEquals( Filter.EXCLUDE, simplify(ff.between(ff.literal(3), ff.literal(1), ff.literal(2)))); }
public void testSimplifyStaticInclude() { assertEquals(Filter.INCLUDE, simplify(ff.less(ff.literal(3), ff.literal(5)))); assertEquals(Filter.INCLUDE, simplify(ff.lessOrEqual(ff.literal(3), ff.literal(5)))); assertEquals(Filter.INCLUDE, simplify(ff.greater(ff.literal(5), ff.literal(3)))); assertEquals(Filter.INCLUDE, simplify(ff.greaterOrEqual(ff.literal(5), ff.literal(3)))); assertEquals(Filter.INCLUDE, simplify(ff.equal(ff.literal(5), ff.literal(5), true))); assertEquals( Filter.INCLUDE, simplify(ff.between(ff.literal(3), ff.literal(1), ff.literal(4)))); }
public void testAttributeBuilder() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(); AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.binding(Integer.class); builder.minOccurs(1).maxOccurs(1); builder.defaultValue(0); builder.name("percent").description("Percent between 0 and 100"); builder.restriction(ff.greaterOrEqual(ff.property("."), ff.literal(0))) .restriction(ff.lessOrEqual(ff.property("."), ff.literal(100))); final AttributeType PERCENT = builder.buildType(); builder.minOccurs(1).maxOccurs(1); builder.defaultValue(0); builder.name("percent").description("Percent between 0 and 100"); AttributeDescriptor a = builder.buildDescriptor("a", PERCENT); assertSame(a.getType(), PERCENT); assertEquals(a.getDefaultValue(), 0); Filter restrictions = ff.and(PERCENT.getRestrictions()); assertTrue(restrictions.evaluate(50)); assertFalse(restrictions.evaluate(150)); }