1 package org.apidesign.apifest08.currency;
4 import java.math.BigDecimal;
5 import java.util.Currency;
10 * Convert between two currencies.
12 * @author D'Arcy Smith
15 public interface Convertor
18 * Convert an amount from one currency to another.
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.
27 BigDecimal convert(Currency from,
30 throws InvalidConversionException;
33 * Check to see if converting between the two currencies is possible.
35 * @param from the currency to convert from.
36 * @param to the currency to convert to.
37 * @return true if the conversion is possible.
39 boolean canConvert(Currency from, Currency to);
42 * Get the currencies that the convertor supports. Just because a currency is
43 * supported does not mean that canConvert will return true.
45 * @return the supported currencies.
47 Set<Currency> getCurrencies();
50 * Get the conversion rate between two currencies.
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.
57 BigDecimal getConversionRate(final Currency from, final Currency to)
58 throws InvalidConversionException;