task3/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
author japod@localhost
Fri, 10 Oct 2008 22:24:52 +0200
changeset 58 07c16ec15a25
parent 45 251d0ed461fb
permissions -rw-r--r--
solution13 task3
     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     @Override
    55     public int hashCode() {
    56         return currency==null ? 47/*??*/ : currency.hashCode();
    57     }
    58     
    59     
    60     
    61 
    62     @Override
    63     public String toString() {
    64         return  "ConvertorCurrency[" + (currency != null ? currency.toString() : "NO-BASE-CURRENCY")+"]";
    65     }
    66     
    67     String getCurrencyCode() {
    68         return currency.getCurrencyCode();
    69     }
    70 }