task4/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java
changeset 61 58ec6da75f6f
parent 56 a3144e7f9c90
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task4/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java	Sat Oct 11 23:38:46 2008 +0200
     1.3 @@ -0,0 +1,46 @@
     1.4 +package org.apidesign.apifest08.currency;
     1.5 +
     1.6 +
     1.7 +
     1.8 +/**
     1.9 + * Creates {@link Convertor} implementations.
    1.10 + * @author lukas
    1.11 + *
    1.12 + */
    1.13 +public class ConvertorFactory {
    1.14 +	private ConvertorFactory()
    1.15 +	{
    1.16 +		//nothing
    1.17 +	}
    1.18 +		
    1.19 +	/**
    1.20 +	 * Creates {@link Convertor} that converts from sourceEquivalent.currency to destinationEquivalent.currency. 
    1.21 +	 * Exchange rate is set as equivalents. It means if you want to create USD to CZK convertor where USD1 = CZK17 
    1.22 +     * call createConvertor(new MoneyImpl(1, USD), new MoneyImpl(17, CZK)). Convertor created by this method 
    1.23 +     * rounds the result to two decimal places. Convertor created by this method is thread safe.
    1.24 +	 * @param sourceEquivalent
    1.25 +	 * @param destinationEquivalent
    1.26 +	 * @return
    1.27 +	 */
    1.28 +	public static final ExtendedConvertor createConvertor(Money sourceEquivalent, Money destinationEquivalent)
    1.29 +	{
    1.30 +		return mergeConvertors(
    1.31 +				new DefaultConvertor(sourceEquivalent, destinationEquivalent),
    1.32 +				new DefaultConvertor(destinationEquivalent ,sourceEquivalent)
    1.33 +		);
    1.34 +	}
    1.35 +	
    1.36 +	/**
    1.37 +	 * Merges convertors. The resulting convertor has ability to do all conversions that its underlying 
    1.38 +	 * convertors could do. No consistency validation is done, inconsistent input will result in a convertor with
    1.39 +	 * inconsistent behavior. Convertor created by this method is thread safe.
    1.40 +	 * @param convertors
    1.41 +	 * @return
    1.42 +	 */
    1.43 +	public static final ExtendedConvertor mergeConvertors(ExtendedConvertor... convertors)
    1.44 +	{
    1.45 +		return new CompositeConvertor(convertors);
    1.46 +	}
    1.47 +	
    1.48 +
    1.49 +}