author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Tue, 07 Oct 2008 11:05:34 +0200 | |
changeset 45 | 251d0ed461fb |
parent 41 | task2/solution13/src/org/apidesign/apifest08/currency/ExchangeRate.java@a7e6f84fb078 |
permissions | -rw-r--r-- |
japod@23 | 1 |
|
japod@23 | 2 |
package org.apidesign.apifest08.currency; |
japod@23 | 3 |
|
japod@23 | 4 |
import java.math.BigDecimal; |
japod@23 | 5 |
|
japod@23 | 6 |
/** |
japod@23 | 7 |
* Exchange rate value. Contains <code>from</code> and <code>to</code> value. |
japod@23 | 8 |
* |
japod@23 | 9 |
* @author arnostvalicek |
japod@23 | 10 |
*/ |
japod@23 | 11 |
public class ExchangeRate { |
japod@23 | 12 |
private BigDecimal numberFor; |
japod@23 | 13 |
private BigDecimal numberGet; |
japod@23 | 14 |
|
japod@41 | 15 |
/** |
japod@41 | 16 |
* Constructor for new exchange rate holding two values - <em>from value</em> and <em>to value</em> |
japod@41 | 17 |
* @param fromValue Exchange rate <em>from value</em> |
japod@41 | 18 |
* @param toValue Exchange rate <em>to value</em> |
japod@41 | 19 |
*/ |
japod@23 | 20 |
public ExchangeRate(BigDecimal fromValue, BigDecimal toValue) { |
japod@23 | 21 |
this.numberFor = fromValue; |
japod@23 | 22 |
this.numberGet = toValue; |
japod@23 | 23 |
} |
japod@41 | 24 |
|
japod@41 | 25 |
/** |
japod@41 | 26 |
* Create new instance of <code>ExchangeRate</code> based on provided exchange rate, but swapping its |
japod@41 | 27 |
* <em>from</em> and <em>to</em> value. |
japod@41 | 28 |
* <p> |
japod@41 | 29 |
* Provided exchange rate is not chaged, this method returns different instance describing reverted exchange rate. |
japod@41 | 30 |
* |
japod@41 | 31 |
* @param rate Exchange rate which describes rate to be reverted. |
japod@41 | 32 |
* @return Instance of reverted rate. |
japod@41 | 33 |
*/ |
japod@41 | 34 |
public static ExchangeRate createRevertedRate(ExchangeRate rate) { |
japod@41 | 35 |
ExchangeRate reverted = new ExchangeRate(rate.getToValue(), rate.getFromValue()); |
japod@41 | 36 |
return reverted; |
japod@41 | 37 |
} |
japod@23 | 38 |
|
japod@23 | 39 |
@Override |
japod@23 | 40 |
public String toString() { |
japod@23 | 41 |
return "for "+numberFor+" recieve "+numberGet+" @"+getClass().getName(); |
japod@23 | 42 |
} |
japod@23 | 43 |
|
japod@41 | 44 |
/** |
japod@41 | 45 |
* Return exchange rate <em>from</em> value stored in this object. |
japod@41 | 46 |
* @return Returns <em>from</em> value for this exchange rate. |
japod@41 | 47 |
*/ |
japod@23 | 48 |
public BigDecimal getFromValue() { |
japod@23 | 49 |
return numberFor; |
japod@23 | 50 |
} |
japod@23 | 51 |
|
japod@41 | 52 |
/** |
japod@41 | 53 |
* Return exchange rate <em>to</em> value stored in this object. |
japod@41 | 54 |
* @return Returns <em>to</em> value for this exchange rate. |
japod@41 | 55 |
*/ |
japod@23 | 56 |
public BigDecimal getToValue() { |
japod@23 | 57 |
return numberGet; |
japod@23 | 58 |
} |
japod@23 | 59 |
|
japod@23 | 60 |
|
japod@23 | 61 |
// public ExchangeRate createExchangeRate(BigDecimal forValue, BigDecimal getValue) { |
japod@23 | 62 |
// ExchangeRate rate = new ExchangeRate(forValue, getValue); |
japod@23 | 63 |
// return rate; |
japod@23 | 64 |
// } |
japod@23 | 65 |
|
japod@23 | 66 |
|
japod@23 | 67 |
|
japod@23 | 68 |
} |