task3/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 07 Oct 2008 11:05:34 +0200
changeset 45 251d0ed461fb
parent 41 task2/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java@a7e6f84fb078
child 58 07c16ec15a25
permissions -rw-r--r--
Copying all solution that advanced into round #3 into task3 directory
     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 }