/**
* Validation check that returns true only if the total beneficiary allocation adds up to 100%.
*/
//TODO 8: Add annotation indicating that there is an attribute to persist.
public boolean isValid() {
Percentage totalPercentage = Percentage.zero();
for (Beneficiary b : beneficiaries) {
try {
totalPercentage = totalPercentage.add(b.getAllocationPercentage());
} catch (IllegalArgumentException e) {
// total would have been over 100% - return invalid
return false;
}
}
if (totalPercentage.equals(Percentage.oneHundred())) {
return true;
} else {
return false;
}
}