All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.money.currency.v1_0.CurrencyBook

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

public class CurrencyBook
extends Object
CurrencyBook stores Currency objects. Each currency in the currency book is identified by a unique mnemonic. A currency’s mnemonic can only appear once -- duplicates are not allowed. A CurrencyBook can be initialized from a file.

Author:
Trevor Misfeldt
See Also:
Currency, CurrencyExample

Variable Index

 o currencies

Constructor Index

 o CurrencyBook()
Creates an empty currency book.

Method Index

 o clear()
Removes all currencies from the currency book.
 o contains(Currency)
Returns true if the specified currency is in the currency book.
 o contains(String)
Returns true if the currency specified by the mnemonic is in the currency book.
 o entries()
Returns the number of currencies in the currency book.
 o find(String)
Finds the currency indicated by the mnemonic.
 o getCurrencies()
Returns all of the currencies in the currency book.
 o getKeys()
Returns the keys to all of the elements in the currency book.
 o initialize(Reader)
Initializes a currency book with currencies from a reader.
 o insert(Currency)
Adds the given currency to the currency book.
 o read(Reader)
Creates a new currency book with initialized values from a reader.
 o remove(Currency)
Removes the given currency.
 o remove(String)
Removes the currency indicated by the currency mnemonic.
 o toString()
Returns a string representation of this collection of currencies.
 o write(Writer)
Persists the book's collection of currencies.

Variables

 o currencies
 public Hashtable currencies

Constructors

 o CurrencyBook
 public CurrencyBook()
Creates an empty currency book.

Methods

 o getCurrencies
 public Enumeration getCurrencies()
Returns all of the currencies in the currency book.

Returns:
An enumeration containing all of the currencies.
 o getKeys
 public Enumeration getKeys()
Returns the keys to all of the elements in the currency book. The keys are the currency's mnemonic in upper case.

Returns:
An enumeration containing all of the currencies' mnemonics.
 o insert
 public Currency insert(Currency currency)
Adds the given currency to the currency book. If the currency book already contains an entry that matches the currency, then this currency is inserted and the old value is returned. Otherwise, null is returned.

Parameters:
currency - the currency to be added
Returns:
Returns the existing currency if one is already stored. Otherwise, returns null.
 o remove
 public Currency remove(String mnemonic)
Removes the currency indicated by the currency mnemonic.

Parameters:
mnemonic - the mnemonic of the currency to be removed
Returns:
If there is an existing currency with this mnemonic, then it is returned. Otherwise, null is returned.
 o remove
 public Currency remove(Currency currency)
Removes the given currency.

Parameters:
currency - the currency to be removed
Returns:
If there is an existing currency with this currency's mnemonic, then it is returned. Otherwise, null is returned.
 o find
 public Currency find(String mnemonic)
Finds the currency indicated by the mnemonic.

Parameters:
mnemonic - the mnemonic of the desired currency
Returns:
The currency in the book with the specified mnemonic. If it can't be found, returns null.
 o contains
 public boolean contains(Currency currency)
Returns true if the specified currency is in the currency book. Otherwise, returns false.

Parameters:
currency - the desired currency
Returns:
whether the currency is contained in the book or not.
 o contains
 public boolean contains(String mnemonic)
Returns true if the currency specified by the mnemonic is in the currency book. Otherwise, returns false.

Parameters:
mnemonic - the mnemonic for the desired currency
Returns:
whether the specified currency is contained in the book or not.
 o entries
 public int entries()
Returns the number of currencies in the currency book.

Returns:
the currency count
 o clear
 public void clear()
Removes all currencies from the currency book.

 o initialize
 public void initialize(Reader reader) throws IOException
Initializes a currency book with currencies from a reader. NOTE: The previous contents of this currency book are deleted when this method is invoked.

A currency specification begins with BEGIN_CURRENCY. Each attribute of the currency is specified as a name/value pair, one per line. The name/value separator is the equal sign '='. The end of a currency specification is indicated by the token END_CURRENCY. Comment lines start with a '#' character and are automatically skipped. For example:

 #Kenya
 BEGIN_CURRENCY
 mnemonic=KES
 ratio=.01
 name=shilling
 fraction=cents
 code=404
 introduced=
 expires=
 END_CURRENCY
 

Name matching is case-insensitive and the only required value is mnemonic. The pairs can be in any order.

Parameters:
reader - The reader from which data will be read. Note: The reader is not closed.
 o read
 public static CurrencyBook read(Reader reader) throws IOException
Creates a new currency book with initialized values from a reader.

A currency specification begins with BEGIN_CURRENCY. Each attribute of the currency is specified as a name/value pair, one per line. The name/value separator is the equal sign '='. The end of a currency specification is indicated by the token END_CURRENCY. Comment lines start with a '#' character and are automatically skipped. For example:

 #Kenya
 BEGIN_CURRENCY
 mnemonic=KES
 ratio=.01
 name=shilling
 fraction=cents
 code=404
 introduced=
 expires=
 END_CURRENCY
 

Name matching is case-insensitive and the only required value is mnemonic. The pairs can be in any order.

Parameters:
reader - The reader from which data will be read. Note: The reader is not closed.
Returns:
the new, initialized currency book.
See Also:
Currency, read
 o write
 public Writer write(Writer writer) throws IOException
Persists the book's collection of currencies. Each currency's 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 flused or closed.
See Also:
Currency, write
 o toString
 public String toString()
Returns a string representation of this collection of currencies. The format will be as follows:

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

Default values are not added.

Returns:
A string containing all of the currencies' string representations.
Overrides:
toString in class Object
See Also:
Currency, toString

All Packages  Class Hierarchy  This Package  Previous  Next  Index