1 package org.apidesign.apifest08.currency;
3 import java.util.Currency;
7 * Creates default {@link Convertor} implementations.
11 public class ConvertorFactory {
12 private static final DefaultConvertorFactory DEFAULT_FACTORY = new DefaultConvertorFactory();
14 private ConvertorFactory()
20 * Creates {@link Convertor} that converts from sourceCurrency to destinationCurrency with stored exchange rate.
21 * @param sourceCurrency
22 * @param destinationCurrency
24 * @throws UnsupportedConversionException when exchange rate between currencies is not known.
27 * Only one of the createConveror methods is needed. The assignment is not explicit where the exchange rate should be set.
29 public static final Convertor createConvertor(Currency sourceCurrency, Currency destinationCurrency) throws UnsupportedConversionException
31 return DEFAULT_FACTORY.getConvertor(sourceCurrency, destinationCurrency);
34 * Creates {@link Convertor} that converts from sourceEquivalent.currency to destinationEquivalent.currency.
35 * Exchange rate is set as equivalents. It means if you want to create USD to CZK convertor where USD1 = CZK17
36 * call createConvertor(new MoneyImpl(1, USD), new MoneyImpl(17, CZK)).
37 * @param sourceEquivalent
38 * @param destinationEquivalent
42 * Only one of the createConveror methods is needed. The assignment is not explicit where the exchange rate should be set.
44 public static final Convertor createConvertor(Money sourceEquivalent, Money destinationEquivalent)
46 return new DefaultConvertor(sourceEquivalent.getAmount(), destinationEquivalent.getAmount(), sourceEquivalent.getCurrency(), destinationEquivalent.getCurrency());