task2/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
author japod@localhost
Tue, 07 Oct 2008 01:18:23 +0200
changeset 41 a7e6f84fb078
parent 29 f6073056b9fe
permissions -rw-r--r--
adding solution13 for task2
     1 
     2 package org.apidesign.apifest08.currency;
     3 
     4 import java.util.Currency;
     5 
     6 /**
     7  * Desription of currency. 
     8  * 
     9  * Java has similar class {@link java.util.Currency}, but original class is not flexible
    10  * enough, we use our own implementation of currency.
    11  *
    12  * @author arnostvalicek
    13  */
    14 public class ConvertorCurrency {
    15 
    16     private Currency currency;
    17 
    18     private void setJavaCurrency(Currency javaCurrency) {
    19         this.currency = javaCurrency;
    20     }
    21 
    22     /**
    23      * Static method providing instance of <code>ConvertorCurrency</code> base of currency code.
    24      * 
    25      * @param currencyCode Code of required currency.
    26      * @return Returns required <code>ConvertorCurrency</code>
    27      */
    28     public static ConvertorCurrency getInstance(String currencyCode) {
    29         ConvertorCurrency convertorCurrency = new ConvertorCurrency();
    30         convertorCurrency.setJavaCurrency(Currency.getInstance(currencyCode));
    31         return convertorCurrency;
    32     }
    33 
    34     /**
    35      * 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.
    36      * @return Returns the default number of fraction digits used with this currency.
    37      */
    38     public int getDefaultFractionDigits() {
    39         return currency.getDefaultFractionDigits();
    40     }
    41 
    42     @Override
    43     public boolean equals(Object obj) {
    44         boolean result;
    45         if (obj instanceof ConvertorCurrency) {
    46             ConvertorCurrency that = (ConvertorCurrency) obj;
    47             result = currency.equals(that.currency);
    48         } else {
    49             result = false;
    50         }
    51         return result;
    52     }
    53     
    54 
    55     @Override
    56     public String toString() {
    57         return  "ConvertorCurrency[" + (currency != null ? currency.toString() : "NO-BASE-CURRENCY")+"]";
    58     }
    59     
    60     String getCurrencyCode() {
    61         return currency.getCurrencyCode();
    62     }
    63 }