Skip to content

Commit 72ebe23

Browse files
committed
Fixed inefficient Stream API call chains ending with count()
Signed-off-by: Dmitry Kryukov <[email protected]>
1 parent 9e5604b commit 72ebe23

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

modules/percolator/src/main/java/org/opensearch/percolator/QueryAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ static Result selectBestResult(Result result1, Result result2) {
512512
private static int minTermLength(Set<QueryExtraction> extractions) {
513513
// In case there are only range extractions, then we return Integer.MIN_VALUE,
514514
// so that selectBestExtraction(...) we are likely to prefer the extractions that contains at least a single extraction
515-
if (extractions.stream().filter(queryExtraction -> queryExtraction.term != null).count() == 0
516-
&& extractions.stream().filter(queryExtraction -> queryExtraction.range != null).count() > 0) {
515+
if (extractions.stream().noneMatch(queryExtraction -> queryExtraction.term != null)
516+
&& extractions.stream().anyMatch(queryExtraction -> queryExtraction.range != null)) {
517517
return Integer.MIN_VALUE;
518518
}
519519

0 commit comments

Comments
 (0)