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