task4/solution11/src/org/apidesign/apifest08/currency/StaticExchangeRateProvider.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task4/solution11/src/org/apidesign/apifest08/currency/StaticExchangeRateProvider.java Fri Oct 17 17:34:40 2008 +0200
1.3 @@ -0,0 +1,48 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +/**
1.7 + * Static exchange rate provider.
1.8 + *
1.9 + * @author ked
1.10 + */
1.11 +final class StaticExchangeRateProvider<AmountType, IdentifierType> implements ExchangeRateProvider<AmountType, IdentifierType> {
1.12 +
1.13 + final ExchangeRateValue<AmountType, IdentifierType> exchangeRate;
1.14 +
1.15 + private StaticExchangeRateProvider(ExchangeRateValue<AmountType, IdentifierType> exchangeRate) {
1.16 + this.exchangeRate = exchangeRate;
1.17 + }
1.18 +
1.19 + public void getExchangeRate(ExchangeRateRequest<AmountType, IdentifierType> request, ExchangeRateResponse<AmountType, IdentifierType> response) {
1.20 + response.setExchangeRate(exchangeRate);
1.21 + }
1.22 +
1.23 + static <AmountType, IdentifierType> StaticExchangeRateProvider<AmountType, IdentifierType> getStaticExchangeRateProvider(ExchangeRateValue<AmountType, IdentifierType> exchangeRate) {
1.24 + return new StaticExchangeRateProvider<AmountType, IdentifierType>(exchangeRate);
1.25 + }
1.26 +
1.27 + @Override
1.28 + public boolean equals(Object obj) {
1.29 + if (obj == null) {
1.30 + return false;
1.31 + }
1.32 +
1.33 + if (getClass() != obj.getClass()) {
1.34 + return false;
1.35 + }
1.36 +
1.37 + final StaticExchangeRateProvider other = (StaticExchangeRateProvider) obj;
1.38 + if (this.exchangeRate != other.exchangeRate && (this.exchangeRate == null || !this.exchangeRate.equals(other.exchangeRate))) {
1.39 + return false;
1.40 + }
1.41 +
1.42 + return true;
1.43 + }
1.44 +
1.45 + @Override
1.46 + public int hashCode() {
1.47 + int hash = 7;
1.48 + hash = 67 * hash + (this.exchangeRate != null ? this.exchangeRate.hashCode() : 0);
1.49 + return hash;
1.50 + }
1.51 +}