task3/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
changeset 45 251d0ed461fb
parent 41 a7e6f84fb078
child 58 07c16ec15a25
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task3/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java	Tue Oct 07 11:05:34 2008 +0200
     1.3 @@ -0,0 +1,63 @@
     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 boolean equals(Object obj) {
    1.47 +        boolean result;
    1.48 +        if (obj instanceof ConvertorCurrency) {
    1.49 +            ConvertorCurrency that = (ConvertorCurrency) obj;
    1.50 +            result = currency.equals(that.currency);
    1.51 +        } else {
    1.52 +            result = false;
    1.53 +        }
    1.54 +        return result;
    1.55 +    }
    1.56 +    
    1.57 +
    1.58 +    @Override
    1.59 +    public String toString() {
    1.60 +        return  "ConvertorCurrency[" + (currency != null ? currency.toString() : "NO-BASE-CURRENCY")+"]";
    1.61 +    }
    1.62 +    
    1.63 +    String getCurrencyCode() {
    1.64 +        return currency.getCurrencyCode();
    1.65 +    }
    1.66 +}