finishing update to 1.5 (sol 02)
authorjapod@localhost
Tue, 30 Sep 2008 15:15:22 +0200
changeset 26953f221cb986
parent 25 a022dd2a5d30
child 27 724f953a5f3e
finishing update to 1.5 (sol 02)
task1/solution02/src/org/apidesign/apifest08/currency/DefaultConvertorFactory.java
task1/solution02/src/org/apidesign/apifest08/currency/UnsupportedConversionException.java
     1.1 --- a/task1/solution02/src/org/apidesign/apifest08/currency/DefaultConvertorFactory.java	Tue Sep 30 13:51:18 2008 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,49 +0,0 @@
     1.4 -package org.apidesign.apifest08.currency;
     1.5 -
     1.6 -
     1.7 -import java.math.BigDecimal;
     1.8 -import java.util.Currency;
     1.9 -import java.util.HashMap;
    1.10 -import java.util.Map;
    1.11 -
    1.12 -/**
    1.13 - * Default factory for convertors. Basically it just keeps exchange rates for given currency combinations.
    1.14 - * @author lukas
    1.15 - *
    1.16 - */
    1.17 -class DefaultConvertorFactory {
    1.18 -	private static final Currency SKK = Currency.getInstance("SKK");
    1.19 -	private static final Currency USD = Currency.getInstance("USD");
    1.20 -	private static final Currency CZK = Currency.getInstance("CZK");
    1.21 -	private Map<String, Convertor> convertorMap = new HashMap<String, Convertor>();
    1.22 -	
    1.23 -	public 	DefaultConvertorFactory()
    1.24 -	{
    1.25 -		addConvertor(CZK,USD,BigDecimal.valueOf(17),BigDecimal.valueOf(1));
    1.26 -		addConvertor(CZK,SKK,BigDecimal.valueOf(80),BigDecimal.valueOf(100));
    1.27 -	}
    1.28 -
    1.29 -	private void addConvertor(Currency sourceCurrency, Currency destinationCurrency, BigDecimal sourceEquivalent, BigDecimal destinationEquivalent) {
    1.30 -		DefaultConvertor convertor = new DefaultConvertor(sourceEquivalent, destinationEquivalent, sourceCurrency, destinationCurrency);
    1.31 -		convertorMap.put(getConvertorKey(sourceCurrency, destinationCurrency), convertor);
    1.32 -		convertorMap.put(getConvertorKey(destinationCurrency, sourceCurrency), convertor.revert());
    1.33 -	}
    1.34 -		
    1.35 -	public Convertor getConvertor(Currency sourceCurrency, Currency destinationCurrency) throws UnsupportedConversionException
    1.36 -	{
    1.37 -		String convertorKey = getConvertorKey(sourceCurrency, destinationCurrency);
    1.38 -		Convertor result = convertorMap.get(convertorKey);
    1.39 -		if (result!=null)
    1.40 -		{
    1.41 -			return result;
    1.42 -		}
    1.43 -		else
    1.44 -		{
    1.45 -			throw new UnsupportedConversionException("Conversion from "+sourceCurrency+" to "+destinationCurrency+" is not supported");
    1.46 -		}
    1.47 -	}
    1.48 -
    1.49 -	private String getConvertorKey(Currency sourceCurrency,	Currency destinationCurrency) {
    1.50 -		return sourceCurrency.getCurrencyCode()+destinationCurrency.getCurrencyCode();
    1.51 -	}
    1.52 -}
     2.1 --- a/task1/solution02/src/org/apidesign/apifest08/currency/UnsupportedConversionException.java	Tue Sep 30 13:51:18 2008 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,28 +0,0 @@
     2.4 -package org.apidesign.apifest08.currency;
     2.5 -
     2.6 -/**
     2.7 - * Exception thrown when conversion is not supported.
     2.8 - * @author lukas
     2.9 - *
    2.10 - */
    2.11 -public class UnsupportedConversionException extends IllegalArgumentException {
    2.12 -	private static final long serialVersionUID = 4412475695345865196L;
    2.13 -
    2.14 -	public UnsupportedConversionException() {
    2.15 -		super();
    2.16 -	}
    2.17 -
    2.18 -	public UnsupportedConversionException(String message, Throwable cause) {
    2.19 -		super(message, cause);
    2.20 -	}
    2.21 -
    2.22 -	public UnsupportedConversionException(String s) {
    2.23 -		super(s);
    2.24 -	}
    2.25 -
    2.26 -	public UnsupportedConversionException(Throwable cause) {
    2.27 -		super(cause);
    2.28 -	}
    2.29 -
    2.30 -
    2.31 -}