private void validateState() { if (fAmount == null) { throw new IllegalArgumentException("Amount cannot be null"); } if (fCurrency == null) { throw new IllegalArgumentException("Currency cannot be null"); } if (fAmount.scale() > getNumDecimalsForCurrency()) { throw new IllegalArgumentException( "Number of decimals is " + fAmount.scale() + ", but currency only takes " + getNumDecimalsForCurrency() + " decimals."); } }
public int hashCode() { if (fHashCode == 0) { fHashCode = HASH_SEED; fHashCode = HASH_FACTOR * fHashCode + fAmount.hashCode(); fHashCode = HASH_FACTOR * fHashCode + fCurrency.hashCode(); } return fHashCode; }
public Money minus(Money aThat) { checkCurrenciesMatch(aThat); return new Money(fAmount.subtract(aThat.fAmount), fCurrency); }
public Money plus(Money aThat) { checkCurrenciesMatch(aThat); return new Money(fAmount.add(aThat.fAmount), fCurrency); }
public String toString() { return fAmount.toPlainString() + " " + fCurrency.getSymbol(); }