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