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