/** * 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... operands) { List<Filter> anded = Lists.newArrayList(operands); return factory.and(anded); }
/** * 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(List<Filter> operands) { if (operands.size() == 0) { return Filter.INCLUDE; } else if (operands.size() == 1) { return operands.get(0); } else { return factory.and(operands); } }
/** * 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); }
/** * Refine filter to make sure to AND the filter with a filter selecting the proper file * * @param filter * @return */ private Filter refineFilter(Filter filter) { return filter != null ? FF.and(filter, queryFilter) : queryFilter; } }
@SuppressWarnings("unchecked") private <T extends BinaryLogicOperator> T createOperator(T oldParent, List<Filter> children) { T result = null; if (oldParent instanceof And) { result = (T) ff.and(children); } else if (oldParent instanceof Or) { result = (T) ff.or(children); } return result; }
private Filter override(Filter filter, Filter override) { if (isNOP(override)) { // no override is needed return filter; } else if (isNOP(filter)) { return override; } else { return ff.and(filter, override); } }
public void testNullTransactionAccessor() throws Exception { accessor = null; Filter f1 = createPropertyIsEqualToFilter(nameAtt, "david"); Filter f2 = createPropertyIsEqualToFilter(nameAtt, "david"); runTest(ff.and(f1, f2), simpleLogicalCaps, nameAtt); }
public void testVisitLogicalANDFilter() throws Exception { Filter f1 = createPropertyIsEqualToFilter(nameAtt, "david"); Filter f2 = createPropertyIsEqualToFilter(nameAtt, "david"); runTest(ff.and(f1, f2), simpleLogicalCaps, nameAtt); }
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 testRecurseAnd() { Filter test = ff.and(Filter.INCLUDE, ff.or(property, Filter.EXCLUDE)); assertEquals(property, test.accept(simpleVisitor, null)); }
public void testAndWithLikeEncode() throws Exception { FilterFactory f = FilterMockData.f; And and = f.and(FilterMockData.propertyIsLike(), FilterMockData.propertyIsLike()); Document dom = encode(and, OGC.And); assertEquals(2, getElementsByQName(dom, OGC.PropertyIsLike).getLength()); }
public void testAndWithNullEncode() throws Exception { FilterFactory f = FilterMockData.f; And and = f.and(FilterMockData.propertyIsNull(), FilterMockData.propertyIsNull()); Document dom = encode(and, OGC.And); assertEquals(2, getElementsByQName(dom, OGC.PropertyIsNull).getLength()); }
public void testAndWithBetweenEncode() throws Exception { FilterFactory f = FilterMockData.f; And and = f.and(FilterMockData.propertyIsBetween(), FilterMockData.propertyIsBetween()); Document dom = encode(and, OGC.And); assertEquals(2, getElementsByQName(dom, OGC.PropertyIsBetween).getLength()); } }
@Test public void testVisitLogicalANDFilter() throws Exception { Filter f1 = createPropertyIsEqualToFilter(nameAtt, "david"); Filter f2 = createPropertyIsEqualToFilter(nameAtt, "david"); runTest(ff.and(f1, f2), simpleLogicalCaps, nameAtt); }
@Test public void testNullTransactionAccessor() throws Exception { accessor = null; Filter f1 = createPropertyIsEqualToFilter(nameAtt, "david"); Filter f2 = createPropertyIsEqualToFilter(nameAtt, "david"); runTest(ff.and(f1, f2), simpleLogicalCaps, nameAtt); }
public void testDualFilterNullAnd() { Filter original = ff.and( Arrays.asList( ff.not(ff.isNull(ff.property("a"))), ff.isNull(ff.property("a")))); assertEquals(Filter.EXCLUDE, original.accept(simpleVisitor, null)); }
public void testSimplifyFilter() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Filter filter = ff.and(Filter.INCLUDE, Filter.INCLUDE); Query query = new Query(Query.ALL); query.setFilter(filter); DataUtilities.simplifyFilter(query); assertEquals(Filter.INCLUDE, query.getFilter()); }
public void testDualFilterAnd() { Filter original = ff.and( Arrays.asList( ff.not(ff.equal(ff.property("a"), ff.literal(3), true)), ff.equal(ff.property("a"), ff.literal(3), true))); assertEquals(Filter.EXCLUDE, original.accept(simpleVisitor, null)); }
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 testNegateOr() throws Exception { // not(a > 3 or b = 5 or c < 0) Filter fa = ff.greater(ff.property(aname(A)), ff.literal(3)); Filter fb = ff.equal(ff.property(aname(B)), ff.literal(5), false); Filter fc = ff.less(ff.property(aname(C)), ff.literal(0)); Not filter = ff.not(ff.and(Arrays.asList(fa, fb, fc))); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); Query q = new Query(tname(ABC), filter); int count = fs.getCount(q); assertEquals(2, count); }