task4/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
changeset 61 58ec6da75f6f
parent 58 07c16ec15a25
child 63 20d332739f60
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task4/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java	Sat Oct 11 23:38:46 2008 +0200
     1.3 @@ -0,0 +1,70 @@
     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 +    @Override
    1.58 +    public int hashCode() {
    1.59 +        return currency==null ? 47/*??*/ : currency.hashCode();
    1.60 +    }
    1.61 +    
    1.62 +    
    1.63 +    
    1.64 +
    1.65 +    @Override
    1.66 +    public String toString() {
    1.67 +        return  "ConvertorCurrency[" + (currency != null ? currency.toString() : "NO-BASE-CURRENCY")+"]";
    1.68 +    }
    1.69 +    
    1.70 +    String getCurrencyCode() {
    1.71 +        return currency.getCurrencyCode();
    1.72 +    }
    1.73 +}