use of com.google.gerrit.index.query.RangeUtil.Range in project gerrit by GerritCodeReview.
the class LabelPredicate method predicates.
protected static List<Predicate<ChangeData>> predicates(Args args) {
String v = args.value;
List<Integer> counts = getCounts(args.count, args.countOp);
try {
MagicLabelVote mlv = MagicLabelVote.parseWithEquals(v);
List<Predicate<ChangeData>> result = Lists.newArrayListWithCapacity(counts.size());
if (counts.isEmpty()) {
result.add(magicLabelPredicate(args, mlv, /* count= */
null));
} else {
counts.forEach(count -> result.add(magicLabelPredicate(args, mlv, count)));
}
return result;
} catch (IllegalArgumentException e) {
// Try next format.
}
Parsed parsed = null;
try {
LabelVote lv = LabelVote.parse(v);
parsed = new Parsed(lv.label(), "=", lv.value());
} catch (IllegalArgumentException e) {
// Try next format.
}
try {
LabelVote lv = LabelVote.parseWithEquals(v);
parsed = new Parsed(lv.label(), "=", lv.value());
} catch (IllegalArgumentException e) {
// Try next format.
}
Range range;
if (parsed == null) {
range = RangeUtil.getRange(v, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
if (range == null) {
range = new Range(v, 1, 1);
}
} else {
range = RangeUtil.getRange(parsed.label, parsed.test, parsed.numericValue, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
}
String prefix = range.prefix;
int min = range.min;
int max = range.max;
List<Predicate<ChangeData>> r = Lists.newArrayListWithCapacity((counts.isEmpty() ? 1 : counts.size()) * (max - min + 1));
for (int i = min; i <= max; i++) {
if (counts.isEmpty()) {
r.add(onePredicate(args, prefix, i, /* count= */
null));
} else {
for (int count : counts) {
r.add(onePredicate(args, prefix, i, count));
}
}
}
return r;
}
use of com.google.gerrit.index.query.RangeUtil.Range in project gerrit by GerritCodeReview.
the class RangeUtilTest method getRangeForValueOutsideOfMinMaxRange_minNotGreaterThanMax.
@Test
public void getRangeForValueOutsideOfMinMaxRange_minNotGreaterThanMax() {
for (String operator : ImmutableList.of("=", ">", ">=", "<", "<=")) {
Range range = RangeUtil.getRange("foo", operator, 10, -4, 4);
assertThat(range.min).isAtMost(range.max);
range = RangeUtil.getRange("foo", operator, -10, -4, 4);
assertThat(range.min).isAtMost(range.max);
}
}
Aggregations