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