net.sf.jec.functions
Class CurrencyFormat

java.lang.Object
  extended bynet.sf.jec.functions.CurrencyFormat

public class CurrencyFormat
extends java.lang.Object

This is a utility class for currency formatting and conversion. Use it to convert currency amounts between countries (example: EUR->ESP). You can just convert a 'double' amount, so it acts as a converter, or a 'double' to a formatted String.

To create a new CurrencyFormat object you need a factor map, which gives the relationship between amounts, and a format map, that specifies how a currency type must be transformed into a String.

factorMap is a Map with pairs String/Double with the relationships between currency types amounts. The default instance has 2 entries: "EUR"->"1.0d" and "ESP"->"166.386d". Notice that there's a reference currency with value "1.0d". Other currency values are relative to this reference currency type.

formatMap is a Map with pairs String/DecimalFormat with the relationships between currency types and their formatter (as they are 'doubles' their formatter are DecimalFormat objects).

The default CurrencyFormat has only 2 currency types: ESP and EUR.

Version:
Author:
mballesteros

Constructor Summary
CurrencyFormat(java.util.Map factorMap, java.util.Map formatMap, java.lang.String defaultCurrType)
          Creates a new CurrencyFormat object given a factor map, which gives the relationship between amounts, and a format map, that specifies how a currency type must be transformed into a String.
 
Method Summary
 double convert(double amount, java.lang.String idSource, java.lang.String idTarget)
          Converts an amount, given a source currency type, into a target currency amount.
static CurrencyFormat getDefaultInstance()
          Returns the default instance with ESP and EUR as the only currency types.
 double parseString(java.lang.String amount)
          Parses an String expressed in a source currency type and converts it to a target currency type amount
 double parseString(java.lang.String amount, java.lang.String idSource, java.lang.String idTarget)
          Parses an String expressed in a source currency type and converts it to a target currency type amount
 java.lang.String toString(double amount)
          Formats an amount in the default currency type
 java.lang.String toString(double amount, java.lang.String idSource, java.lang.String idTarget)
          Converts and formats an amount, given a source currency type, into a target currency format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CurrencyFormat

public CurrencyFormat(java.util.Map factorMap,
                      java.util.Map formatMap,
                      java.lang.String defaultCurrType)
Creates a new CurrencyFormat object given a factor map, which gives the relationship between amounts, and a format map, that specifies how a currency type must be transformed into a String.

Parameters:
factorMap - A Map with pairs String/Double with the relationships between currency types amounts. The default instance has 2 entries: "EUR"->"1.0d" and "ESP"->"166.386d". Notice that there's a reference currency with value "1.0d". Other currency values are relative to this reference currency type.
formatMap - A Map with pairs String/DecimalFormat with the relationships between currency types and their formatter (as they are 'doubles' their formatter are DecimalFormat objects).
Method Detail

getDefaultInstance

public static CurrencyFormat getDefaultInstance()
Returns the default instance with ESP and EUR as the only currency types.


toString

public java.lang.String toString(double amount)
Formats an amount in the default currency type

Parameters:
amount - The amount to convert and format

toString

public java.lang.String toString(double amount,
                                 java.lang.String idSource,
                                 java.lang.String idTarget)
Converts and formats an amount, given a source currency type, into a target currency format.

Parameters:
amount - The amount to convert and format
idSource - The amount's currency type
idTarget - The desired target currency type

parseString

public double parseString(java.lang.String amount)
Parses an String expressed in a source currency type and converts it to a target currency type amount


parseString

public double parseString(java.lang.String amount,
                          java.lang.String idSource,
                          java.lang.String idTarget)
Parses an String expressed in a source currency type and converts it to a target currency type amount


convert

public double convert(double amount,
                      java.lang.String idSource,
                      java.lang.String idTarget)
Converts an amount, given a source currency type, into a target currency amount.

Parameters:
amount - The amount to convert
idSource - The amount's currency type
idTarget - The desired target currency type


Copyright © 2003 SourceForge. All Rights Reserved.