task4/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java
changeset 63 20d332739f60
parent 61 58ec6da75f6f
     1.1 --- a/task4/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java	Sat Oct 11 23:38:46 2008 +0200
     1.2 +++ b/task4/solution13/src/org/apidesign/apifest08/currency/ConvertorCurrency.java	Fri Oct 17 17:31:48 2008 +0200
     1.3 @@ -12,22 +12,38 @@
     1.4   * @author arnostvalicek
     1.5   */
     1.6  public class ConvertorCurrency {
     1.7 +    private String currencyCode;
     1.8 +    private int fractionDigits;
     1.9  
    1.10 -    private Currency currency;
    1.11 -
    1.12 -    private void setJavaCurrency(Currency javaCurrency) {
    1.13 -        this.currency = javaCurrency;
    1.14 -    }
    1.15  
    1.16      /**
    1.17 -     * Static method providing instance of <code>ConvertorCurrency</code> base of currency code.
    1.18 +     * Static method providing instance of <code>ConvertorCurrency</code> based on currency code.
    1.19 +     * <p>
    1.20 +     * <code>currencyCode</code> is one of codes supported by Java class {@link java.util.Currency}.
    1.21       * 
    1.22       * @param currencyCode Code of required currency.
    1.23       * @return Returns required <code>ConvertorCurrency</code>
    1.24       */
    1.25      public static ConvertorCurrency getInstance(String currencyCode) {
    1.26          ConvertorCurrency convertorCurrency = new ConvertorCurrency();
    1.27 -        convertorCurrency.setJavaCurrency(Currency.getInstance(currencyCode));
    1.28 +        Currency currency = Currency.getInstance(currencyCode);
    1.29 +        convertorCurrency.setCurrencyCode(currency.getCurrencyCode());
    1.30 +        convertorCurrency.setDefaultFractionDigits(currency.getDefaultFractionDigits());
    1.31 +        return convertorCurrency;
    1.32 +    }
    1.33 +    
    1.34 +    /**
    1.35 +     * Static method providing instance of <code>ConvertorCurrency</code> base of currency code.
    1.36 +     * 
    1.37 +     * @param currencyCode Code of required currency.
    1.38 +     * @param fractionDigits Number of fraction digits for currency.
    1.39 +     * @return Returns required <code>ConvertorCurrency</code>
    1.40 +     * @since version4
    1.41 +     */
    1.42 +    public static ConvertorCurrency getInstance(String currencyCode, int fractionDigits) {
    1.43 +        ConvertorCurrency convertorCurrency = new ConvertorCurrency();
    1.44 +        convertorCurrency.setCurrencyCode(currencyCode);
    1.45 +        convertorCurrency.setDefaultFractionDigits(fractionDigits);
    1.46          return convertorCurrency;
    1.47      }
    1.48  
    1.49 @@ -36,7 +52,23 @@
    1.50       * @return Returns the default number of fraction digits used with this currency.
    1.51       */
    1.52      public int getDefaultFractionDigits() {
    1.53 -        return currency.getDefaultFractionDigits();
    1.54 +        return fractionDigits;
    1.55 +    }
    1.56 +    
    1.57 +    private void setDefaultFractionDigits(int value) {
    1.58 +        this.fractionDigits = value;
    1.59 +    }
    1.60 +    
    1.61 +    /**
    1.62 +     * Get currency code.
    1.63 +     * @return Returns currency code.
    1.64 +     */
    1.65 +    public String getCurrencyCode() {
    1.66 +        return currencyCode;
    1.67 +    }
    1.68 +    
    1.69 +    private void setCurrencyCode(String value) {
    1.70 +        currencyCode = value;
    1.71      }
    1.72  
    1.73      @Override
    1.74 @@ -44,7 +76,7 @@
    1.75          boolean result;
    1.76          if (obj instanceof ConvertorCurrency) {
    1.77              ConvertorCurrency that = (ConvertorCurrency) obj;
    1.78 -            result = currency.equals(that.currency);
    1.79 +            result = getCurrencyCode().equals(that.getCurrencyCode())  && getDefaultFractionDigits()==that.getDefaultFractionDigits();
    1.80          } else {
    1.81              result = false;
    1.82          }
    1.83 @@ -53,18 +85,13 @@
    1.84  
    1.85      @Override
    1.86      public int hashCode() {
    1.87 -        return currency==null ? 47/*??*/ : currency.hashCode();
    1.88 +        return currencyCode==null ? 47/*??*/ : currencyCode.hashCode();
    1.89      }
    1.90 -    
    1.91 -    
    1.92 -    
    1.93 +        
    1.94  
    1.95      @Override
    1.96      public String toString() {
    1.97 -        return  "ConvertorCurrency[" + (currency != null ? currency.toString() : "NO-BASE-CURRENCY")+"]";
    1.98 +        return  "ConvertorCurrency[" + (currencyCode != null ? currencyCode : "NO-BASE-CURRENCY")+"]";
    1.99      }
   1.100 -    
   1.101 -    String getCurrencyCode() {
   1.102 -        return currency.getCurrencyCode();
   1.103 -    }
   1.104 -}
   1.105 +   
   1.106 +}
   1.107 \ No newline at end of file