Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use streams in group matcher #3696

Merged
merged 1 commit into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
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
19 changes: 4 additions & 15 deletions src/main/java/org/jabref/model/search/matchers/AndMatcher.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
19 changes: 4 additions & 15 deletions src/main/java/org/jabref/model/search/matchers/OrMatcher.java
Original file line number Diff line number Diff line change
@@ -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));
}
}