task4/solution14/src/org/apidesign/apifest08/currency/CurrencyRateImpl.java
changeset 67 bf7622ec1713
parent 61 58ec6da75f6f
     1.1 --- a/task4/solution14/src/org/apidesign/apifest08/currency/CurrencyRateImpl.java	Sat Oct 11 23:38:46 2008 +0200
     1.2 +++ b/task4/solution14/src/org/apidesign/apifest08/currency/CurrencyRateImpl.java	Fri Oct 17 17:35:52 2008 +0200
     1.3 @@ -1,10 +1,12 @@
     1.4  
     1.5  package org.apidesign.apifest08.currency;
     1.6  
     1.7 -public final class CurrencyRateImpl implements CurrencyRate {
     1.8 +public final class CurrencyRateImpl implements CurrencyRate, TimeLimitedCurrencyRate {
     1.9      private String currency1;
    1.10      private String currency2;
    1.11      private Rate rate;
    1.12 +    private long fromTime;
    1.13 +    private long toTime;
    1.14      
    1.15      CurrencyRateImpl(final String currency1, final String currency2, final Rate rate) {
    1.16          if ((currency1 == null)||(currency2 == null) || (rate == null)) {
    1.17 @@ -20,6 +22,29 @@
    1.18          this.currency1 = currency1;
    1.19          this.currency2 = currency2;
    1.20          this.rate = rate;
    1.21 +        this.fromTime = Long.MIN_VALUE;
    1.22 +        this.toTime = Long.MAX_VALUE;
    1.23 +    }
    1.24 +
    1.25 +    CurrencyRateImpl(final String currency1, final String currency2, final Rate rate, final long fromTime, final long toTime) {
    1.26 +        if ((currency1 == null)||(currency2 == null) || (rate == null)) {
    1.27 +            throw new IllegalArgumentException("Argument cannot be null.");
    1.28 +        }
    1.29 +        if ("".equals(currency1) || "".equals(currency2)) {
    1.30 +            throw new IllegalArgumentException("Name of currency cannot be empty string");
    1.31 +        }
    1.32 +        if (currency1.equals(currency2)) {
    1.33 +            throw new IllegalArgumentException("Currencies in rate cannot be the same");
    1.34 +        }
    1.35 +        if (fromTime > toTime) {
    1.36 +            throw new IllegalArgumentException("Invalid time range");
    1.37 +        }
    1.38 +
    1.39 +        this.currency1 = currency1;
    1.40 +        this.currency2 = currency2;
    1.41 +        this.rate = rate;
    1.42 +        this.fromTime = fromTime;
    1.43 +        this.toTime = toTime;
    1.44      }
    1.45  
    1.46      public String getCurrency1() {
    1.47 @@ -34,4 +59,12 @@
    1.48          return rate;
    1.49      }
    1.50  
    1.51 +    public long getFromTime() {
    1.52 +        return fromTime;
    1.53 +    }
    1.54 +
    1.55 +    public long getToTime() {
    1.56 +        return toTime;
    1.57 +    }
    1.58 +
    1.59  }