Skip to content
Permalink
Browse files

Step 9: Filterer

  • Loading branch information...
tlinkowski committed Jan 31, 2019
1 parent cf4e4d4 commit b3c81daf4b5d2481a7cc8cc9f198bdf8efec04ad
Showing with 10 additions and 10 deletions.
  1. +6 −0 Filterer.java
  2. +1 −2 IssueWiseText.java
  3. +1 −6 ProbabilisticIssueWiseText.java
  4. +2 −2 Usage.java
@@ -0,0 +1,6 @@
import java.util.function.Predicate;

@FunctionalInterface
interface Filterer<T, I> {
T by(Predicate<? super I> predicate);
}
@@ -1,10 +1,9 @@
import java.util.List;
import java.util.function.Predicate;

interface IssueWiseText {
String text(); // e.g. "You migth know it."

List<? extends Issue> issues(); // e.g. ["migth"]

IssueWiseText filtered(Predicate<? super Issue> issueFilter);
Filterer<? extends IssueWiseText, ? extends Issue> filtered();
}
@@ -1,14 +1,9 @@
import java.util.List;
import java.util.function.Predicate;

interface ProbabilisticIssueWiseText extends IssueWiseText {
@Override
List<? extends ProbableIssue> issues();

@Override
default ProbabilisticIssueWiseText filtered(Predicate<? super Issue> issueFilter) {
return filteredProbabilistic(issueFilter);
}

ProbabilisticIssueWiseText filteredProbabilistic(Predicate<? super ProbableIssue> issueFilter);
Filterer<? extends ProbabilisticIssueWiseText, ? extends ProbableIssue> filtered();
}
@@ -7,13 +7,13 @@ static double issueCoverage(Stream<? extends IssueWiseText> textStream) {

static double issueCoverage(Stream<? extends IssueWiseText> textStream, IssueType issueType) {
return textStream
.map(text -> text.filtered(issue -> issue.type() == issueType))
.map(text -> text.filtered().by(issue -> issue.type() == issueType))
.collect(IssueCoverage.collector());
}

static double issueCoverage(Stream<? extends ProbabilisticIssueWiseText> textStream, double minProbability) {
return textStream
.map(text -> text.filteredProbabilistic(issue -> issue.probability() >= minProbability))
.map(text -> text.filtered().by(issue -> issue.probability() >= minProbability))
.collect(IssueCoverage.collector());
}

0 comments on commit b3c81da

Please sign in to comment.
You can’t perform that action at this time.