Holger's
Java API

com.antelmann.math
Class MoneyConverter

java.lang.Object
  extended by com.antelmann.math.MoneyConverter
All Implemented Interfaces:
UnitConverter, Converter<Money,Money>, Serializable, Comparator<Money>

public class MoneyConverter
extends Object
implements Serializable, Comparator<Money>, Converter<Money,Money>, UnitConverter

provides money exchange rates

Since:
7. Juli 2007, 15:29
Author:
Holger Antelmann
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.antelmann.util.Converter
Converter.Adapter<T1,T2>
 
Constructor Summary
MoneyConverter()
           
MoneyConverter(Currency baseCurrency)
           
 
Method Summary
 BigDecimal addCurrency(Currency c, BigDecimal exchangeRate)
          returns the previously set exchange rate or null
 BigDecimal addCurrency(Currency c, double exchangeRate)
           
<P,T> HashMap<P,Money>
aggregate(Map<T,Money> data, PatternExtractor<T,P> pattern)
          all Money is converted into the base currency
 int compare(Money m1, Money m2)
          If the currencies are not equal, they are compared based on the baseCurrency.
 boolean contains(Currency c)
           
 Money convert(Measurable m, Unit targetUnit)
          converts the given measurable into the target unit and returns the resulting measurable
 Money convert(Money m)
          converts to the base currency
 Money convertBack(Money obj)
          always throws UnsupportedOperationException as it is not clear what currency is desired
 Money convertToBaseCurrency(Money m)
           
 Money convertToCurrency(Money m, Currency c)
           
 Currency getBaseCurrency()
           
 BigDecimal getExchangeRate(Currency c)
           
 BigDecimal getExchangeRate(Money m)
           
 Set<Currency> getKnownCurrencies()
          returns an unmodifiable view of the known currencies
 BigDecimal removeCurrency(Currency c)
          returns the exchange rate that was previously set or null
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

MoneyConverter

public MoneyConverter()

MoneyConverter

public MoneyConverter(Currency baseCurrency)
Method Detail

getBaseCurrency

public Currency getBaseCurrency()

contains

public boolean contains(Currency c)

getKnownCurrencies

public Set<Currency> getKnownCurrencies()
returns an unmodifiable view of the known currencies


getExchangeRate

public BigDecimal getExchangeRate(Currency c)

getExchangeRate

public BigDecimal getExchangeRate(Money m)

addCurrency

public BigDecimal addCurrency(Currency c,
                              double exchangeRate)

addCurrency

public BigDecimal addCurrency(Currency c,
                              BigDecimal exchangeRate)
returns the previously set exchange rate or null


removeCurrency

public BigDecimal removeCurrency(Currency c)
returns the exchange rate that was previously set or null


convertToBaseCurrency

public Money convertToBaseCurrency(Money m)
                            throws WrongCurrencyException
Throws:
WrongCurrencyException

convertToCurrency

public Money convertToCurrency(Money m,
                               Currency c)

compare

public int compare(Money m1,
                   Money m2)
            throws WrongCurrencyException
If the currencies are not equal, they are compared based on the baseCurrency.

Specified by:
compare in interface Comparator<Money>
Throws:
WrongCurrencyException - if any given currency is not known to this instance

aggregate

public <P,T> HashMap<P,Money> aggregate(Map<T,Money> data,
                                        PatternExtractor<T,P> pattern)
                           throws WrongCurrencyException
all Money is converted into the base currency

Throws:
WrongCurrencyException

convert

public Money convert(Money m)
converts to the base currency

Specified by:
convert in interface Converter<Money,Money>
Throws:
WrongCurrencyException - if the given currency is unknown
See Also:
getBaseCurrency()

convertBack

public Money convertBack(Money obj)
                  throws UnsupportedOperationException
always throws UnsupportedOperationException as it is not clear what currency is desired

Specified by:
convertBack in interface Converter<Money,Money>
Throws:
UnsupportedOperationException

convert

public Money convert(Measurable m,
                     Unit targetUnit)
              throws IllegalArgumentException,
                     UnsupportedOperationException
Description copied from interface: UnitConverter
converts the given measurable into the target unit and returns the resulting measurable

Specified by:
convert in interface UnitConverter
Parameters:
m - the original measurable to be converted
targetUnit - the desired unit
Returns:
a measurable that embeds the target unit and a number that corresponds
Throws:
IllegalArgumentException - if this converter cannot handle any of the given units
UnsupportedOperationException - if the units of the given measurable and the target unit are not convertible


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads