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