task1/solution01/src/org/apidesign/apifest08/currency/AbstractCurrencyConvertor.java
1 package org.apidesign.apifest08.currency;
3 import java.util.Currency;
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
11 abstract class AbstractCurrencyConvertor implements Convertor {
12 protected final ConversionRatioProvider conversionRatioProvider;
13 protected final Currency currency1;
14 protected final Currency currency2;
16 public AbstractCurrencyConvertor(Currency currency1, Currency currency2, ConversionRatioProvider conversionRatioProvider) {
17 this.currency1 = currency1;
18 this.currency2 = currency2;
19 this.conversionRatioProvider = conversionRatioProvider;
23 public Currency getCurrency1() {
28 public Currency getCurrency2() {
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
36 // protected abstract BigDecimal getConversionValue();
38 @SuppressWarnings({"RedundantIfStatement"})
39 public boolean equals(Object o) {
40 if (this == o) return true;
41 if (o == null || getClass() != o.getClass()) return false;
43 AbstractCurrencyConvertor that = (AbstractCurrencyConvertor) o;
45 if (!conversionRatioProvider.equals(that.conversionRatioProvider)) return false;
46 if (!currency1.equals(that.currency1)) return false;
47 if (!currency2.equals(that.currency2)) return false;
52 public int hashCode() {
54 result = conversionRatioProvider.hashCode();
55 result = 31 * result + currency1.hashCode();
56 result = 31 * result + currency2.hashCode();
60 ConversionRatioProvider getConversionRatioProvider() {
61 return conversionRatioProvider;