japod@55: package org.apidesign.apifest08.currency; japod@55: japod@55: japod@55: import java.math.BigDecimal; japod@55: import java.util.Currency; japod@55: japod@55: japod@55: /** japod@55: * The exchange rate between two currencies. japod@55: * japod@55: * @author D'Arcy Smith japod@55: * @version 1.0 japod@55: */ japod@55: public final class ExchangeRate japod@55: { japod@55: /** japod@55: * japod@55: */ japod@55: private final Currency currencyA; japod@55: japod@55: /** japod@55: * japod@55: */ japod@55: private final Currency currencyB; japod@55: japod@55: /** japod@55: * japod@55: */ japod@55: private final BigDecimal rateAtoB; japod@55: japod@55: /** japod@55: * japod@55: */ japod@55: private final BigDecimal rateBtoA; japod@55: japod@55: /** japod@55: * Construct an ExchangeRate with the specified values. japod@55: * japod@55: * @param a the first currency japod@55: * @param b the second currency japod@55: * @param ra the rate to convert a to b japod@55: * @param rb the rate to covertt b to a japod@55: * @throws IllegalArgumentException if any parameter is null. japod@55: */ japod@55: public ExchangeRate(final Currency a, japod@55: final Currency b, japod@55: final BigDecimal ra, japod@55: final BigDecimal rb) japod@55: { japod@55: if(a == null) japod@55: { japod@55: throw new IllegalArgumentException("a cannot be null"); japod@55: } japod@55: japod@55: if(b == null) japod@55: { japod@55: throw new IllegalArgumentException("b cannot be null"); japod@55: } japod@55: japod@55: if(ra == null) japod@55: { japod@55: throw new IllegalArgumentException("ra cannot be null"); japod@55: } japod@55: japod@55: if(rb == null) japod@55: { japod@55: throw new IllegalArgumentException("rb cannot be null"); japod@55: } japod@55: japod@55: if(ra.compareTo(BigDecimal.ZERO) <= 0) japod@55: { japod@55: throw new IllegalArgumentException("ra cannot be <= 0, was: " + ra); japod@55: } japod@55: japod@55: if(rb.compareTo(BigDecimal.ZERO) <= 0) japod@55: { japod@55: throw new IllegalArgumentException("rb cannot be <= 0, was: " + ra); japod@55: } japod@55: japod@55: currencyA = a; japod@55: currencyB = b; japod@55: rateAtoB = ra; japod@55: rateBtoA = rb; japod@55: } japod@55: japod@55: /** japod@55: * Get the first currency. japod@55: * japod@55: * @return the first currency. japod@55: */ japod@55: public Currency getCurrencyA() japod@55: { japod@55: return currencyA; japod@55: } japod@55: japod@55: /** japod@55: * Get the second currency. japod@55: * japod@55: * @return the second currency. japod@55: */ japod@55: public Currency getCurrencyB() japod@55: { japod@55: return currencyB; japod@55: } japod@55: japod@55: /** japod@55: * Get the conversion rate from currencyA to currencyB. japod@55: * japod@55: * @return the conversion rate from currencyA to currencyB. japod@55: */ japod@55: public BigDecimal getRateAtoB() japod@55: { japod@55: return rateAtoB; japod@55: } japod@55: japod@55: /** japod@55: * Get the conversion rate from currencyB to currencyA. japod@55: * japod@55: * @return the conversion rate from currencyB to currencyA. japod@55: */ japod@55: public BigDecimal getRateBtoA() japod@55: { japod@55: return rateBtoA; japod@55: } japod@55: }