task3/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java
author japod@localhost
Fri, 10 Oct 2008 22:07:25 +0200
changeset 56 a3144e7f9c90
parent 45 251d0ed461fb
permissions -rw-r--r--
solution02 task3
     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 }