use of org.apache.ivy.util.filter.OrFilter in project ant-ivy by apache.
the class IvyEventFilter method parseExpression.
private Filter<IvyEvent> parseExpression(String filterExpression) {
// expressions handled for the moment: (informal grammar)
// EXP := SIMPLE_EXP | AND_EXP | OR_EXP | NOT_EXP
// AND_EXP := EXP && EXP
// OR_EXP := EXP || EXP
// NOT_EXP := ! EXP
// SIMPLE_EXP := attname = comma, separated, list, of, accepted, values
// example: organisation = foo && module = bar, baz
filterExpression = filterExpression.trim();
int index = filterExpression.indexOf(AND);
if (index == -1) {
index = filterExpression.indexOf(OR);
if (index == -1) {
if (filterExpression.startsWith(NOT)) {
return new NotFilter<>(parseExpression(filterExpression.substring(NOT.length())));
} else {
index = filterExpression.indexOf("=");
if (index == -1) {
throw new IllegalArgumentException("bad filter expression: " + filterExpression + ": no equal sign found");
}
final String attname = filterExpression.substring(0, index).trim();
final List<Matcher> matchers = new ArrayList<>();
for (String value : splitToArray(filterExpression.substring(index + 1))) {
matchers.add(matcher.getMatcher(value));
}
return new Filter<IvyEvent>() {
public boolean accept(IvyEvent e) {
String val = e.getAttributes().get(attname);
if (val == null) {
return false;
}
for (Matcher matcher : matchers) {
if (matcher.matches(val)) {
return true;
}
}
return false;
}
};
}
} else {
return new OrFilter<>(parseExpression(filterExpression.substring(0, index)), parseExpression(filterExpression.substring(index + OR.length())));
}
} else {
return new AndFilter<>(parseExpression(filterExpression.substring(0, index)), parseExpression(filterExpression.substring(index + AND.length())));
}
}
Aggregations