jaroslav@66
|
1 |
package org.apidesign.apifest08.currency;
|
jaroslav@66
|
2 |
|
jaroslav@66
|
3 |
/**
|
jaroslav@66
|
4 |
* Static exchange rate provider.
|
jaroslav@66
|
5 |
*
|
jaroslav@66
|
6 |
* @author ked
|
jaroslav@66
|
7 |
*/
|
jaroslav@66
|
8 |
final class StaticExchangeRateProvider<AmountType, IdentifierType> implements ExchangeRateProvider<AmountType, IdentifierType> {
|
jaroslav@66
|
9 |
|
jaroslav@66
|
10 |
final ExchangeRateValue<AmountType, IdentifierType> exchangeRate;
|
jaroslav@66
|
11 |
|
jaroslav@66
|
12 |
private StaticExchangeRateProvider(ExchangeRateValue<AmountType, IdentifierType> exchangeRate) {
|
jaroslav@66
|
13 |
this.exchangeRate = exchangeRate;
|
jaroslav@66
|
14 |
}
|
jaroslav@66
|
15 |
|
jaroslav@66
|
16 |
public void getExchangeRate(ExchangeRateRequest<AmountType, IdentifierType> request, ExchangeRateResponse<AmountType, IdentifierType> response) {
|
jaroslav@66
|
17 |
response.setExchangeRate(exchangeRate);
|
jaroslav@66
|
18 |
}
|
jaroslav@66
|
19 |
|
jaroslav@66
|
20 |
static <AmountType, IdentifierType> StaticExchangeRateProvider<AmountType, IdentifierType> getStaticExchangeRateProvider(ExchangeRateValue<AmountType, IdentifierType> exchangeRate) {
|
jaroslav@66
|
21 |
return new StaticExchangeRateProvider<AmountType, IdentifierType>(exchangeRate);
|
jaroslav@66
|
22 |
}
|
jaroslav@66
|
23 |
|
jaroslav@66
|
24 |
@Override
|
jaroslav@66
|
25 |
public boolean equals(Object obj) {
|
jaroslav@66
|
26 |
if (obj == null) {
|
jaroslav@66
|
27 |
return false;
|
jaroslav@66
|
28 |
}
|
jaroslav@66
|
29 |
|
jaroslav@66
|
30 |
if (getClass() != obj.getClass()) {
|
jaroslav@66
|
31 |
return false;
|
jaroslav@66
|
32 |
}
|
jaroslav@66
|
33 |
|
jaroslav@66
|
34 |
final StaticExchangeRateProvider other = (StaticExchangeRateProvider) obj;
|
jaroslav@66
|
35 |
if (this.exchangeRate != other.exchangeRate && (this.exchangeRate == null || !this.exchangeRate.equals(other.exchangeRate))) {
|
jaroslav@66
|
36 |
return false;
|
jaroslav@66
|
37 |
}
|
jaroslav@66
|
38 |
|
jaroslav@66
|
39 |
return true;
|
jaroslav@66
|
40 |
}
|
jaroslav@66
|
41 |
|
jaroslav@66
|
42 |
@Override
|
jaroslav@66
|
43 |
public int hashCode() {
|
jaroslav@66
|
44 |
int hash = 7;
|
jaroslav@66
|
45 |
hash = 67 * hash + (this.exchangeRate != null ? this.exchangeRate.hashCode() : 0);
|
jaroslav@66
|
46 |
return hash;
|
jaroslav@66
|
47 |
}
|
jaroslav@66
|
48 |
}
|