/** Return the sum of <code>money</code> */ public static Money sum(List<Money> money) { Money total = Money.dollars(0.00); for (Iterator<Money> i = money.iterator(); i.hasNext(); ) { total = total.plus(i.next()); } return total; }
public static Money sum(Collection<Money> monies) { // TODO Return Default Currency if (monies.isEmpty()) { return Money.dollars(0.00); } Iterator<Money> iterator = monies.iterator(); Money sum = iterator.next(); while (iterator.hasNext()) { Money each = iterator.next(); sum = sum.plus(each); } return sum; }
public static Money zeroIfNull(Money money) { return money == null ? Money.dollars(0.00) : money; }