Agent System POND 1.2 (28.2.2002)

FIM.payment
Class Currency

java.lang.Object
  |
  +--FIM.payment.Currency
All Implemented Interfaces:
Serializable, XMLEncodeable

public class Currency
extends Object
implements XMLEncodeable, Serializable

A class representing a currency. Also includes a (fixed) conversion factor.
Includes a static list of the currencies available.
Currently includes Euro, ATS, DEM and US$

Version:
1.0
Author:
Michael Sonntag
See Also:
Serialized Form

Field Summary
protected  String[] abbrev
          The list of abbreviations of the currency.
protected static Vector currencies
          The static list of currencies available.
 
Constructor Summary
Currency(Element elem)
          Creates a new currency object from values stored in an XML Element.
Currency(String shortName, String longName, boolean pre, String[] abbrev, Locale loc, double exchangeRate)
          Creates a new currency object.
 
Method Summary
(package private) static void ()
          Creates the four standard objects and adds them to the static list.
static void addCurrency(Currency cur)
          Adds a currency to the list.
static void clearCurrencies()
          Clears the list of all currencies.
static int currenciesCount()
          Retrieve the number of currencies in the list
static int currencyPos(Currency cur)
          Retrieve the index of a certain currency
 void decodeXMLElement(Element elem)
          Parse back the currency from an XML element.
 boolean equals(Object obj)
          Compares two currencies for equality.
static Currency findCurrency(String str)
          Finds the first currency equivalent to the string.
 String[] getAbbreviations()
          Retrieve the abbreviations of this currency.
 Serializable getAsSerializable()
          Retrieve the currency as a serializable (just returns this as this object is directly serializable).
 Element getAsXMLElement(Document doc)
          Retrieve the currency as an XML element.
