From 8616e29955aa55880a9d8341f76e9feb757b9e02 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 5 Feb 2018 23:57:34 +0100 Subject: [PATCH] Use stream in matcher --- .../model/search/matchers/AndMatcher.java | 19 ++++--------------- .../model/search/matchers/OrMatcher.java | 19 ++++--------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/jabref/model/search/matchers/AndMatcher.java b/src/main/java/org/jabref/model/search/matchers/AndMatcher.java index c39b3c36ffc..81839607ad0 100644 --- a/src/main/java/org/jabref/model/search/matchers/AndMatcher.java +++ b/src/main/java/org/jabref/model/search/matchers/AndMatcher.java @@ -1,26 +1,15 @@ package org.jabref.model.search.matchers; import org.jabref.model.entry.BibEntry; -import org.jabref.model.search.SearchMatcher; /** - * Subclass of MatcherSet that ANDs or ORs between its rules, returning 0 or - * 1. + * A set of matchers that returns true if all matcher match the given entry. */ public class AndMatcher extends MatcherSet { @Override - public boolean isMatch(BibEntry bibEntry) { - int score = 0; - - // We let each rule add a maximum of 1 to the score. - for (SearchMatcher rule : matchers) { - if (rule.isMatch(bibEntry)) { - score++; - } - } - - // Then an AND rule demands that score == number of rules - return score == matchers.size(); + public boolean isMatch(BibEntry entry) { + return matchers.stream() + .allMatch(rule -> rule.isMatch(entry)); } } diff --git a/src/main/java/org/jabref/model/search/matchers/OrMatcher.java b/src/main/java/org/jabref/model/search/matchers/OrMatcher.java index ffd2ebf1e28..c0a0eddf1d9 100644 --- a/src/main/java/org/jabref/model/search/matchers/OrMatcher.java +++ b/src/main/java/org/jabref/model/search/matchers/OrMatcher.java @@ -1,26 +1,15 @@ package org.jabref.model.search.matchers; import org.jabref.model.entry.BibEntry; -import org.jabref.model.search.SearchMatcher; /** - * Subclass of MatcherSet that ANDs or ORs between its rules, returning 0 or - * 1. + * A set of matchers that returns true if any matcher matches the given entry. */ public class OrMatcher extends MatcherSet { @Override - public boolean isMatch(BibEntry bibEntry) { - int score = 0; - - // We let each rule add a maximum of 1 to the score. - for (SearchMatcher rule : matchers) { - if (rule.isMatch(bibEntry)) { - score++; - } - } - - // OR rule demands score > 0. - return score > 0; + public boolean isMatch(BibEntry entry) { + return matchers.stream() + .anyMatch(rule -> rule.isMatch(entry)); } }