japod@6: package org.apidesign.apifest08.currency; japod@6: japod@6: japod@6: japod@6: /** japod@16: * Creates {@link Convertor} implementations. japod@6: * @author lukas japod@6: * japod@6: */ japod@6: public class ConvertorFactory { japod@6: private ConvertorFactory() japod@6: { japod@6: //nothing japod@6: } japod@6: japod@6: /** japod@6: * Creates {@link Convertor} that converts from sourceEquivalent.currency to destinationEquivalent.currency. japod@6: * Exchange rate is set as equivalents. It means if you want to create USD to CZK convertor where USD1 = CZK17 japod@16: * call createConvertor(new MoneyImpl(1, USD), new MoneyImpl(17, CZK)). Convertor created by this method japod@56: * rounds the result to two decimal places. Convertor created by this method is thread safe. japod@6: * @param sourceEquivalent japod@6: * @param destinationEquivalent japod@6: * @return japod@6: */ japod@34: public static final ExtendedConvertor createConvertor(Money sourceEquivalent, Money destinationEquivalent) japod@6: { japod@34: return mergeConvertors( japod@34: new DefaultConvertor(sourceEquivalent, destinationEquivalent), japod@34: new DefaultConvertor(destinationEquivalent ,sourceEquivalent) japod@34: ); japod@34: } japod@34: japod@34: /** japod@34: * Merges convertors. The resulting convertor has ability to do all conversions that its underlying japod@34: * convertors could do. No consistency validation is done, inconsistent input will result in a convertor with japod@56: * inconsistent behavior. Convertor created by this method is thread safe. japod@34: * @param convertors japod@34: * @return japod@34: */ japod@34: public static final ExtendedConvertor mergeConvertors(ExtendedConvertor... convertors) japod@34: { japod@34: return new CompositeConvertor(convertors); japod@6: } japod@6: japod@6: japod@6: }