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