Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static io.github.perplexhub.rsql.RSQLOperators.*;

import cz.jirutka.rsql.parser.ast.LogicalNode;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -417,14 +419,24 @@ private Predicate equalPredicate(Expression expr, Class type, Object argument) {
@Override
public Predicate visit(AndNode node, From root) {
log.debug("visit(node:{},root:{})", node, root);

return node.getChildren().stream().map(n -> n.accept(this, root)).collect(Collectors.reducing(builder::and)).get();
return visitChildren(node, root, builder::and);
}

@Override
public Predicate visit(OrNode node, From root) {
log.debug("visit(node:{},root:{})", node, root);
return visitChildren(node, root, builder::or);
}

private Predicate visitChildren(LogicalNode node, From root, BiFunction<Predicate, Predicate, Predicate> reducer) {
Predicate result = null;

for (var child : node) {
result = result != null
? reducer.apply(result, child.accept(this, root))
: child.accept(this, root);
}

return node.getChildren().stream().map(n -> n.accept(this, root)).collect(Collectors.reducing(builder::or)).get();
return result;
}
}
Loading