Taking Refactoring Too Far?

Similarly, extract the code that calculates the total weighting of all matches:

iloveyouboss/22/src/iloveyouboss/Profile.java
 
public​ ​boolean​ matches(Criteria criteria) {
*
calculateScore(criteria);
 
 
boolean​ kill = false;
 
for​ (Criterion criterion: criteria) {
 
boolean​ match = criterion.matches(answerMatching(criterion));
 
if​ (!match && criterion.getWeight() == Weight.MustMatch) {
 
kill = true;
 
}
 
}
 
if​ (kill)
 
return​ false;
 
return​ anyMatches(criteria);
 
}
 
*
private​ ​void​ calculateScore(Criteria criteria) {
*
score = 0;
*
for​ (Criterion criterion: criteria)
*
if​ (criterion.matches(answerMatching(criterion)))
*
score += criterion.getWeight().getValue();
*
}

Double hmm. You might be wondering ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.