}
@Override
public <T> List<T> execute(final Collection<T> collection,
final String query) throws ParsingException, FilterException {
AbstractExpression ex = getParser().parse(query);
// TODO allow all whitespaces in value!!!
final List<T> filtered = new ArrayList<>();
for (T obj : collection) {
if (ex.evaluate(obj)) {
filtered.add(obj);
// if the order is set we have to add all items before limiting
// the result
if (ex.getLimit() != -1 && ex.getOrder() == null
&& ex.getLimit() == filtered.size()) {
break;
}
}
}
if (ex.getOrder() != null) {
Collections.sort(filtered, ex.getOrder());
if (ex.getLimit() != -1) {
return filtered.subList(0, ex.getLimit());
}
}
return filtered;
}