task2/solution13/src/org/apidesign/apifest08/currency/ExchangeRateProvider.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 23 task1/solution13/src/org/apidesign/apifest08/currency/ExchangeRateProvider.java@f4b4f95ae1bd
child 41 a7e6f84fb078
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
     1 
     2 package org.apidesign.apifest08.currency;
     3 
     4 import java.math.BigDecimal;
     5 import java.util.Date;
     6 
     7 /**
     8  * Exchange rate provider - can provide fixed exchange rate which does not depend
     9  * on date (method {@link #getExchangeRate()} ) or exchange rate based on date (method {@link #getExchangeRate(java.util.Date) }).
    10  * 
    11  * 
    12  * @author arnostvalicek
    13  */
    14 public class ExchangeRateProvider {
    15     BigDecimal fromValue, toValue;
    16     ConvertorCurrency fromCurrency, toCurrency;
    17 
    18     /**
    19      * Simple constructor for <code>ExchangeRateProviderM</code> which can provide fixed exchange rate.
    20      * 
    21      * Describes conversion <em>from</em> to <em>to</em> currency.
    22      * 
    23      * @param fromValue From value. BigDecimal value, precision should be set to currency precision.
    24      * @param fromCurrency From currency.
    25      * @param toValue To value. BigDecimal value, precision should be set to currency precision.
    26      * @param toCurrency To currency.
    27      */
    28     public ExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) {
    29         this.fromValue = fromValue;
    30         this.toValue = toValue;
    31         this.fromCurrency = fromCurrency;
    32         this.toCurrency = toCurrency;
    33     }
    34     
    35     /**
    36      * Get fixed exange rate for currencies (from->to).
    37      * @return Returns exchange rate.
    38      */
    39     public ExchangeRate getExchangeRate() {
    40         return new ExchangeRate(fromValue, toValue);
    41     }
    42     
    43     /**
    44      * Get exchange rate for currencies (from->to) based on provided date.
    45      * @param date Date for which exchange rate should be provided.
    46      * @return Returns exchange rate 
    47      */
    48     public ExchangeRate getExchangeRate(Date date) {
    49         return new ExchangeRate(fromValue, toValue);
    50     }
    51     
    52 
    53     ConvertorCurrency getFromCurrency() {
    54         return fromCurrency;
    55     }
    56     
    57     ConvertorCurrency getToCurrency() {
    58         return toCurrency;
    59     }
    60     
    61 
    62 }