November 2024
Intermediate to advanced
300 pages
7h 12m
English
Let’s return to the fun and see how tight you can make the code.
First, replace the old-school loops with Java streams. Start with anyMatches:
| | private boolean anyMatches(Criteria criteria) { |
| | return criteria.stream() |
| | .anyMatch(criterion -> |
| | criterion.isMatch(profileAnswerMatching(criterion))); |
| | } |
To get that compiling and passing, you’ll need to add a stream method to the Criteria record:
| | public Stream<Criterion> stream() { |
| | return criteria.stream(); |
| | } |
Next, rework the calculateScore method:
| | private void calculateScore(Criteria criteria) ... |
Read now
Unlock full access