1 package org.apidesign.apifest08.currency;
4 import java.math.BigDecimal;
5 import java.util.Currency;
9 * The exchange rate between two currencies.
11 * @author D'Arcy Smith
14 public final class ExchangeRate
19 private final Currency currencyA;
24 private final Currency currencyB;
29 private final BigDecimal rateAtoB;
34 private final BigDecimal rateBtoA;
37 * Construct an ExchangeRate with the specified values.
39 * @param a the first currency
40 * @param b the second currency
41 * @param ra the rate to convert a to b
42 * @param rb the rate to covertt b to a
43 * @throws IllegalArgumentException if any parameter is null.
45 public ExchangeRate(final Currency a,
52 throw new IllegalArgumentException("a cannot be null");
57 throw new IllegalArgumentException("b cannot be null");
62 throw new IllegalArgumentException("ra cannot be null");
67 throw new IllegalArgumentException("rb cannot be null");
70 if(ra.compareTo(BigDecimal.ZERO) <= 0)
72 throw new IllegalArgumentException("ra cannot be <= 0, was: " + ra);
75 if(rb.compareTo(BigDecimal.ZERO) <= 0)
77 throw new IllegalArgumentException("rb cannot be <= 0, was: " + ra);
87 * Get the first currency.
89 * @return the first currency.
91 public Currency getCurrencyA()
97 * Get the second currency.
99 * @return the second currency.
101 public Currency getCurrencyB()
107 * Get the conversion rate from currencyA to currencyB.
109 * @return the conversion rate from currencyA to currencyB.
111 public BigDecimal getRateAtoB()
117 * Get the conversion rate from currencyB to currencyA.
119 * @return the conversion rate from currencyB to currencyA.
121 public BigDecimal getRateBtoA()