-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24ed12a
commit bd3ef32
Showing
2 changed files
with
8 additions
and
30 deletions.
There are no files selected for viewing
19 changes: 4 additions & 15 deletions
19
src/main/java/org/jabref/model/search/matchers/AndMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
src/main/java/org/jabref/model/search/matchers/OrMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |