Search in sources :

Example 1 with AndPredicate

use of com.google.gerrit.index.query.AndPredicate in project gerrit by GerritCodeReview.

the class ChangeIndexRewriter method extractStatus.

private static EnumSet<Change.Status> extractStatus(Predicate<ChangeData> in) {
    if (in instanceof ChangeStatusPredicate) {
        Status status = ((ChangeStatusPredicate) in).getStatus();
        return status != null ? EnumSet.of(status) : null;
    } else if (in instanceof NotPredicate) {
        EnumSet<Status> s = extractStatus(in.getChild(0));
        return s != null ? EnumSet.complementOf(s) : null;
    } else if (in instanceof OrPredicate) {
        EnumSet<Change.Status> r = null;
        int childrenWithStatus = 0;
        for (int i = 0; i < in.getChildCount(); i++) {
            EnumSet<Status> c = extractStatus(in.getChild(i));
            if (c != null) {
                if (r == null) {
                    r = EnumSet.noneOf(Change.Status.class);
                }
                r.addAll(c);
                childrenWithStatus++;
            }
        }
        if (r != null && childrenWithStatus < in.getChildCount()) {
            // the child was used at the root of a query.
            return EnumSet.allOf(Change.Status.class);
        }
        return r;
    } else if (in instanceof AndPredicate) {
        EnumSet<Change.Status> r = null;
        for (int i = 0; i < in.getChildCount(); i++) {
            EnumSet<Change.Status> c = extractStatus(in.getChild(i));
            if (c != null) {
                if (r == null) {
                    r = EnumSet.allOf(Change.Status.class);
                }
                r.retainAll(c);
            }
        }
        return r;
    }
    return null;
}
Also used : Status(com.google.gerrit.entities.Change.Status) OrPredicate(com.google.gerrit.index.query.OrPredicate) EnumSet(java.util.EnumSet) ChangeStatusPredicate(com.google.gerrit.server.query.change.ChangeStatusPredicate) AndPredicate(com.google.gerrit.index.query.AndPredicate) Change(com.google.gerrit.entities.Change) NotPredicate(com.google.gerrit.index.query.NotPredicate)

Aggregations

Change (com.google.gerrit.entities.Change)1 Status (com.google.gerrit.entities.Change.Status)1 AndPredicate (com.google.gerrit.index.query.AndPredicate)1 NotPredicate (com.google.gerrit.index.query.NotPredicate)1 OrPredicate (com.google.gerrit.index.query.OrPredicate)1 ChangeStatusPredicate (com.google.gerrit.server.query.change.ChangeStatusPredicate)1 EnumSet (java.util.EnumSet)1