Beispiel #1
0
 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.");
   }
 }
Beispiel #2
0
 public int hashCode() {
   if (fHashCode == 0) {
     fHashCode = HASH_SEED;
     fHashCode = HASH_FACTOR * fHashCode + fAmount.hashCode();
     fHashCode = HASH_FACTOR * fHashCode + fCurrency.hashCode();
   }
   return fHashCode;
 }
Beispiel #3
0
 public Money minus(Money aThat) {
   checkCurrenciesMatch(aThat);
   return new Money(fAmount.subtract(aThat.fAmount), fCurrency);
 }
Beispiel #4
0
 public Money plus(Money aThat) {
   checkCurrenciesMatch(aThat);
   return new Money(fAmount.add(aThat.fAmount), fCurrency);
 }
Beispiel #5
0
 public String toString() {
   return fAmount.toPlainString() + " " + fCurrency.getSymbol();
 }