CompoundQuery implements Query<O> { public static <O> CompoundQuery<O> fromAndQueryIfSuitable(And<O> andQuery) { if (andQuery.hasLogicalQueries() || andQuery.hasComparativeQueries()) { return null; } List<Attribute<O, ?>> attributeList = new ArrayList<Attribute<O, ?>>(andQuery.getSimpleQueries().size()); for (SimpleQuery<O, ?> simpleQuery : andQuery.getSimpleQueries()) { if (!(simpleQuery instanceof Equal)) { return null; } attributeList.add(simpleQuery.getAttribute()); } CompoundAttribute<O> compoundAttribute = new CompoundAttribute<O>(attributeList); return new CompoundQuery<O>(andQuery, compoundAttribute); } CompoundQuery(And<O> andQuery, CompoundAttribute<O> compoundAttribute); @Override boolean matches(O object, QueryOptions queryOptions); And<O> getAndQuery(); CompoundAttribute<O> getCompoundAttribute(); CompoundValueTuple<O> getCompoundValueTuple(); static CompoundQuery<O> fromAndQueryIfSuitable(And<O> andQuery);  }
@Test public void testFromAndQueryIfSuitable() { assertNotNull(CompoundQuery.fromAndQueryIfSuitable(and(equal(Car.DOORS, 5), equal(Car.MANUFACTURER, "Ford")))); assertNull(CompoundQuery.fromAndQueryIfSuitable(and(equal(Car.DOORS, 5), in(Car.MANUFACTURER, "Ford", "Honda")))); }