@Test public void testAdd() { assertEquals(new BigDecimal("2"), UNDER_TEST_ONE.add(UNDER_TEST_ONE).getAmount()); assertEquals(UNDER_TEST_ONE, UNDER_TEST_ONE.add(Money.NOTHING)); assertEquals(UNDER_TEST_ONE, Money.NOTHING.add(UNDER_TEST_ONE)); }
public Money add(Money augend) { if (isZero(this)) { return augend; } if (isZero(augend)) { return this; } if (currency != augend.getCurrency()) { throw new IllegalArgumentException("Only money of the same currency can be added."); } return new Money(amount.add(augend.getAmount()), currency); }
Money { public Money add(Money augend) { if (isZero(this)) { return augend; } if (isZero(augend)) { return this; } if (currency != augend.getCurrency()) { throw new IllegalArgumentException("Only money of the same currency can be added."); } return new Money(amount.add(augend.getAmount()), currency); } }
Money { public Money add(Money augend) { if (isZero(this)) { return augend; } if (isZero(augend)) { return this; } if (currency != augend.getCurrency()) { throw new IllegalArgumentException("Only money of the same currency can be added."); } return new Money(amount.add(augend.getAmount()), currency); } private  Money(BigDecimal amount, Currency currency); }
Money { public Money add(Money augend) { if (isZero(this)) { return augend; } if (isZero(augend)) { return this; } if (currency != augend.getCurrency()) { throw new IllegalArgumentException("Only money of the same currency can be added."); } return new Money(amount.add(augend.getAmount()), currency); } private  Money(BigDecimal amount, Currency currency); static Money valueOf(MoneyPO money); static Money valueOf(String amount); static Money valueOf(String amount, Currency currency); static Money valueOf(BigDecimal amount, String currency); static Money valueOf(BigDecimal amount, Currency currency); static Money valueOf(String amount, String currencyCode); boolean isZero(); Money add(Money augend); Money divide(BigDecimal divisor); Money divide(BigDecimal divisor, int additionalScale); Money divide(long divisor); @Override boolean equals(Object obj); BigDecimal getAmount(); Currency getCurrency(); Money round(RoundingMode mode); Money round(); Money stripTrailingZeros(); @Override int hashCode(); Money multiply(BigDecimal multiplicand); Money negate(); Money subtract(Money subtrahend); MoneyPO toMoneyPO(); @Override String toString(); }
Money { public Money add(Money augend) { if (isZero(this)) { return augend; } if (isZero(augend)) { return this; } if (currency != augend.getCurrency()) { throw new IllegalArgumentException("Only money of the same currency can be added."); } return new Money(amount.add(augend.getAmount()), currency); } private  Money(BigDecimal amount, Currency currency); static Money valueOf(MoneyPO money); static Money valueOf(String amount); static Money valueOf(String amount, Currency currency); static Money valueOf(BigDecimal amount, String currency); static Money valueOf(BigDecimal amount, Currency currency); static Money valueOf(String amount, String currencyCode); boolean isZero(); Money add(Money augend); Money divide(BigDecimal divisor); Money divide(BigDecimal divisor, int additionalScale); Money divide(long divisor); @Override boolean equals(Object obj); BigDecimal getAmount(); Currency getCurrency(); Money round(RoundingMode mode); Money round(); Money stripTrailingZeros(); @Override int hashCode(); Money multiply(BigDecimal multiplicand); Money negate(); Money subtract(Money subtrahend); MoneyPO toMoneyPO(); @Override String toString(); static final Money NOTHING; static final Money ONE_USD; }