Refine search
public Object visit(And filter, Object data) { if (data == null) return null; if (filter.getChildren() != null) { for (Filter child : filter.getChildren()) { data = child.accept(this, data); if (data == null) return null; } } return data; }
@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); }
/** * Returns a predicate that evaluates to {@code true} if each of its components evaluates to * {@code true}. * * <p>The components are evaluated in order, and evaluation will be "short-circuited" as soon as * a false predicate is found. */ public static Filter and(Filter op1, Filter op2) { List<Filter> children = new ArrayList<Filter>(); if (op1 instanceof And) { children.addAll(((And) op1).getChildren()); } else { children.add(op1); } if (op2 instanceof And) { children.addAll(((And) op2).getChildren()); } else { children.add(op2); } return factory.and(children); }
public void testCoalesheNestedAnd() { Filter eq = ff.equal(ff.property("A"), ff.literal("3"), true); Filter gt = ff.greater(ff.property("b"), ff.literal("3")); Filter lt = ff.less(ff.property("c"), ff.literal("5")); And nested = ff.and(Arrays.asList(ff.and(Arrays.asList(eq, gt)), lt)); And simplified = (And) nested.accept(simpleVisitor, null); assertEquals(3, simplified.getChildren().size()); assertEquals(ff.and(Arrays.asList(eq, gt, lt)), simplified); }
public void testIncludeAndExclude() { Filter result = (Filter) ff.and(Filter.INCLUDE, Filter.EXCLUDE).accept(simpleVisitor, null); assertEquals(Filter.EXCLUDE, result); }
LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertTrue(!filter.evaluate(testFeature)); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertTrue(!filter.evaluate(testFeature)); LOGGER.finer("contains feature: " + filter.evaluate(testFeature)); assertTrue(filter.evaluate(testFeature));
public Query invertQuery( @DescribeParameter(name = "outputBBOX", description = "Georeferenced bounding box of the output") ReferencedEnvelope envelope, Query targetQuery, GridGeometry targetGridGeometry ) throws ProcessException { final BBOXRemovingFilterVisitor visitor = new BBOXRemovingFilterVisitor(); Filter filter = (Filter) targetQuery.getFilter().accept(visitor, null); final String geometryName = visitor.getGeometryPropertyName(); if (geometryName != null) { final BBOX bbox; try { if (envelope.getCoordinateReferenceSystem() != null) { envelope = envelope.transform(DefaultGeographicCRS.WGS84,false); } bbox = FILTER_FACTORY.bbox(geometryName, envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY(), "EPSG:4326"); } catch (Exception e) { throw new ProcessException("Unable to create bbox filter for feature source", e); } filter = (Filter) FILTER_FACTORY.and(filter, bbox).accept(new SimplifyingFilterVisitor(), null); targetQuery.setFilter(filter); } final List<PropertyName> properties = new ArrayList<>(); properties.add(FILTER_FACTORY.property("_aggregation")); targetQuery.setProperties(properties); return targetQuery; }
@Override protected void addFiltersToResults(List<Filter> results, Filter filter) { if (filter instanceof org.opengis.filter.And) { results.addAll(((org.opengis.filter.And) filter).getChildren()); } else { results.add(filter); } } }
@Test public void testLogicFilterAnd() throws Exception { PropertyIsEqualTo equals = ff.equals(ff.property("measurement/result"), ff.literal(1.1)); PropertyIsGreaterThan greater = ff.greater(ff.property("measurement/determinand_description"), ff.literal("desc1")); And logicFilter = ff.and(equals, greater); Filter unrolled = (Filter) logicFilter.accept(visitor, null); assertNotNull(unrolled); assertTrue(unrolled instanceof And); assertNotSame(equals, unrolled); And sourceAnd = (And) unrolled; assertEquals(2, sourceAnd.getChildren().size()); Filter sourceEquals = (Filter) sourceAnd.getChildren().get(0); assertTrue(sourceEquals instanceof PropertyIsEqualTo); Expression left = ((PropertyIsEqualTo) sourceEquals).getExpression1(); Expression right = ((PropertyIsEqualTo) sourceEquals).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); assertEquals("results_value", ((PropertyName) left).getPropertyName()); assertEquals(new Double(1.1), ((Literal) right).getValue()); Filter sourceGreater = (Filter) sourceAnd.getChildren().get(1); assertTrue(sourceGreater instanceof PropertyIsGreaterThan); left = ((PropertyIsGreaterThan) sourceGreater).getExpression1(); right = ((PropertyIsGreaterThan) sourceGreater).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); assertEquals("determinand_description", ((PropertyName) left).getPropertyName()); assertEquals("desc1", ((Literal) right).getValue()); }
public void testExcludeAndExclude() { Filter result = (Filter) ff.and(Filter.EXCLUDE, Filter.EXCLUDE).accept(simpleVisitor, null); assertEquals(Filter.EXCLUDE, result); }
public Object visit(And filter, Object data) { if (filter.getChildren() != null) { for (Filter child : filter.getChildren()) { child.accept(this, data); if (found) break; } } return found; }
public AndBuilder<P> reset(And filter) { if (filter == null) { return unset(); } this.list = new ArrayList<FilterBuilder>(); if (filter.getChildren() != null) { for (Filter child : filter.getChildren()) { list.add(new FilterBuilder().reset(child)); } } return this; }
newList.add(child); And and = getFactory(extraData).and(newList); Filter simplified = (Filter) and.accept(this, extraData); if (simplified == Filter.EXCLUDE) { continue; return Collections.singletonList(reduced); } else { filters.addAll(((And) reduced).getChildren()); filters = basicAndSimplification(filters);
public void testIncludeAndProperty() { Filter result = (Filter) ff.and(Filter.INCLUDE, property).accept(simpleVisitor, null); assertEquals(property, result); }
public Object visit(And filter, Object data) { List<Filter> childList = filter.getChildren(); if (childList != null) { for (Filter child : childList) { if (child == null) continue; data = child.accept(this, data); } } return data; }
if (filter1 instanceof And) { And some = (And) filter1; list.addAll(some.getChildren()); } else if (filter1 != null) { list.add(filter1); list.addAll(more.getChildren()); } else if (filter2 != null) { list.add(filter2);
@Test public void testLogicFilterAnd() throws Exception { PropertyIsEqualTo equals = ff.equals(ff.property("measurement/result"), ff.literal(1.1)); PropertyIsGreaterThan greater = ff.greater(ff .property("measurement/determinand_description"), ff.literal("desc1")); And logicFilter = ff.and(equals, greater); Filter unrolled = (Filter) logicFilter.accept(visitor, null); assertNotNull(unrolled); assertTrue(unrolled instanceof And); assertNotSame(equals, unrolled); And sourceAnd = (And) unrolled; assertEquals(2, sourceAnd.getChildren().size()); Filter sourceEquals = (Filter) sourceAnd.getChildren().get(0); assertTrue(sourceEquals instanceof PropertyIsEqualTo); Expression left = ((PropertyIsEqualTo) sourceEquals).getExpression1(); Expression right = ((PropertyIsEqualTo) sourceEquals).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); assertEquals("results_value", ((PropertyName) left).getPropertyName()); assertEquals(new Double(1.1), ((Literal) right).getValue()); Filter sourceGreater = (Filter) sourceAnd.getChildren().get(1); assertTrue(sourceGreater instanceof PropertyIsGreaterThan); left = ((PropertyIsGreaterThan) sourceGreater).getExpression1(); right = ((PropertyIsGreaterThan) sourceGreater).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); assertEquals("determinand_description", ((PropertyName) left).getPropertyName()); assertEquals("desc1", ((Literal) right).getValue()); }
public void testIncludeAndInclude() { Filter result = (Filter) ff.and(Filter.INCLUDE, Filter.INCLUDE).accept(simpleVisitor, null); assertEquals(Filter.INCLUDE, result); }
@Override public Object visit(And filter, Object extraData) { List<Filter> children = filter.getChildren(); for (Filter child : children) { child.accept(this, extraData); } return extraData; }
/** * Splits a query into two parts, a spatial component that can be turned into a bbox filter (by * including some more feature in the result) and a residual component that we cannot address * with the spatial index * * @param query */ Filter[] splitFilters(Query query) { Filter filter = query.getFilter(); if (filter == null || filter.equals(Filter.EXCLUDE)) { return new Filter[] {Filter.EXCLUDE, bboxFilter(originalBounds)}; } if (!(filter instanceof And)) { Envelope envelope = getEnvelope(filter); if (envelope == null) return new Filter[] {Filter.EXCLUDE, bboxFilter(originalBounds)}; else return new Filter[] {Filter.EXCLUDE, bboxFilter(envelope)}; } And and = (And) filter; List residuals = new ArrayList(); List bboxBacked = new ArrayList(); for (Iterator it = and.getChildren().iterator(); it.hasNext(); ) { Filter child = (Filter) it.next(); if (getEnvelope(child) != null) { bboxBacked.add(child); } else { residuals.add(child); } } return new Filter[] {(Filter) ff.and(residuals), (Filter) ff.and(bboxBacked)}; }