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
-
DEFAULT_CODE
-
-
DEFAULT_EXPIRATION
-
-
DEFAULT_FRACTION_NAME
-
-
DEFAULT_INTRODUCTION
-
-
DEFAULT_MNEMONIC
-
-
DEFAULT_NAME
-
-
DEFAULT_RATIO
-
-
Currency()
- Creates a new currency with all of the default variables.
-
Currency(String, int, String, String, double)
- Creates a new currency with the given information.
-
Currency(String, int, String, String, double, Date, Date)
- Creates a new currency with the given information.
-
equals(Currency)
- Returns true if and only if all of the data members are equal.
-
getCode()
- Returns the numeric code.
-
getExpirationDate()
- Returns the expiration date.
-
getFractionName()
- Returns the name of the fractional units, if any.
-
getIntroductionDate()
- Returns the introduction date.
-
getMnemonic()
- Returns the mnemonic.
-
getName()
- Returns the name of the currency.
-
getWholeToFractionRatio()
- Returns the ratio between the whole units and the fractional sub-units.
-
hasExpired()
- Returns true if today's date is past the expiration date.
-
isActive()
- Returns true if today's date is past the introduction date and prior to the
expiration date.
-
isValid()
- Returns true if this is a valid currency.
-
read(Reader)
- Reads in data values and initializes a new currency with those values.
-
setCode(int)
- Sets the numeric code.
-
setExpirationDate(Date)
- Sets the expiration date.
-
setFractionName(String)
- Sets the name of the fractional units.
-
setIntroductionDate(Date)
- Sets the introduction date.
-
setMnemonic(String)
- Sets the mnemonic.
-
setName(String)
- Sets the name of the currency.
-
setWholeToFractionRatio(double)
- Sets the ratio of whole units to fractional sub-units.
-
toString()
- Currency is converted to a string.
-
write(Writer)
- Persists the currency's data.
DEFAULT_MNEMONIC
public static final String DEFAULT_MNEMONIC
DEFAULT_NAME
public static final String DEFAULT_NAME
DEFAULT_CODE
public static final int DEFAULT_CODE
DEFAULT_FRACTION_NAME
public static final String DEFAULT_FRACTION_NAME
DEFAULT_RATIO
public static final double DEFAULT_RATIO
DEFAULT_INTRODUCTION
public static final Date DEFAULT_INTRODUCTION
DEFAULT_EXPIRATION
public static final Date DEFAULT_EXPIRATION
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
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
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.
getMnemonic
public String getMnemonic()
- Returns the mnemonic.
- Returns:
- the current mnemonic
setMnemonic
public void setMnemonic(String mnemonic)
- Sets the mnemonic.
- Parameters:
- mnemonic - the desired mnemonic
getCode
public int getCode()
- Returns the numeric code.
- Returns:
- the current code
setCode
public void setCode(int code)
- Sets the numeric code.
- Parameters:
- code - the desired code
getName
public String getName()
- Returns the name of the currency.
- Returns:
- the current name
setName
public void setName(String name)
- Sets the name of the currency.
- Parameters:
- name - the desired name
getFractionName
public String getFractionName()
- Returns the name of the fractional units, if any.
- Returns:
- the current fraction name
setFractionName
public void setFractionName(String fractionName)
- Sets the name of the fractional units.
- Parameters:
- fraction - the desired fraction name
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
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
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
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
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
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
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
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.
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.
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
hasExpired
public boolean hasExpired()
- Returns true if today's date is past the expiration date.
- Returns:
- whether the currency has expired or not
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
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