task4/solution14/src/org/apidesign/apifest08/currency/CurrencyRateImpl.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 17 Oct 2008 17:35:52 +0200
changeset 67 bf7622ec1713
parent 61 58ec6da75f6f
permissions -rw-r--r--
Solution 14, task4
     1 
     2 package org.apidesign.apifest08.currency;
     3 
     4 public final class CurrencyRateImpl implements CurrencyRate, TimeLimitedCurrencyRate {
     5     private String currency1;
     6     private String currency2;
     7     private Rate rate;
     8     private long fromTime;
     9     private long toTime;
    10     
    11     CurrencyRateImpl(final String currency1, final String currency2, final Rate rate) {
    12         if ((currency1 == null)||(currency2 == null) || (rate == null)) {
    13             throw new IllegalArgumentException("Argument cannot be null.");
    14         }
    15         if ("".equals(currency1) || "".equals(currency2)) {
    16             throw new IllegalArgumentException("Name of currency cannot be empty string");
    17         }
    18         if (currency1.equals(currency2)) {
    19             throw new IllegalArgumentException("Currencies in rate cannot be the same");
    20         }
    21        
    22         this.currency1 = currency1;
    23         this.currency2 = currency2;
    24         this.rate = rate;
    25         this.fromTime = Long.MIN_VALUE;
    26         this.toTime = Long.MAX_VALUE;
    27     }
    28 
    29     CurrencyRateImpl(final String currency1, final String currency2, final Rate rate, final long fromTime, final long toTime) {
    30         if ((currency1 == null)||(currency2 == null) || (rate == null)) {
    31             throw new IllegalArgumentException("Argument cannot be null.");
    32         }
    33         if ("".equals(currency1) || "".equals(currency2)) {
    34             throw new IllegalArgumentException("Name of currency cannot be empty string");
    35         }
    36         if (currency1.equals(currency2)) {
    37             throw new IllegalArgumentException("Currencies in rate cannot be the same");
    38         }
    39         if (fromTime > toTime) {
    40             throw new IllegalArgumentException("Invalid time range");
    41         }
    42 
    43         this.currency1 = currency1;
    44         this.currency2 = currency2;
    45         this.rate = rate;
    46         this.fromTime = fromTime;
    47         this.toTime = toTime;
    48     }
    49 
    50     public String getCurrency1() {
    51         return currency1;
    52     }
    53             
    54     public String getCurrency2() {
    55         return currency2;
    56     }
    57 
    58     public Rate getRate(){
    59         return rate;
    60     }
    61 
    62     public long getFromTime() {
    63         return fromTime;
    64     }
    65 
    66     public long getToTime() {
    67         return toTime;
    68     }
    69 
    70 }