class FileExchangeRateProvider extends java.lang.Object implements ExchangeRateProvider
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
currencyConfigFile |
private ResourceLoader |
loader |
static org.slf4j.Logger |
log |
protected static java.lang.String |
PARAM_CURRENCY_CONFIG |
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Double>> |
rates |
Constructor and Description |
---|
FileExchangeRateProvider() |
Modifier and Type | Method and Description |
---|---|
private void |
addRate(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Double>> ratesMap,
java.lang.String sourceCurrencyCode,
java.lang.String targetCurrencyCode,
double rate)
Registers the specified exchange rate.
|
boolean |
equals(java.lang.Object o) |
double |
getExchangeRate(java.lang.String sourceCurrencyCode,
java.lang.String targetCurrencyCode)
Returns the currently known exchange rate between two currencies.
|
int |
hashCode() |
void |
inform(ResourceLoader loader)
Passes a ResourceLoader, used to read config files from e.g.
|
void |
init(java.util.Map<java.lang.String,java.lang.String> params)
Initializes the provider by passing in a set of key/value configs as a map.
|
java.util.Set<java.lang.String> |
listAvailableCurrencies()
List all configured currency codes which are valid as source/target for this Provider
|
private java.lang.Double |
lookupRate(java.lang.String sourceCurrencyCode,
java.lang.String targetCurrencyCode)
Looks up the current known rate, if any, between the source and target currencies.
|
boolean |
reload()
Ask the currency provider to explicitly reload/refresh its configuration.
|
java.lang.String |
toString() |
public static org.slf4j.Logger log
protected static final java.lang.String PARAM_CURRENCY_CONFIG
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Double>> rates
private java.lang.String currencyConfigFile
private ResourceLoader loader
public double getExchangeRate(java.lang.String sourceCurrencyCode, java.lang.String targetCurrencyCode)
getExchangeRate
in interface ExchangeRateProvider
sourceCurrencyCode
- The source currency being converted from.targetCurrencyCode
- The target currency being converted to.an
- exception if the requested currency pair cannot be foundprivate java.lang.Double lookupRate(java.lang.String sourceCurrencyCode, java.lang.String targetCurrencyCode)
sourceCurrencyCode
- The source currency being converted from.targetCurrencyCode
- The target currency being converted to.private void addRate(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Double>> ratesMap, java.lang.String sourceCurrencyCode, java.lang.String targetCurrencyCode, double rate)
ratesMap
- The map to add rate tosourceCurrencyCode
- The source currency.targetCurrencyCode
- The target currency.rate
- The known exchange rate.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Set<java.lang.String> listAvailableCurrencies()
ExchangeRateProvider
listAvailableCurrencies
in interface ExchangeRateProvider
public boolean reload() throws SolrException
ExchangeRateProvider
reload
in interface ExchangeRateProvider
SolrException
- if there is a problem reloadingpublic void init(java.util.Map<java.lang.String,java.lang.String> params) throws SolrException
ExchangeRateProvider
Important: Custom config params must be removed from the map before returning
init
in interface ExchangeRateProvider
params
- a @Map of key/value config params to initialize the providerSolrException
public void inform(ResourceLoader loader) throws SolrException
ExchangeRateProvider
Typically called after init
inform
in interface ExchangeRateProvider
loader
- a @ResourceLoader instanceSolrException