/** * Validation check that returns true only if the total beneficiary allocation adds up to 100%. */ @Transient 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; } }
/** * Add a single beneficiary with a 100% allocation percentage. * * @param beneficiaryName the name of the beneficiary (should be unique) */ public void addBeneficiary(String beneficiaryName) { addBeneficiary(beneficiaryName, Percentage.oneHundred()); }