2 package org.apidesign.apifest08.currency;
4 public final class CurrencyRateImpl implements CurrencyRate, TimeLimitedCurrencyRate {
5 private String currency1;
6 private String currency2;
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.");
15 if ("".equals(currency1) || "".equals(currency2)) {
16 throw new IllegalArgumentException("Name of currency cannot be empty string");
18 if (currency1.equals(currency2)) {
19 throw new IllegalArgumentException("Currencies in rate cannot be the same");
22 this.currency1 = currency1;
23 this.currency2 = currency2;
25 this.fromTime = Long.MIN_VALUE;
26 this.toTime = Long.MAX_VALUE;
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.");
33 if ("".equals(currency1) || "".equals(currency2)) {
34 throw new IllegalArgumentException("Name of currency cannot be empty string");
36 if (currency1.equals(currency2)) {
37 throw new IllegalArgumentException("Currencies in rate cannot be the same");
39 if (fromTime > toTime) {
40 throw new IllegalArgumentException("Invalid time range");
43 this.currency1 = currency1;
44 this.currency2 = currency2;
46 this.fromTime = fromTime;
50 public String getCurrency1() {
54 public String getCurrency2() {
58 public Rate getRate(){
62 public long getFromTime() {
66 public long getToTime() {