All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.money.currency.v1_0.ExchangeFactory

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

public class ExchangeFactory
extends Object
Money.h++ provides a factory class, ExchangeFactory that creates currency exchange objects. The currency exchange factory is essentially a list of ExchangeGroups. When the factory receives a request for a currency exchange, it finds the first currency exchange group that can create an Exchange object and returns the object it found. By default, upon construction, the ExchangeFactory class always contains one currency exchange group: MultiplicationGroup.

The MultiplicationGroup group is the default exchange group, and, initially, is always available in the factory’s list of currency groups. When presented with a source/target currency pair and exchange rate table, the default exchange group looks for an exchange rate in the table for the pair and, if found, constructs a MultiplicationExchange exchange object.

Author:
Trevor Misfeldt
See Also:
Exchange, BilateralExchange, MultiplicationExchange, DivisionExchange, TriangularExchange, ExchangeRateTable, ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup, MoneyCalculatorExample, FactoryExample, GroupExample

Variable Index

 o NOT_FOUND
Index returned when an exchange group cannot be found.

Constructor Index

 o ExchangeFactory()
Creates an exchange factory with the default bilateral multiplication group and an empty exchange rate table.
 o ExchangeFactory(ExchangeRateTable)
Creates an exchange factory with the default bilateral multiplication group and the given exchange rate table.

Method Index

 o appendExchangeGroup(ExchangeGroup)
Appends the exchange group to the collection of exchange groups.
 o clearExchangeGroups()
Removes all exchange groups.
 o containsExchangeGroup(String)
Searchs the collection for the named exchange group.
 o findExchangeGroup(String)
Finds the named exchange group and returns it.
 o getExchange(String, String)
Starting with the first entry in the exchange group collection, the factory traverses until it finds an exchange group which can create an exchange object.
 o getExchangeGroupAt(int)
Returns the exchange group at the specified index.
 o getExchangeGroupIndex(String)
Finds the named exchange group and returns its position in the collection.
 o getExchangeGroups()
Returns a vector of exchange groups.
 o getExchangeRateTable()
Returns the factory's exchange rate table.
 o getFirstExchangeGroup()
Returns the first exchange group.
 o getLastExchangeGroup()
Returns the last exchange group.
 o insertExchangeGroupAt(ExchangeGroup, int)
Inserts the exchange group at the desired position in the collection of exchange groups.
 o numberOfExchangeGroups()
Returns the number of exchange groups.
 o prependExchangeGroup(ExchangeGroup)
Prepends the exchange group to the collection of exchange groups.
 o removeExchangeGroup(String)
Removes the named exchange group.
 o removeExchangeGroupAt(int)
Removes the exchange group at the specified position.
 o removeFirstExchangeGroup()
Removes the first exchange group.
 o removeLastExchangeGroup()
Removes the last exchange group.
 o setExchangeGroups(Vector)
Sets the vector of exchange groups.
 o setExchangeRateTable(ExchangeRateTable)
Sets the factory's exchange rate table.

Variables

 o NOT_FOUND
 public static final int NOT_FOUND
Index returned when an exchange group cannot be found.

Constructors

 o ExchangeFactory
 public ExchangeFactory()
Creates an exchange factory with the default bilateral multiplication group and an empty exchange rate table.

 o ExchangeFactory
 public ExchangeFactory(ExchangeRateTable table)
Creates an exchange factory with the default bilateral multiplication group and the given exchange rate table.

Parameters:
table - an exchange rate table
See Also:
ExchangeRateTable

Methods

 o getExchangeGroups
 public Vector getExchangeGroups()
Returns a vector of exchange groups.

Returns:
the exchange groups
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o setExchangeGroups
 public void setExchangeGroups(Vector groups)
Sets the vector of exchange groups. Note: Will clear the current exchange groups.

Parameters:
groups - the new exchange groups
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o getExchange
 public Exchange getExchange(String source,
                             String target)
Starting with the first entry in the exchange group collection, the factory traverses until it finds an exchange group which can create an exchange object.

