task2/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 16 task1/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java@2864c6d744c0
child 34 3a18aae85c9e
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
     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.
    21 	 * @param sourceEquivalent
    22 	 * @param destinationEquivalent
    23 	 * @return
    24 	 */
    25 	public static final Convertor createConvertor(Money sourceEquivalent, Money destinationEquivalent)
    26 	{
    27 		return new DefaultConvertor(sourceEquivalent.getAmount(), destinationEquivalent.getAmount(), sourceEquivalent.getCurrency(), destinationEquivalent.getCurrency());
    28 	}
    29 	
    30 
    31 }