diff -r 14e78f48ac2b -r 58ec6da75f6f task4/solution04/src/org/apidesign/apifest08/currency/ExchangeRate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/task4/solution04/src/org/apidesign/apifest08/currency/ExchangeRate.java Sat Oct 11 23:38:46 2008 +0200 @@ -0,0 +1,125 @@ +package org.apidesign.apifest08.currency; + + +import java.math.BigDecimal; +import java.util.Currency; + + +/** + * The exchange rate between two currencies. + * + * @author D'Arcy Smith + * @version 1.0 + */ +public final class ExchangeRate +{ + /** + * + */ + private final Currency currencyA; + + /** + * + */ + private final Currency currencyB; + + /** + * + */ + private final BigDecimal rateAtoB; + + /** + * + */ + private final BigDecimal rateBtoA; + + /** + * Construct an ExchangeRate with the specified values. + * + * @param a the first currency + * @param b the second currency + * @param ra the rate to convert a to b + * @param rb the rate to covertt b to a + * @throws IllegalArgumentException if any parameter is null. + */ + public ExchangeRate(final Currency a, + final Currency b, + final BigDecimal ra, + final BigDecimal rb) + { + if(a == null) + { + throw new IllegalArgumentException("a cannot be null"); + } + + if(b == null) + { + throw new IllegalArgumentException("b cannot be null"); + } + + if(ra == null) + { + throw new IllegalArgumentException("ra cannot be null"); + } + + if(rb == null) + { + throw new IllegalArgumentException("rb cannot be null"); + } + + if(ra.compareTo(BigDecimal.ZERO) <= 0) + { + throw new IllegalArgumentException("ra cannot be <= 0, was: " + ra); + } + + if(rb.compareTo(BigDecimal.ZERO) <= 0) + { + throw new IllegalArgumentException("rb cannot be <= 0, was: " + ra); + } + + currencyA = a; + currencyB = b; + rateAtoB = ra; + rateBtoA = rb; + } + + /** + * Get the first currency. + * + * @return the first currency. + */ + public Currency getCurrencyA() + { + return currencyA; + } + + /** + * Get the second currency. + * + * @return the second currency. + */ + public Currency getCurrencyB() + { + return currencyB; + } + + /** + * Get the conversion rate from currencyA to currencyB. + * + * @return the conversion rate from currencyA to currencyB. + */ + public BigDecimal getRateAtoB() + { + return rateAtoB; + } + + /** + * Get the conversion rate from currencyB to currencyA. + * + * @return the conversion rate from currencyB to currencyA. + */ + public BigDecimal getRateBtoA() + { + return rateBtoA; + } +}