Parameters:
source - original source currency
target - desired target currency
Returns:
A valid exchange object, or, a null value.
See Also:
Exchange, MultiplicationExchange, DivisionExchange, TriangularExchange
 o containsExchangeGroup
 public boolean containsExchangeGroup(String name)
Searchs the collection for the named exchange group.

Parameters:
name - the name of the exchange group
Returns:
whether the named group exists or not
See Also:
Exchange, MultiplicationExchange, DivisionExchange, TriangularExchange
 o findExchangeGroup
 public ExchangeGroup findExchangeGroup(String name)
Finds the named exchange group and returns it. For example, to retrieve the multiplication group, you can use:

ExchangeGroup multGroup = myFactory.findExchangeGroup(MultiplicationGroup.NAME);

Parameters:
name - the name of the desired group.
Returns:
the exchange group or, if not found, a null value.
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o getExchangeGroupIndex
 public int getExchangeGroupIndex(String name)
Finds the named exchange group and returns its position in the collection. For example, to retrieve the multiplication group index, you can use:

 int multIndex = myFactory.findExchangeGroupIndex(MultiplicationGroup.NAME);
 if(multIndex != ExchangeFactory.NOT_FOUND) {
   // do something
 }
 

Parameters:
name - the name of the desired group.
Returns:
The index of the exchange group (starts at zero). If not found, then NOT_FOUND is returned.
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup, NOT_FOUND
 o clearExchangeGroups
 public void clearExchangeGroups()
Removes all exchange groups.

See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o numberOfExchangeGroups
 public int numberOfExchangeGroups()
Returns the number of exchange groups.

Returns:
the number of groups
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o getFirstExchangeGroup
 public ExchangeGroup getFirstExchangeGroup()
Returns the first exchange group.

Returns:
the first group
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o getLastExchangeGroup
 public ExchangeGroup getLastExchangeGroup()
Returns the last exchange group.

Returns:
the last group
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o getExchangeGroupAt
 public ExchangeGroup getExchangeGroupAt(int index)
Returns the exchange group at the specified index.

Parameters:
index - the index of the desired exchange group (starts at zero)
Returns:
the exchange group
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o appendExchangeGroup
 public synchronized void appendExchangeGroup(ExchangeGroup group)
Appends the exchange group to the collection of exchange groups.

Parameters:
group - the new exchange group
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o insertExchangeGroupAt
 public synchronized void insertExchangeGroupAt(ExchangeGroup group,
                                                int index)
Inserts the exchange group at the desired position in the collection of exchange groups.

Parameters:
group - the new exchange group
index - the desired position
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o prependExchangeGroup
 public synchronized void prependExchangeGroup(ExchangeGroup group)
Prepends the exchange group to the collection of exchange groups.

Parameters:
group - the new exchange group
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o removeExchangeGroup
 public synchronized boolean removeExchangeGroup(String name)
Removes the named exchange group.

Parameters:
name - the group to remove
Returns:
whether the exchange group was found or not
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o removeExchangeGroupAt
 public synchronized ExchangeGroup removeExchangeGroupAt(int index)
Removes the exchange group at the specified position.

Parameters:
index - the position
Returns:
the group that was at the specified position.
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o removeFirstExchangeGroup
 public synchronized ExchangeGroup removeFirstExchangeGroup()
Removes the first exchange group.

Returns:
the group that was at the first position.
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o removeLastExchangeGroup
 public synchronized ExchangeGroup removeLastExchangeGroup()
Removes the last exchange group.

Returns:
the group that was at the last position.
See Also:
ExchangeGroup, MultiplicationGroup, DivisionGroup, EuroGroup
 o getExchangeRateTable
 public ExchangeRateTable getExchangeRateTable()
Returns the factory's exchange rate table.

Returns:
the exchange rate table or, if non-existent, the null value
See Also:
ExchangeRateTable
 o setExchangeRateTable
 public void setExchangeRateTable(ExchangeRateTable table)
Sets the factory's exchange rate table. Note: Replaces the current table.

Parameters:
table - the new exchange rate table
See Also:
ExchangeRateTable

All Packages  Class Hierarchy  This Package  Previous  Next  Index