All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.money.currency.v1_0.Currency

java.lang.Object
   |
   +----com.roguewave.money.currency.v1_0.Currency

public class Currency
extends Object
The Currency class provides a repository for the following currency information:

  • Mnemonic -- Defined in the ISO 4217:1995 standard. The mnemonic uniquely identifies a currency.
  • Numeric Code -- Defined in the ISO 4217:1995 standard. The numeric code uniquely identifies a currency.
  • Name -- Defined in the ISO 4217:1995 standard. The name uniquely identifies a currency.
  • Fraction Name -- The name of the fractional portion of a currency. For example “Cents” is the fractional name of the United States dollar, and “Pence” is the fractional name for the United Kingdom pound.
  • Ratio of Whole to Fraction -- Ratio between one unit of the whole part of a currency and the smallest unit of the fractional part of that currency. For example, for United States Dollars the ratio is one dollar to one penny which is 0.01.
  • Introduction Date
  • -- Date upon which the currency was, or will be, introduced.

  • Expiration Date
  • -- Date upon which the currency is, or was, no longer valid.

    Note: If you omit the introduction date and the expiration date when constructing a Currency object, the constructor assigns them values based on the public static data members DEFAULT_INTRODUCTION and DEFAULT_EXPIRATION.

    The date data members provide a way to deal with currencies that do not have introduction or expiration dates. The data member DEFAULT_INTRODUCTION represents a date that is "before the beginning of time." Similarly, DEFAULT_EXPIRATION represents a date that is "after the end of time." If you omit the introduction date and the expiration date when constructing a Currency object, these values will be used. You can also use them in applications to determine whether specific introduction or expiration dates occur. The following example shows how they are used:

     Currency currency;
     .
     .
     .
     if(currency.getExpirationDate().equals(Currency.DEFAULT_EXPIRATION) {
       .
       .
       .
     }
     Date date = new Date();
     if(d.before(DEFAULT_EXPIRATION)) {
       //Always true
     }
     if(d.after(DEFAULT_INTRODUCTION)) {
       //Always true
     }
     

    Author:
    Trevor Misfeldt
    See Also:
    CurrencyBook, CurrencyExample

    Variable Index

     o DEFAULT_CODE
     o DEFAULT_EXPIRATION
     o DEFAULT_FRACTION_NAME
     o DEFAULT_INTRODUCTION
     o DEFAULT_MNEMONIC
     o DEFAULT_NAME
     o DEFAULT_RATIO

    Constructor Index

     o Currency()
    Creates a new currency with all of the default variables.
     o Currency(String, int, String, String, double)
    Creates a new currency with the given information.
     o Currency(String, int, String, String, double, Date, Date)
    Creates a new currency with the given information.

    Method Index

     o equals(Currency)
    Returns true if and only if all of the data members are equal.
     o getCode()
    Returns the numeric code.
     o getExpirationDate()
    Returns the expiration date.
     o getFractionName()
    Returns the name of the fractional units, if any.
     o getIntroductionDate()
    Returns the introduction date.
     o getMnemonic()
    Returns the mnemonic.
     o getName()
    Returns the name of the currency.
     o getWholeToFractionRatio()
    Returns the ratio between the whole units and the fractional sub-units.
     o hasExpired()
    Returns true if today's date is past the expiration date.
     o isActive()
    Returns true if today's date is past the introduction date and prior to the expiration date.
     o isValid()
    Returns true if this is a valid currency.
     o read(Reader)
    Reads in data values and initializes a new currency with those values.
     o setCode(int)
    Sets the numeric code.
     o setExpirationDate(Date)
    Sets the expiration date.
     o setFractionName(String)
    Sets the name of the fractional units.
     o setIntroductionDate(Date)
    Sets the introduction date.
     o setMnemonic(String)
    Sets the mnemonic.
     o setName(String)
    Sets the name of the currency.
     o setWholeToFractionRatio(double)
    Sets the ratio of whole units to fractional sub-units.
     o toString()
    Currency is converted to a string.
     o write(Writer)
    Persists the currency's data.

    Variables

     o DEFAULT_MNEMONIC
     public static final String DEFAULT_MNEMONIC
    
     o DEFAULT_NAME
     public static final String DEFAULT_NAME
    
     o DEFAULT_CODE
     public static final int DEFAULT_CODE
    
     o DEFAULT_FRACTION_NAME
     public static final String DEFAULT_FRACTION_NAME
    
     o DEFAULT_RATIO
     public static final double DEFAULT_RATIO
    
     o DEFAULT_INTRODUCTION
     public static final Date DEFAULT_INTRODUCTION
    
     o DEFAULT_EXPIRATION
     public static final Date DEFAULT_EXPIRATION
    

    Constructors

     o Currency
     public Currency()
    
    Creates a new currency with all of the default variables.

    See Also:
    DEFAULT_MNEMONIC, DEFAULT_CODE, DEFAULT_NAME, DEFAULT_FRACTION_NAME, DEFAULT_RATIO, DEFAULT_INTRODUCTION, DEFAULT_EXPIRATION
     o Currency
     public Currency(String mnemonic,
                     int code,
                     String name,
                     String fractionName,
                     double ratio)
    
    Creates a new currency with the given information. Defaults are used for the introduction and expiration dates.

    Parameters:
    mnemonic - A character code. For example, "USD".
    code - A numeric code.
    name - The common name of the currency. For example, "US dollars".
    fractionName - The common name for the sub-unit. For example, "British pence".
    ratio - The ratio of whole units to fractional sub-units. For example, "0.01" in the case of the US currency.
    See Also:
    DEFAULT_INTRODUCTION, DEFAULT_EXPIRATION
     o Currency
     public Currency(String mnemonic,
                     int code,
                     String name,
                     String fractionName,
                     double ratio,
                     Date introduction,
                     Date expiration)
    
    Creates a new currency with the given information.

    Parameters:
    mnemonic - A character code. For example, "USD".
    code - A numeric code.
    name - The common name of the currency. For example, "US dollars".
    fractionName - The common name for the sub-unit. For example, "British pence".
    ratio - The ratio of whole units to fractional sub-units. For example, "0.01" in the case of the US currency.
    introduction - The start of the period when the currency is valid.
    expiration - The end of the period when the currency is valid.

    Methods

     o getMnemonic
     public String getMnemonic()
    
    Returns the mnemonic.

    Returns:
    the current mnemonic
     o setMnemonic
     public void setMnemonic(String mnemonic)
    
    Sets the mnemonic.

    Parameters:
    mnemonic - the desired mnemonic
     o getCode
     public int getCode()
    
    Returns the numeric code.

    Returns:
    the current code
     o setCode
     public void setCode(int code)
    
    Sets the numeric code.

    Parameters:
    code - the desired code
     o getName
     public String getName()
    
    Returns the name of the currency.

    Returns:
    the current name
     o setName
     public void setName(String name)
    
    Sets the name of the currency.

    Parameters:
    name - the desired name
     o getFractionName
     public String getFractionName()
    
    Returns the name of the fractional units, if any.

    Returns:
    the current fraction name
     o setFractionName
     public void setFractionName(String fractionName)
    
    Sets the name of the fractional units.

    Parameters:
    fraction - the desired fraction name
     o getWholeToFractionRatio
     public double getWholeToFractionRatio()
    
    Returns the ratio between the whole units and the fractional sub-units. For example, 0.01, in the case of the US currency.

    Returns:
    the current ratio
     o setWholeToFractionRatio
     public void setWholeToFractionRatio(double ratio)
    
    Sets the ratio of whole units to fractional sub-units. For example, 0.01 in the case of the US currency.

    Parameters:
    ratio - the desired ratio
     o getIntroductionDate
     public Date getIntroductionDate()
    
    Returns the introduction date. A value of DEFAULT_INTRODUCTION indicates there is no introduction date.

    Returns:
    the current introduction date
    See Also:
    DEFAULT_INTRODUCTION
     o setIntroductionDate
     public void setIntroductionDate(Date introduction)
    
    Sets the introduction date. Note: This can be a date in the past.

    Parameters:
    introduction - the date this currency becomes valid
     o getExpirationDate
     public Date getExpirationDate()
    
    Returns the expiration date. A value of DEFAULT_EXPIRATION indicates there is no expiration date.

    Returns:
    the current expiration date
    See Also:
    DEFAULT_INTRODUCTION
     o setExpirationDate
     public void setExpirationDate(Date expiration)
    
    Sets the expiration date. Note: This can be a date in the past.

    Parameters:
    expiration - the date this currency ceases to be valid
     o equals
     public boolean equals(Currency currency)
    
    Returns true if and only if all of the data members are equal.

    Returns:
    whether the currencies are equal
     o write
     public Writer write(Writer writer) throws IOException
    
    Persists the currency's data. The output will be as follows:

     BEGIN_CURRENCY
     mnemonic=USD
     code=908
     name="US Dollars"
     fraction=cents
     ratio=.08
     introduced=12-Jun-83
     expires=12-Mar-25
     END_CURRENCY
     

    Default values are not written.

    Parameters:
    writer - The writer to which the data will be persisted.
    Returns:
    The writer. Note: The writer is not flushed or closed.
     o read
     public static Currency read(Reader reader) throws IOException
    
    Reads in data values and initializes a new currency with those values. Name-value pairs can be in any order. A field without a value or a missing field will be set to the default value. The format is as follows:

     BEGIN_CURRENCY
     mnemonic=USD
     code=908
     name="US Dollars"
     fraction=cents
     ratio=.08
     introduced=12-Jun-83
     expires=12-Mar-25
     END_CURRENCY
     

    Parameters:
    reader - The reader from which data will be read. Note: The reader is not closed.
    Returns:
    A new, initialized currency.
     o toString
     public String toString()
    
    Currency is converted to a string. The format will be as follows:

     BEGIN_CURRENCY
     mnemonic=USD
     code=908
     name="US Dollars"
     fraction=cents
     ratio=.08
     introduced=12-Jun-83
     expires=12-Mar-25
     END_CURRENCY
     

    Default values are not added.

    Returns:
    A string contained all of the data members.
    Overrides:
    toString in class Object
     o hasExpired
     public boolean hasExpired()
    
    Returns true if today's date is past the expiration date.

    Returns:
    whether the currency has expired or not
     o isActive
     public boolean isActive()
    
    Returns true if today's date is past the introduction date and prior to the expiration date.

    Returns:
    whether the currency is currently active
     o isValid
     public boolean isValid()
    
    Returns true if this is a valid currency. A valid currency requires a value for the mnemonic field which is not null.

    Returns:
    whether the currency is valid or not

    All Packages  Class Hierarchy  This Package  Previous  Next  Index