1.1 --- a/task3/solution04/src/org/apidesign/apifest08/currency/ConverterImpl.java Tue Oct 07 11:05:34 2008 +0200
1.2 +++ b/task3/solution04/src/org/apidesign/apifest08/currency/ConverterImpl.java Fri Oct 10 22:05:15 2008 +0200
1.3 @@ -20,12 +20,12 @@
1.4 implements Convertor
1.5 {
1.6 /**
1.7 - * The currency to cvonvert from.
1.8 + * The currency to convert from.
1.9 */
1.10 private final Currency currencyA;
1.11
1.12 /**
1.13 - * The currency to cvonvert from.
1.14 + * The currency to convert to.
1.15 */
1.16 private final Currency currencyB;
1.17
1.18 @@ -142,9 +142,20 @@
1.19 * @param from the currency to convert from.
1.20 * @param to the currency to convert to.
1.21 * @return true if the conversion is possible.
1.22 + * @throws IllegalArgumentException if either from or to are null.
1.23 */
1.24 public boolean canConvert(final Currency from, final Currency to)
1.25 {
1.26 + if(from == null)
1.27 + {
1.28 + throw new IllegalArgumentException("from cannot be null");
1.29 + }
1.30 +
1.31 + if(to == null)
1.32 + {
1.33 + throw new IllegalArgumentException("to cannot be null");
1.34 + }
1.35 +
1.36 return ((from.equals(currencyA) || from.equals(currencyB)) &&
1.37 (to.equals(currencyA) || to.equals(currencyB)));
1.38 }
1.39 @@ -172,12 +183,23 @@
1.40 * @param to the currency to convert to.
1.41 * @return the conversion rate between the two currencies.
1.42 * @throws InvalidConversionException if canConvert would return false.
1.43 + * @throws IllegalArgumentException if either from or to are null.
1.44 */
1.45 public BigDecimal getConversionRate(final Currency from,
1.46 final Currency to)
1.47 throws InvalidConversionException
1.48 - {
1.49 + {
1.50 final BigDecimal rate;
1.51 +
1.52 + if(from == null)
1.53 + {
1.54 + throw new IllegalArgumentException("from cannot be null");
1.55 + }
1.56 +
1.57 + if(to == null)
1.58 + {
1.59 + throw new IllegalArgumentException("to cannot be null");
1.60 + }
1.61
1.62 if(from.equals(to))
1.63 {