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