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 live online training, plus books, videos, and digital content from nearly 200 publishers.