1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task4/solution13/src/org/apidesign/apifest08/currency/ExchangeRate.java Sat Oct 11 23:38:46 2008 +0200
1.3 @@ -0,0 +1,68 @@
1.4 +
1.5 +package org.apidesign.apifest08.currency;
1.6 +
1.7 +import java.math.BigDecimal;
1.8 +
1.9 +/**
1.10 + * Exchange rate value. Contains <code>from</code> and <code>to</code> value.
1.11 + *
1.12 + * @author arnostvalicek
1.13 + */
1.14 +public class ExchangeRate {
1.15 + private BigDecimal numberFor;
1.16 + private BigDecimal numberGet;
1.17 +
1.18 + /**
1.19 + * Constructor for new exchange rate holding two values - <em>from value</em> and <em>to value</em>
1.20 + * @param fromValue Exchange rate <em>from value</em>
1.21 + * @param toValue Exchange rate <em>to value</em>
1.22 + */
1.23 + public ExchangeRate(BigDecimal fromValue, BigDecimal toValue) {
1.24 + this.numberFor = fromValue;
1.25 + this.numberGet = toValue;
1.26 + }
1.27 +
1.28 + /**
1.29 + * Create new instance of <code>ExchangeRate</code> based on provided exchange rate, but swapping its
1.30 + * <em>from</em> and <em>to</em> value.
1.31 + * <p>
1.32 + * Provided exchange rate is not chaged, this method returns different instance describing reverted exchange rate.
1.33 + *
1.34 + * @param rate Exchange rate which describes rate to be reverted.
1.35 + * @return Instance of reverted rate.
1.36 + */
1.37 + public static ExchangeRate createRevertedRate(ExchangeRate rate) {
1.38 + ExchangeRate reverted = new ExchangeRate(rate.getToValue(), rate.getFromValue());
1.39 + return reverted;
1.40 + }
1.41 +
1.42 + @Override
1.43 + public String toString() {
1.44 + return "for "+numberFor+" recieve "+numberGet+" @"+getClass().getName();
1.45 + }
1.46 +
1.47 + /**
1.48 + * Return exchange rate <em>from</em> value stored in this object.
1.49 + * @return Returns <em>from</em> value for this exchange rate.
1.50 + */
1.51 + public BigDecimal getFromValue() {
1.52 + return numberFor;
1.53 + }
1.54 +
1.55 + /**
1.56 + * Return exchange rate <em>to</em> value stored in this object.
1.57 + * @return Returns <em>to</em> value for this exchange rate.
1.58 + */
1.59 + public BigDecimal getToValue() {
1.60 + return numberGet;
1.61 + }
1.62 +
1.63 +
1.64 +// public ExchangeRate createExchangeRate(BigDecimal forValue, BigDecimal getValue) {
1.65 +// ExchangeRate rate = new ExchangeRate(forValue, getValue);
1.66 +// return rate;
1.67 +// }
1.68 +
1.69 +
1.70 +
1.71 +}