task4/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Oct 2008 23:38:46 +0200
changeset 61 58ec6da75f6f
parent 58 task3/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java@07c16ec15a25
child 63 20d332739f60
permissions -rw-r--r--
Copying structure for task4
     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 }