PartialIndex implements AttributeIndex<A, O> { static <A, O, I extends AttributeIndex<A, O>> boolean supportsQueryInternal(I backingIndex, Query<O> filterQuery, Query<O> rootQuery, Query<O> branchQuery, QueryOptions queryOptions) { if (!backingIndex.supportsQuery(branchQuery, queryOptions)) { return false; } if (filterQuery.equals(rootQuery)) { return true; } if (!(rootQuery instanceof And)) { return false; } And<O> rootAndQuery = (And<O>)rootQuery; if (rootAndQuery.getChildQueries().contains(filterQuery)) { return true; } if (!(filterQuery instanceof And)) { return false; } And<O> filterAndQuery = ((And<O>) filterQuery); return rootAndQuery.getChildQueries().containsAll(filterAndQuery.getChildQueries()); } protected  PartialIndex(Attribute<O, A> attribute, Query<O> filterQuery); Attribute<O, A> getAttribute(); Query<O> getFilterQuery(); AttributeIndex<A, O> getBackingIndex(); @Override boolean supportsQuery(Query<O> query, QueryOptions queryOptions); @Override boolean equals(Object o); @Override int hashCode(); @Override boolean isMutable(); @Override boolean isQuantized(); @Override ResultSet<O> retrieve(Query<O> query, QueryOptions queryOptions); @Override Index<O> getEffectiveIndex(); @Override void init(ObjectStore<O> objectStore, QueryOptions queryOptions); @Override void destroy(QueryOptions queryOptions); @Override boolean addAll(ObjectSet<O> objectSet, QueryOptions queryOptions); @Override boolean removeAll(ObjectSet<O> objectSet, QueryOptions queryOptions); @Override void clear(QueryOptions queryOptions);  }
@Test public <O> void testSupportsQuery_Positive_RootQueryEqualsFilterQuery() { assertTrue(supportsQueryInternal( backingIndexSupportsQuery(in(Car.MANUFACTURER, "Ford", "Honda")), in(Car.MANUFACTURER, "Ford", "Honda"), in(Car.MANUFACTURER, "Ford", "Honda"), in(Car.MANUFACTURER, "Ford", "Honda"), noQueryOptions() )); }
@Test public <O> void testSupportsQuery_Positive_RootQueryIsAnAndQueryWithFilterQueryAsChild() { assertTrue(supportsQueryInternal( backingIndexSupportsQuery(lessThan(Car.PRICE, 5000.0)), in(Car.MANUFACTURER, "Ford", "Honda"), and(lessThan(Car.PRICE, 5000.0), in(Car.MANUFACTURER, "Ford", "Honda")), lessThan(Car.PRICE, 5000.0), noQueryOptions() )); }
@Test public <O> void testSupportsQuery_Positive_RootAndFilterQueriesAreBothAndQueriesAndChildrenOfFilterQueryAreChildrenOfRootQuery() { assertTrue(supportsQueryInternal( backingIndexSupportsQuery(lessThan(Car.PRICE, 5000.0)), and(in(Car.MANUFACTURER, "Ford", "Honda"), equal(Car.COLOR, Car.Color.BLUE)), and(lessThan(Car.PRICE, 5000.0), in(Car.MANUFACTURER, "Ford", "Honda"), equal(Car.COLOR, Car.Color.BLUE)), lessThan(Car.PRICE, 5000.0), noQueryOptions() )); }
@Test public <O> void testSupportsQuery_Negative_BackingIndexDoesNotSupportQuery() { assertFalse(supportsQueryInternal( backingIndexSupportsQuery(in(Car.MODEL, "Focus", "Civic")), in(Car.MANUFACTURER, "Ford", "Honda"), in(Car.MANUFACTURER, "Ford", "Honda"), in(Car.MANUFACTURER, "Ford", "Honda"), noQueryOptions() )); }
@Test public <O> void testSupportsQuery_Negative_RootQueryDoesNotEqualFilterQueryAndRootQueryIsNotAnAndQuery() { assertFalse(supportsQueryInternal( backingIndexSupportsQuery(in(Car.MANUFACTURER, "Ford", "Honda")), or(in(Car.MANUFACTURER, "Ford", "Honda"), in(Car.MODEL, "Focus", "Civic")), in(Car.MANUFACTURER, "Ford", "Honda"), in(Car.MANUFACTURER, "Ford", "Honda"), noQueryOptions() )); }
@Test public <O> void testSupportsQuery_Negative_RootQueryDoesNotEqualFilterQueryAndFilterQueryIsNotAnAndQuery() { assertFalse(supportsQueryInternal( backingIndexSupportsQuery(lessThan(Car.PRICE, 5000.0)), or(in(Car.MANUFACTURER, "Ford", "Honda"), equal(Car.COLOR, Car.Color.BLUE)), and(lessThan(Car.PRICE, 5000.0), in(Car.MANUFACTURER, "Ford", "Honda"), equal(Car.COLOR, Car.Color.BLUE)), lessThan(Car.PRICE, 5000.0), noQueryOptions() )); }
@Test public <O> void testSupportsQuery_Negative_RootAndQueryDoesNotContainChildrenOfAndFilterQuery() { assertFalse(supportsQueryInternal( backingIndexSupportsQuery(lessThan(Car.PRICE, 5000.0)), and(in(Car.MANUFACTURER, "Ford", "Honda"), equal(Car.COLOR, Car.Color.BLUE)), and(lessThan(Car.PRICE, 5000.0), in(Car.MANUFACTURER, "Ford", "Honda"), equal(Car.COLOR, Car.Color.RED)), lessThan(Car.PRICE, 5000.0), noQueryOptions() )); }