static Currency[] getCurrencies()
          Retrieve an array of all currencies available.
 double getExchangeRateToStandard()
          Retrieve the exchange rate for this currency to the Euro. xxxx units of this currency are 1 Euro.
 Locale getLocale()
          Retrieve the locale to be used for parsing values of this currency.
 String getLongName()
          Retrieve the long name of this currency.
 String getShortName()
          Retrieve the short name of this currency.
 boolean isPreValue()
          Retrieve whether this currency is a prefix to the value (e. g.
protected  boolean matchString(String str)
          Matches a string to the abbreviations for this currency (case-sensitive).
 double parseCurrencyValue(String str)
          Parses the value from a string according to the currency ('.' or ',' as thousands-separator, ...).
static void removeCurrency(Currency cur)
          Removes a currency from the list.
 void setExchangeRateToStandard(double exchangeRate)
          Set the exchange rate for this currency to the Euro. xxxx units of this currency are 1 Euro.
 String toString()
          Returns a string representation of the object; in this case the short name of the currency.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

abbrev

protected String[] abbrev
The list of abbreviations of the currency.

currencies

protected static Vector currencies
The static list of currencies available.
Constructor Detail

Currency

public Currency(String shortName,
                String longName,
                boolean pre,
                String[] abbrev,
                Locale loc,
                double exchangeRate)
Creates a new currency object.
Parameters:
shortName - the short name for the currency
longName - the long name for the currency
pre - if true, the currency is in front of the value, otherwise behind
abbrev - the list of abbreviations for this currency (may be empty or null)
loc - the locale to use for parsing values in this currency
exchangeRate - the exchange rate to 1 Euro (xxxx units of this currency are 1 Euro); provide 0.0 if not applicable or unknown

Currency

public Currency(Element elem)
Creates a new currency object from values stored in an XML Element.
Parameters:
elem - the XML element to parse the values from
Throws:
IllegalArgumentException - if the currency could not be parsed back completely
Method Detail

static void ()
Creates the four standard objects and adds them to the static list.

setExchangeRateToStandard

public void setExchangeRateToStandard(double exchangeRate)
Set the exchange rate for this currency to the Euro. xxxx units of this currency are 1 Euro. If no applicable or unknown, provide 0.0d.
Parameters:
exchangeRate - the factor for conversion (msut be >=0.0)

getExchangeRateToStandard

public double getExchangeRateToStandard()
Retrieve the exchange rate for this currency to the Euro. xxxx units of this currency are 1 Euro.
Returns:
the factor for conversion or 0.0 if not known/applicable

getAbbreviations

public String[] getAbbreviations()
Retrieve the abbreviations of this currency.
Returns:
the array of abbreviations of this corrency

getShortName

public String getShortName()
Retrieve the short name of this currency.
Returns:
the short name of this currency

getLongName

public String getLongName()
Retrieve the long name of this currency.
Returns:
the long name of this currency

getLocale

public Locale getLocale()
Retrieve the locale to be used for parsing values of this currency.
Returns:
the locale for this currency

isPreValue

public boolean isPreValue()
Retrieve whether this currency is a prefix to the value (e. g. US$ 30.99) or a postfix (e. g. 19,99 S).
Returns:
true if the currency text is in front of the value

toString

public String toString()
Returns a string representation of the object; in this case the short name of the currency.
Specified by:
toString in interface XMLEncodeable
Overrides:
toString in class Object
Returns:
the short name of the currency

matchString

protected boolean matchString(String str)
Matches a string to the abbreviations for this currency (case-sensitive).
Parameters:
str - the string to match
Returns:
true if the string matches one of the abbrevations

addCurrency

public static void addCurrency(Currency cur)
Adds a currency to the list. If the currency already exists (exact match, excluding only the conversion factor!), the request is ignored.
Parameters:
cur - the currency to add.

removeCurrency

public static void removeCurrency(Currency cur)
Removes a currency from the list. Ignored if not in the list.
Parameters:
cur - the currency to remove

clearCurrencies

public static void clearCurrencies()
Clears the list of all currencies.

currenciesCount

public static int currenciesCount()
Retrieve the number of currencies in the list
Returns:
the number of currencies

currencyPos

public static int currencyPos(Currency cur)
Retrieve the index of a certain currency
Parameters:
cur - the currency to find
Returns:
the position of the currency in the list or -1 if not found

getCurrencies

public static Currency[] getCurrencies()
Retrieve an array of all currencies available.
Parameters:
an - array of all currency-objects available

findCurrency

public static Currency findCurrency(String str)
Finds the first currency equivalent to the string. Returns a currency object, where one of the abbreviations equals the string. If the occurs in the abbrveiations of more than one currency, the first one is returned (which is more or less random).
Parameters:
str - the string containing the value of the currency denominator
Returns:
null or the currency for the string

parseCurrencyValue

public double parseCurrencyValue(String str)
Parses the value from a string according to the currency ('.' or ',' as thousands-separator, ...).
Parameters:
str - the string containing the value to parse
Returns:
Double.NaN in case of error, otherwise the parsed value according to the currency

equals

public boolean equals(Object obj)
Compares two currencies for equality. Includes all the data WITHOUT the exchange factor. Abbreviations need not be in the same order, but all must be included and no other may be included.
Overrides:
equals in class Object
Parameters:
obj - the object this one to compare to
Returns:
true if both objects are equal

getAsSerializable

public Serializable getAsSerializable()
Retrieve the currency as a serializable (just returns this as this object is directly serializable).
Specified by:
getAsSerializable in interface XMLEncodeable
Returns:
the currency object as a serializable

getAsXMLElement

public Element getAsXMLElement(Document doc)
Retrieve the currency as an XML element.
Specified by:
getAsXMLElement in interface XMLEncodeable
Parameters:
doc - the document within which to create the element
Returns:
the currency as an element

decodeXMLElement

public void decodeXMLElement(Element elem)
                      throws IllegalArgumentException
Parse back the currency from an XML element.
Specified by:
decodeXMLElement in interface XMLEncodeable
Parameters:
elem - the element containing the currency to parse back
Throws:
IllegalArgumentException - if the element is incorrect (e. g. wrong tag name)

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.