### Question:
FilterSplitter extends StrictFilterAdapter<Object> { public Pair<Filter,Filter> split(Filter filter) { FilterStack stack = new FilterStack(); filter.accept(this, stack); Filter pass = Filters.all(); while (!stack.pass.isEmpty()) { pass = stack.pass.pop().and(pass); } Filter fail = Filters.all(); while (!stack.fail.isEmpty()) { fail = stack.fail.pop().and(fail); } return Pair.of(pass, fail); } FilterSplitter(FilterVisitor<Boolean> qualifier); Pair<Filter,Filter> split(Filter filter); @Override Object visit(Self self, Object obj); @Override Object visit(Literal literal, Object obj); @Override Object visit(Property property, Object obj); @Override Object visit(Function function, Object obj); @Override Object visit(Mixed mixed, Object obj); @Override Object visit(Math math, Object obj); @Override Object visit(Expression expr, Object obj); @Override Object visit(All<?> all, Object obj); @Override Object visit(None<?> none, Object obj); @Override Object visit(Id<?> id, Object obj); @Override Object visit(Comparison<?> compare, Object obj); @Override Object visit(Spatial<?> spatial, Object obj); @Override Object visit(TypeOf<?> inst, Object obj); @Override Object visit(In<?> in, Object obj); @Override Object visit(Like<?> like, Object obj); @Override Object visit(Null<?> isNull, Object obj); @Override Object visit(Filter<?> filter, Object obj); @Override Object visit(Logic<?> logic, Object obj);  }### Answer:
@Test public void testFlat() throws Exception { Filter f = CQL.parse("foo = TRUE AND x = TRUE"); Pair<Filter,Filter> split = split(f); assertEquals(f, split.first); assertEquals(Filters.all(), split.second); f = CQL.parse("foo = TRUE AND x = FALSE"); split = split(f); assertEquals(CQL.parse("foo = TRUE"), split.first); assertEquals(CQL.parse("x = FALSE"), split.second); f = CQL.parse("foo = FALSE AND x = FALSE"); split = split(f); assertEquals(Filters.all(), split.first); assertEquals(f, split.second); f = CQL.parse("foo = TRUE OR x = TRUE"); split = split(f); assertEquals(f, split.first); assertEquals(Filters.all(), split.second); f = CQL.parse("foo = TRUE OR x = FALSE"); split = split(f); assertEquals(Filters.all(), split.first); assertEquals(f, split.second); f = CQL.parse("foo = FALSE OR x = FALSE"); split = split(f); assertEquals(Filters.all(), split.first); assertEquals(f, split.second); }
@Test public void testNested() throws Exception { Filter f = CQL.parse("(foo = TRUE AND x = TRUE) AND z = TRUE"); Pair<Filter,Filter> split = split(f); assertEquals(f, split.first); assertEquals(Filters.all(), split.second); f = CQL.parse("(foo = TRUE OR x = FALSE) AND z = TRUE"); split = split(f); assertEquals(CQL.parse("z = TRUE"), split.first); assertEquals(CQL.parse("foo = TRUE OR x = FALSE"), split.second); f = CQL.parse("(foo = TRUE AND x = FALSE) AND z = TRUE"); split = split(f); assertEquals(CQL.parse("foo = TRUE AND z = TRUE"), split.first); assertEquals(CQL.parse("x = FALSE"), split.second); f = CQL.parse("(foo = TRUE AND x = FALSE) OR z = TRUE"); split = split(f); assertEquals(Filters.all(), split.first); assertEquals(CQL.parse("(foo = TRUE AND x = FALSE) OR z = TRUE"), split.second); }
@Test public void testNonLogic() throws Exception { Filter f = CQL.parse("foo = TRUE"); Pair<Filter,Filter> split = split(f); assertEquals(f, split.first); assertEquals(Filters.all(), split.second); f = CQL.parse("foo = FALSE"); split = split(f); assertEquals(Filters.all(), split.first); assertEquals(f, split.second); }