Purple Code

com.purpletech.graph.currency
Class CurrencyMapper

java.lang.Object
  |
  +--com.purpletech.graph.currency.CurrencyMapper
All Implemented Interfaces:
Unit
Direct Known Subclasses:
USDMapper

public abstract class CurrencyMapper
extends java.lang.Object
implements Unit

This class converts between BogoDollars and a particular currency representation. A BogoDollar is an int value. The actual meaning of this value is completely dependent on the particular currency the subclass represents. But since it's an int, we can optimize our calculations and our display code, and then provide a mapping to String or to double for display or storage purposes.

BogoDollars may need to be upgraded to be longs soon.

Version:
$Id: CurrencyMapper.java,v 1.2 2001/10/30 12:20:51 alex Exp $
Author:
Alex Chaffee, Ian McFarland

Field Summary
protected  java.util.Locale locale
          This is not the default Locale, otherwise the USD classes would break.
 
Constructor Summary
CurrencyMapper()
           
 
Method Summary
abstract  int fromDouble(double val)
          converts from a double (representing an actual value in the actual underlying currency) to BogoDollars
 int fromString(java.lang.String s)
          converts from a String (representing an actual value in the actual underlying currency) to BogoDollars.
 java.util.Locale getLocale()
          returns the Locale for which this currency is standard
 UnitInterval getUnitInterval()
           
protected  void setLocale(java.util.Locale locale)
          If the sublass currency is not a US currency, then the subclass must call this method in its constructor.
abstract  double toDouble(int val)
          converts from BogoDollars to a double representation of this currency
 java.lang.String toString(int val)
          converts from BogoDollars to a String representation of this currency
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.purpletech.graph.Unit
fromObject, toString
 

Field Detail

locale

protected java.util.Locale locale
This is not the default Locale, otherwise the USD classes would break. In other words, using US as the standard locale allows us to optimize all the US currency subclasses.

Constructor Detail

CurrencyMapper

public CurrencyMapper()
Method Detail

toDouble

public abstract double toDouble(int val)
converts from BogoDollars to a double representation of this currency


toString

public java.lang.String toString(int val)
converts from BogoDollars to a String representation of this currency

Specified by:
toString in interface Unit

fromDouble

public abstract int fromDouble(double val)
converts from a double (representing an actual value in the actual underlying currency) to BogoDollars


fromString

public int fromString(java.lang.String s)
               throws java.text.ParseException
converts from a String (representing an actual value in the actual underlying currency) to BogoDollars.

Should be overridden if the Locale's parse method doesn't work correctly for this currency (e.g. fractious and fractional values)

Specified by:
fromString in interface Unit
Parameters:
s - a String representing an actual value in the real units
Returns:
an int in the abstract scale
java.text.ParseException

getLocale

public java.util.Locale getLocale()
returns the Locale for which this currency is standard


setLocale

protected void setLocale(java.util.Locale locale)
If the sublass currency is not a US currency, then the subclass must call this method in its constructor.


getUnitInterval

public UnitInterval getUnitInterval()
Specified by:
getUnitInterval in interface Unit

Documentation generated March 5 2003