1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task4/solution04/src/org/apidesign/apifest08/currency/Convertor.java Sat Oct 11 23:38:46 2008 +0200
1.3 @@ -0,0 +1,59 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +
1.7 +import java.math.BigDecimal;
1.8 +import java.util.Currency;
1.9 +import java.util.Set;
1.10 +
1.11 +
1.12 +/**
1.13 + * Convert between two currencies.
1.14 + *
1.15 + * @author D'Arcy Smith
1.16 + * @version 1.0
1.17 + */
1.18 +public interface Convertor
1.19 +{
1.20 + /**
1.21 + * Convert an amount from one currency to another.
1.22 + *
1.23 + * @param from the currency to convert from.
1.24 + * @param to the currency to convert to.
1.25 + * @param amount the amount to convert.
1.26 + * @return the converted amount.
1.27 + * @throws IllegalArgumentException if any of the arguments are null.
1.28 + * @throws InvalidConversionException if either from or to are not valid for the convertor.
1.29 + */
1.30 + BigDecimal convert(Currency from,
1.31 + Currency to,
1.32 + BigDecimal amount)
1.33 + throws InvalidConversionException;
1.34 +
1.35 + /**
1.36 + * Check to see if converting between the two currencies is possible.
1.37 + *
1.38 + * @param from the currency to convert from.
1.39 + * @param to the currency to convert to.
1.40 + * @return true if the conversion is possible.
1.41 + */
1.42 + boolean canConvert(Currency from, Currency to);
1.43 +
1.44 + /**
1.45 + * Get the currencies that the convertor supports. Just because a currency is
1.46 + * supported does not mean that canConvert will return true.
1.47 + *
1.48 + * @return the supported currencies.
1.49 + */
1.50 + Set<Currency> getCurrencies();
1.51 +
1.52 + /**
1.53 + * Get the conversion rate between two currencies.
1.54 + *
1.55 + * @param from the currency to convert from.
1.56 + * @param to the currency to convert to.
1.57 + * @return the conversion rate between the two currencies.
1.58 + * @throws InvalidConversionException if canConvert would return false.
1.59 + */
1.60 + BigDecimal getConversionRate(final Currency from, final Currency to)
1.61 + throws InvalidConversionException;
1.62 +}