task4/solution04/src/org/apidesign/apifest08/currency/Convertor.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Oct 2008 23:38:46 +0200
changeset 61 58ec6da75f6f
parent 45 task3/solution04/src/org/apidesign/apifest08/currency/Convertor.java@251d0ed461fb
permissions -rw-r--r--
Copying structure for task4
     1 package org.apidesign.apifest08.currency;
     2 
     3 
     4 import java.math.BigDecimal;
     5 import java.util.Currency;
     6 import java.util.Set;
     7 
     8 
     9 /**
    10  * Convert between two currencies.
    11  *
    12  * @author D'Arcy Smith
    13  * @version 1.0
    14  */
    15 public interface Convertor
    16 {
    17     /**
    18      * Convert an amount from one currency to another.
    19      * 
    20      * @param from the currency to convert from.
    21      * @param to the currency to convert to.
    22      * @param amount the amount to convert.
    23      * @return the converted amount.
    24      * @throws IllegalArgumentException if any of the arguments are null.
    25      * @throws InvalidConversionException if either from or to are not valid for the convertor.
    26      */
    27     BigDecimal convert(Currency   from, 
    28                        Currency   to, 
    29                        BigDecimal amount)
    30         throws InvalidConversionException;
    31 
    32     /**
    33      * Check to see if converting between the two currencies is possible.
    34      *
    35      * @param from the currency to convert from.
    36      * @param to the currency to convert to.
    37      * @return true if the conversion is possible.
    38      */
    39     boolean canConvert(Currency from, Currency to);
    40 
    41     /**
    42      * Get the currencies that the convertor supports.  Just because a currency is
    43      * supported does not mean that canConvert will return true.
    44      * 
    45      * @return the supported currencies.
    46      */
    47     Set<Currency> getCurrencies();
    48 
    49     /**
    50      * Get the conversion rate between two currencies.
    51      * 
    52      * @param from the currency to convert from.
    53      * @param to the currency to convert to.
    54      * @return the conversion rate between the two currencies.
    55      * @throws InvalidConversionException if canConvert would return false.
    56      */
    57     BigDecimal getConversionRate(final Currency from, final Currency to)
    58         throws InvalidConversionException;
    59 }