task2/solution01/src/org/apidesign/apifest08/currency/AbstractCurrencyConvertor.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 6 task1/solution01/src/org/apidesign/apifest08/currency/AbstractCurrencyConvertor.java@97662396c0fd
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
     1 package org.apidesign.apifest08.currency;
     2 
     3 import java.util.Currency;
     4 
     5 /**
     6  * Abstract convertor implementation.
     7  * This class provide necessary stuff for creating any CurrencyConvertor
     8  * Convert value can be get by different way. Conversion should be made in its subclass.
     9  * @author Ladislav Vitasek
    10  */
    11 abstract class AbstractCurrencyConvertor implements Convertor {
    12     protected final ConversionRatioProvider conversionRatioProvider;
    13     protected final Currency currency1;
    14     protected final Currency currency2;
    15 
    16     public AbstractCurrencyConvertor(Currency currency1, Currency currency2, ConversionRatioProvider conversionRatioProvider) {
    17         this.currency1 = currency1;
    18         this.currency2 = currency2;
    19         this.conversionRatioProvider = conversionRatioProvider;
    20     }
    21 
    22     
    23     public Currency getCurrency1() {
    24         return currency1;
    25     }
    26 
    27 
    28     public Currency getCurrency2() {
    29         return currency2;
    30     }
    31 
    32 //    /**
    33 //     * Conversion value can be get by Different way. Let's decide subclass where to get actual value
    34 //     * @return current value of conversion constant
    35 //     */
    36 //    protected abstract BigDecimal getConversionValue();
    37 
    38     @SuppressWarnings({"RedundantIfStatement"})
    39     public boolean equals(Object o) {
    40         if (this == o) return true;
    41         if (o == null || getClass() != o.getClass()) return false;
    42 
    43         AbstractCurrencyConvertor that = (AbstractCurrencyConvertor) o;
    44 
    45         if (!conversionRatioProvider.equals(that.conversionRatioProvider)) return false;
    46         if (!currency1.equals(that.currency1)) return false;
    47         if (!currency2.equals(that.currency2)) return false;
    48 
    49         return true;
    50     }
    51 
    52     public int hashCode() {
    53         int result;
    54         result = conversionRatioProvider.hashCode();
    55         result = 31 * result + currency1.hashCode();
    56         result = 31 * result + currency2.hashCode();
    57         return result;
    58     }
    59 
    60     ConversionRatioProvider getConversionRatioProvider() {
    61         return conversionRatioProvider;
    62     }    
    63 
    64 }