public class MonetarySummary {
private final SumOfMoney spending, earnings, net;
public static MonetarySummary summarize(Collection<Money> amounts, Currency currency) {
int spendingCount = 0, earningsCount = 0;
Money spendingSum = Money.zero(currency), earningsSum = Money.zero(currency);
for (Money amount : amounts) {
if (amount.signum() > 0) {
earningsCount++;
earningsSum = earningsSum.add(amount);
} else if (amount.signum() < 0) {
spendingCount++;
spendingSum = spendingSum.add(amount.abs());
}
}
return new MonetarySummary(
new SumOfMoney(spendingSum, spendingCount),