public class CurrencyConverter
Singleton object that handles the exchanging of monetary values from one currency to another.
Modifier and Type | Field and Description |
---|---|
static CurrencyConverter |
INSTANCE
Singleton object that handles the exchanging of monetary values from one currency to another.
|
Modifier and Type | Method and Description |
---|---|
java.math.BigDecimal |
convertValue(java.math.BigDecimal value,
Currency source,
Currency destination)
Converts a value from one currency to another.
|
java.util.Map<net.namibsun.papio.lib.money.Currency,java.math.BigDecimal> |
generateCache()
Sets the cache to the current exchange rates and return that value.
|
java.util.Map<net.namibsun.papio.lib.money.Currency,java.math.BigDecimal> |
getExchangeRateData() |
boolean |
getNetworkDisabled()
Can be set to true to disable any network operations.
Originally added to enable testing the caching functionality.
|
boolean |
isValid()
Checks if the values are currently valid
|
void |
setCache(java.util.Map<net.namibsun.papio.lib.money.Currency,java.math.BigDecimal> cache)
Sets the cache variable as a fallback for currency exchange rates that could not be found
|
void |
setCacheFile(java.io.File cacheFile)
Sets the cache file. This file will be used to store cached exchange rates
|
void |
setNetworkDisabled(boolean p)
Can be set to true to disable any network operations.
Originally added to enable testing the caching functionality.
|
void |
update(boolean force,
boolean reset)
Updates the exchange rate data. Will only update if more than a minute has passed since
the last update or if the force variable is set to true.
|
public static CurrencyConverter INSTANCE
Singleton object that handles the exchanging of monetary values from one currency to another.
public boolean getNetworkDisabled()
Can be set to true to disable any network operations. Originally added to enable testing the caching functionality.
public void setNetworkDisabled(boolean p)
Can be set to true to disable any network operations. Originally added to enable testing the caching functionality.
public java.util.Map<net.namibsun.papio.lib.money.Currency,java.math.BigDecimal> getExchangeRateData()
public void setCacheFile(java.io.File cacheFile)
Sets the cache file. This file will be used to store cached exchange rates
cacheFile
- : The file in which to store the cached datapublic void setCache(java.util.Map<net.namibsun.papio.lib.money.Currency,java.math.BigDecimal> cache)
Sets the cache variable as a fallback for currency exchange rates that could not be found
cache
- : The cache to setpublic java.util.Map<net.namibsun.papio.lib.money.Currency,java.math.BigDecimal> generateCache()
Sets the cache to the current exchange rates and return that value.
public boolean isValid()
Checks if the values are currently valid
public void update(boolean force, boolean reset)
Updates the exchange rate data. Will only update if more than a minute has passed since the last update or if the force variable is set to true.
force
- : Forces an update if set to truereset
- : Resets the internal exchange rate data before updatingpublic java.math.BigDecimal convertValue(java.math.BigDecimal value, Currency source, Currency destination)
Converts a value from one currency to another.
value
- : The value to convertsource
- : The source currency from which to convert fromdestination
- : The destination currency into which to convert to