1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task2/solution13/src/org/apidesign/apifest08/currency/ExchangeRateProvider.java Wed Oct 01 10:43:05 2008 +0200
1.3 @@ -0,0 +1,62 @@
1.4 +
1.5 +package org.apidesign.apifest08.currency;
1.6 +
1.7 +import java.math.BigDecimal;
1.8 +import java.util.Date;
1.9 +
1.10 +/**
1.11 + * Exchange rate provider - can provide fixed exchange rate which does not depend
1.12 + * on date (method {@link #getExchangeRate()} ) or exchange rate based on date (method {@link #getExchangeRate(java.util.Date) }).
1.13 + *
1.14 + *
1.15 + * @author arnostvalicek
1.16 + */
1.17 +public class ExchangeRateProvider {
1.18 + BigDecimal fromValue, toValue;
1.19 + ConvertorCurrency fromCurrency, toCurrency;
1.20 +
1.21 + /**
1.22 + * Simple constructor for <code>ExchangeRateProviderM</code> which can provide fixed exchange rate.
1.23 + *
1.24 + * Describes conversion <em>from</em> to <em>to</em> currency.
1.25 + *
1.26 + * @param fromValue From value. BigDecimal value, precision should be set to currency precision.
1.27 + * @param fromCurrency From currency.
1.28 + * @param toValue To value. BigDecimal value, precision should be set to currency precision.
1.29 + * @param toCurrency To currency.
1.30 + */
1.31 + public ExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) {
1.32 + this.fromValue = fromValue;
1.33 + this.toValue = toValue;
1.34 + this.fromCurrency = fromCurrency;
1.35 + this.toCurrency = toCurrency;
1.36 + }
1.37 +
1.38 + /**
1.39 + * Get fixed exange rate for currencies (from->to).
1.40 + * @return Returns exchange rate.
1.41 + */
1.42 + public ExchangeRate getExchangeRate() {
1.43 + return new ExchangeRate(fromValue, toValue);
1.44 + }
1.45 +
1.46 + /**
1.47 + * Get exchange rate for currencies (from->to) based on provided date.
1.48 + * @param date Date for which exchange rate should be provided.
1.49 + * @return Returns exchange rate
1.50 + */
1.51 + public ExchangeRate getExchangeRate(Date date) {
1.52 + return new ExchangeRate(fromValue, toValue);
1.53 + }
1.54 +
1.55 +
1.56 + ConvertorCurrency getFromCurrency() {
1.57 + return fromCurrency;
1.58 + }
1.59 +
1.60 + ConvertorCurrency getToCurrency() {
1.61 + return toCurrency;
1.62 + }
1.63 +
1.64 +
1.65 +}