task4/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Oct 2008 23:38:46 +0200
changeset 61 58ec6da75f6f
parent 56 task3/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java@a3144e7f9c90
permissions -rw-r--r--
Copying structure for task4
     1 package org.apidesign.apifest08.currency;
     2 
     3 
     4 
     5 /**
     6  * Creates {@link Convertor} implementations.
     7  * @author lukas
     8  *
     9  */
    10 public class ConvertorFactory {
    11 	private ConvertorFactory()
    12 	{
    13 		//nothing
    14 	}
    15 		
    16 	/**
    17 	 * Creates {@link Convertor} that converts from sourceEquivalent.currency to destinationEquivalent.currency. 
    18 	 * Exchange rate is set as equivalents. It means if you want to create USD to CZK convertor where USD1 = CZK17 
    19      * call createConvertor(new MoneyImpl(1, USD), new MoneyImpl(17, CZK)). Convertor created by this method 
    20      * rounds the result to two decimal places. Convertor created by this method is thread safe.
    21 	 * @param sourceEquivalent
    22 	 * @param destinationEquivalent
    23 	 * @return
    24 	 */
    25 	public static final ExtendedConvertor createConvertor(Money sourceEquivalent, Money destinationEquivalent)
    26 	{
    27 		return mergeConvertors(
    28 				new DefaultConvertor(sourceEquivalent, destinationEquivalent),
    29 				new DefaultConvertor(destinationEquivalent ,sourceEquivalent)
    30 		);
    31 	}
    32 	
    33 	/**
    34 	 * Merges convertors. The resulting convertor has ability to do all conversions that its underlying 
    35 	 * convertors could do. No consistency validation is done, inconsistent input will result in a convertor with
    36 	 * inconsistent behavior. Convertor created by this method is thread safe.
    37 	 * @param convertors
    38 	 * @return
    39 	 */
    40 	public static final ExtendedConvertor mergeConvertors(ExtendedConvertor... convertors)
    41 	{
    42 		return new CompositeConvertor(convertors);
    43 	}
    44 	
    45 
    46 }