task2/solution01/src/org/apidesign/apifest08/currency/AbstractCurrencyConvertor.java
changeset 29 f6073056b9fe
parent 6 97662396c0fd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task2/solution01/src/org/apidesign/apifest08/currency/AbstractCurrencyConvertor.java	Wed Oct 01 10:43:05 2008 +0200
     1.3 @@ -0,0 +1,64 @@
     1.4 +package org.apidesign.apifest08.currency;
     1.5 +
     1.6 +import java.util.Currency;
     1.7 +
     1.8 +/**
     1.9 + * Abstract convertor implementation.
    1.10 + * This class provide necessary stuff for creating any CurrencyConvertor
    1.11 + * Convert value can be get by different way. Conversion should be made in its subclass.
    1.12 + * @author Ladislav Vitasek
    1.13 + */
    1.14 +abstract class AbstractCurrencyConvertor implements Convertor {
    1.15 +    protected final ConversionRatioProvider conversionRatioProvider;
    1.16 +    protected final Currency currency1;
    1.17 +    protected final Currency currency2;
    1.18 +
    1.19 +    public AbstractCurrencyConvertor(Currency currency1, Currency currency2, ConversionRatioProvider conversionRatioProvider) {
    1.20 +        this.currency1 = currency1;
    1.21 +        this.currency2 = currency2;
    1.22 +        this.conversionRatioProvider = conversionRatioProvider;
    1.23 +    }
    1.24 +
    1.25 +    
    1.26 +    public Currency getCurrency1() {
    1.27 +        return currency1;
    1.28 +    }
    1.29 +
    1.30 +
    1.31 +    public Currency getCurrency2() {
    1.32 +        return currency2;
    1.33 +    }
    1.34 +
    1.35 +//    /**
    1.36 +//     * Conversion value can be get by Different way. Let's decide subclass where to get actual value
    1.37 +//     * @return current value of conversion constant
    1.38 +//     */
    1.39 +//    protected abstract BigDecimal getConversionValue();
    1.40 +
    1.41 +    @SuppressWarnings({"RedundantIfStatement"})
    1.42 +    public boolean equals(Object o) {
    1.43 +        if (this == o) return true;
    1.44 +        if (o == null || getClass() != o.getClass()) return false;
    1.45 +
    1.46 +        AbstractCurrencyConvertor that = (AbstractCurrencyConvertor) o;
    1.47 +
    1.48 +        if (!conversionRatioProvider.equals(that.conversionRatioProvider)) return false;
    1.49 +        if (!currency1.equals(that.currency1)) return false;
    1.50 +        if (!currency2.equals(that.currency2)) return false;
    1.51 +
    1.52 +        return true;
    1.53 +    }
    1.54 +
    1.55 +    public int hashCode() {
    1.56 +        int result;
    1.57 +        result = conversionRatioProvider.hashCode();
    1.58 +        result = 31 * result + currency1.hashCode();
    1.59 +        result = 31 * result + currency2.hashCode();
    1.60 +        return result;
    1.61 +    }
    1.62 +
    1.63 +    ConversionRatioProvider getConversionRatioProvider() {
    1.64 +        return conversionRatioProvider;
    1.65 +    }    
    1.66 +
    1.67 +}