task2/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
changeset 29 f6073056b9fe
parent 23 f4b4f95ae1bd
child 41 a7e6f84fb078
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task2/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java	Wed Oct 01 10:43:05 2008 +0200
     1.3 @@ -0,0 +1,46 @@
     1.4 +
     1.5 +package org.apidesign.apifest08.currency;
     1.6 +
     1.7 +import java.util.Currency;
     1.8 +
     1.9 +/**
    1.10 + * Desription of currency. 
    1.11 + * 
    1.12 + * Java has similar class {@link java.util.Currency}, but original class is not flexible
    1.13 + * enough, we use our own implementation of currency.
    1.14 + *
    1.15 + * @author arnostvalicek
    1.16 + */
    1.17 +public class ConvertorCurrency {
    1.18 +
    1.19 +    private Currency currency;
    1.20 +
    1.21 +    private void setJavaCurrency(Currency javaCurrency) {
    1.22 +        this.currency = javaCurrency;
    1.23 +    }
    1.24 +
    1.25 +    /**
    1.26 +     * Static method providing instance of <code>ConvertorCurrency</code> base of currency code.
    1.27 +     * 
    1.28 +     * @param currencyCode Code of required currency.
    1.29 +     * @return Returns required <code>ConvertorCurrency</code>
    1.30 +     */
    1.31 +    public static ConvertorCurrency getInstance(String currencyCode) {
    1.32 +        ConvertorCurrency convertorCurrency = new ConvertorCurrency();
    1.33 +        convertorCurrency.setJavaCurrency(Currency.getInstance(currencyCode));
    1.34 +        return convertorCurrency;
    1.35 +    }
    1.36 +
    1.37 +    /**
    1.38 +     * Gets the default number of fraction digits used with this currency. For example, the default number of fraction digits for the Euro is 2, while for the Japanese Yen it's 0.
    1.39 +     * @return Returns the default number of fraction digits used with this currency.
    1.40 +     */
    1.41 +    public int getDefaultFractionDigits() {
    1.42 +        return currency.getDefaultFractionDigits();
    1.43 +    }
    1.44 +
    1.45 +    @Override
    1.46 +    public String toString() {
    1.47 +        return getClass() + " based on " + (currency != null ? currency.toString() : "NO-BASE-CURRENCY");
    1.48 +    }
    1.49 +}