class 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;
        }

        // Check: rootQuery equals filterQuery
        if (filterQuery.equals(rootQuery)) {
            return true;
        }

        if (!(rootQuery instanceof And)) {
            return false;
        }
        // Check: rootQuery (r) is an And query, which has filterQuery (f) as any one of its direct children:
        // r = and(x, y, f, z)
        And<O> rootAndQuery = (And<O>)rootQuery;
        if (rootAndQuery.getChildQueries().contains(filterQuery)) {
            return true;
        }

        // Check: rootQuery (r) is an And query and filterQuery (f) is an And query,
        // and the direct children of f are also the direct children of r:
        // f = and(a, b), r = and(x, a, y, b)
        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);

}