Compare instance of predicates, not exact class
We want the same behavior for any instance of the boolean predicates, not just for the exact boolean classes. Change-Id: I2d1168c7a69e03db4b8dda3ddf60275a603c3e27
This commit is contained in:
committed by
Dave Borowitz
parent
ec4418b3e8
commit
e12cf645de
@@ -54,11 +54,11 @@ public class QueryBuilder {
|
|||||||
|
|
||||||
public static Query toQuery(Predicate<ChangeData> p)
|
public static Query toQuery(Predicate<ChangeData> p)
|
||||||
throws QueryParseException {
|
throws QueryParseException {
|
||||||
if (p.getClass() == AndPredicate.class) {
|
if (p instanceof AndPredicate) {
|
||||||
return booleanQuery(p, MUST);
|
return booleanQuery(p, MUST);
|
||||||
} else if (p.getClass() == OrPredicate.class) {
|
} else if (p instanceof OrPredicate) {
|
||||||
return booleanQuery(p, SHOULD);
|
return booleanQuery(p, SHOULD);
|
||||||
} else if (p.getClass() == NotPredicate.class) {
|
} else if (p instanceof NotPredicate) {
|
||||||
if (p.getChild(0) instanceof TimestampRangePredicate) {
|
if (p.getChild(0) instanceof TimestampRangePredicate) {
|
||||||
return notTimestampQuery(
|
return notTimestampQuery(
|
||||||
(TimestampRangePredicate<ChangeData>) p.getChild(0));
|
(TimestampRangePredicate<ChangeData>) p.getChild(0));
|
||||||
|
|||||||
@@ -159,17 +159,17 @@ public abstract class QueryRewriter<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Predicate<T> replaceGenericNodes(final Predicate<T> in) {
|
protected Predicate<T> replaceGenericNodes(final Predicate<T> in) {
|
||||||
if (in.getClass() == NotPredicate.class) {
|
if (in instanceof NotPredicate) {
|
||||||
return not(replaceGenericNodes(in.getChild(0)));
|
return not(replaceGenericNodes(in.getChild(0)));
|
||||||
|
|
||||||
} else if (in.getClass() == AndPredicate.class) {
|
} else if (in instanceof AndPredicate) {
|
||||||
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
||||||
for (Predicate<T> c : in.getChildren()) {
|
for (Predicate<T> c : in.getChildren()) {
|
||||||
n.add(replaceGenericNodes(c));
|
n.add(replaceGenericNodes(c));
|
||||||
}
|
}
|
||||||
return and(n);
|
return and(n);
|
||||||
|
|
||||||
} else if (in.getClass() == OrPredicate.class) {
|
} else if (in instanceof OrPredicate) {
|
||||||
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
List<Predicate<T>> n = new ArrayList<Predicate<T>>(in.getChildCount());
|
||||||
for (Predicate<T> c : in.getChildren()) {
|
for (Predicate<T> c : in.getChildren()) {
|
||||||
n.add(replaceGenericNodes(c));
|
n.add(replaceGenericNodes(c));
|
||||||
|
|||||||
@@ -65,15 +65,15 @@ public class IndexRewriteImpl implements IndexRewrite {
|
|||||||
public static EnumSet<Change.Status> getPossibleStatus(Predicate<ChangeData> in) {
|
public static EnumSet<Change.Status> getPossibleStatus(Predicate<ChangeData> in) {
|
||||||
if (in instanceof ChangeStatusPredicate) {
|
if (in instanceof ChangeStatusPredicate) {
|
||||||
return EnumSet.of(((ChangeStatusPredicate) in).getStatus());
|
return EnumSet.of(((ChangeStatusPredicate) in).getStatus());
|
||||||
} else if (in.getClass() == NotPredicate.class) {
|
} else if (in instanceof NotPredicate) {
|
||||||
return EnumSet.complementOf(getPossibleStatus(in.getChild(0)));
|
return EnumSet.complementOf(getPossibleStatus(in.getChild(0)));
|
||||||
} else if (in.getClass() == OrPredicate.class) {
|
} else if (in instanceof OrPredicate) {
|
||||||
EnumSet<Change.Status> s = EnumSet.noneOf(Change.Status.class);
|
EnumSet<Change.Status> s = EnumSet.noneOf(Change.Status.class);
|
||||||
for (int i = 0; i < in.getChildCount(); i++) {
|
for (int i = 0; i < in.getChildCount(); i++) {
|
||||||
s.addAll(getPossibleStatus(in.getChild(i)));
|
s.addAll(getPossibleStatus(in.getChild(i)));
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
} else if (in.getClass() == AndPredicate.class) {
|
} else if (in instanceof AndPredicate) {
|
||||||
EnumSet<Change.Status> s = EnumSet.allOf(Change.Status.class);
|
EnumSet<Change.Status> s = EnumSet.allOf(Change.Status.class);
|
||||||
for (int i = 0; i < in.getChildCount(); i++) {
|
for (int i = 0; i < in.getChildCount(); i++) {
|
||||||
s.retainAll(getPossibleStatus(in.getChild(i)));
|
s.retainAll(getPossibleStatus(in.getChild(i)));
|
||||||
@@ -120,7 +120,7 @@ public class IndexRewriteImpl implements IndexRewrite {
|
|||||||
if (in instanceof IndexPredicate) {
|
if (in instanceof IndexPredicate) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
if (!isRewritePossible(in)) {
|
if (!isBoolean(in)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int n = in.getChildCount();
|
int n = in.getChildCount();
|
||||||
@@ -194,9 +194,7 @@ public class IndexRewriteImpl implements IndexRewrite {
|
|||||||
if (p instanceof IndexPredicate) {
|
if (p instanceof IndexPredicate) {
|
||||||
return !((IndexPredicate<ChangeData>) p).isIndexOnly();
|
return !((IndexPredicate<ChangeData>) p).isIndexOnly();
|
||||||
}
|
}
|
||||||
if (p instanceof AndPredicate
|
if (isBoolean(p)) {
|
||||||
|| p instanceof OrPredicate
|
|
||||||
|| p instanceof NotPredicate) {
|
|
||||||
for (int i = 0; i < p.getChildCount(); i++) {
|
for (int i = 0; i < p.getChildCount(); i++) {
|
||||||
if (!allNonIndexOnly(p.getChild(i))) {
|
if (!allNonIndexOnly(p.getChild(i))) {
|
||||||
return false;
|
return false;
|
||||||
@@ -217,12 +215,8 @@ public class IndexRewriteImpl implements IndexRewrite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRewritePossible(Predicate<ChangeData> p) {
|
private static boolean isBoolean(Predicate<ChangeData> p) {
|
||||||
if (p.getClass() != AndPredicate.class
|
return p instanceof AndPredicate || p instanceof OrPredicate
|
||||||
&& p.getClass() != OrPredicate.class
|
|| p instanceof NotPredicate;
|
||||||
&& p.getClass() != NotPredicate.class) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return p.getChildCount() > 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user