task2/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 23 task1/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java@f4b4f95ae1bd
child 41 a7e6f84fb078
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
     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 String toString() {
    44         return getClass() + " based on " + (currency != null ? currency.toString() : "NO-BASE-CURRENCY");
    45     }
    46 }