Updated
This commit is contained in:
parent
aaf3c6aea8
commit
6deb73600d
@ -34,7 +34,7 @@ object MoneyConfig {
|
|||||||
// use to custom locales and allow to detect auto formatter, if enable auto locale format
|
// use to custom locales and allow to detect auto formatter, if enable auto locale format
|
||||||
private val configLocales: ConcurrentMap<String, Locale> = ConcurrentHashMap(LOCALES_INITIAL_SIZE)
|
private val configLocales: ConcurrentMap<String, Locale> = ConcurrentHashMap(LOCALES_INITIAL_SIZE)
|
||||||
|
|
||||||
// use to custom currencies and allow to detect auto, when use auto detect for currencies translate
|
// use to custom currencies and allow to detect auto, when use auto-detect for currencies translate
|
||||||
private val configCurrencies: ConcurrentMap<String, Currency> = ConcurrentHashMap(CURRENCIES_INITIAL_SIZE)
|
private val configCurrencies: ConcurrentMap<String, Currency> = ConcurrentHashMap(CURRENCIES_INITIAL_SIZE)
|
||||||
|
|
||||||
// allow to use config of any states
|
// allow to use config of any states
|
||||||
@ -165,7 +165,7 @@ object MoneyConfig {
|
|||||||
.split(getProperties().deliEqual)
|
.split(getProperties().deliEqual)
|
||||||
if (temp.size == 2) {
|
if (temp.size == 2) {
|
||||||
val currency = temp[0]
|
val currency = temp[0]
|
||||||
.toUpperCase()
|
.uppercase()
|
||||||
.trim()
|
.trim()
|
||||||
val key = getConfigKey(currency)
|
val key = getConfigKey(currency)
|
||||||
val value = temp[1].toDouble()
|
val value = temp[1].toDouble()
|
||||||
@ -185,7 +185,7 @@ object MoneyConfig {
|
|||||||
// append the rate into dataset
|
// append the rate into dataset
|
||||||
// for config key are completed change inside
|
// for config key are completed change inside
|
||||||
fun appendRate(currency: String, rate: Double) = apply {
|
fun appendRate(currency: String, rate: Double) = apply {
|
||||||
val currencyKey = currency.toUpperCase().trim()
|
val currencyKey = currency.uppercase().trim()
|
||||||
val key = getConfigKey(currencyKey)
|
val key = getConfigKey(currencyKey)
|
||||||
if (configRates.containsKey(key)) {
|
if (configRates.containsKey(key)) {
|
||||||
configRates.replace(key, rate)
|
configRates.replace(key, rate)
|
||||||
@ -224,7 +224,7 @@ object MoneyConfig {
|
|||||||
|
|
||||||
@Throws(MoneyCurrencyStateException::class)
|
@Throws(MoneyCurrencyStateException::class)
|
||||||
fun getRate(currency: StdMoney.Currency): Double {
|
fun getRate(currency: StdMoney.Currency): Double {
|
||||||
return getConfigRates()[getConfigKey(currency.getCurrency().toUpperCase().trim())]
|
return getConfigRates()[getConfigKey(currency.getCurrency().uppercase().trim())]
|
||||||
?: if (fallbackRate > 0) fallbackRate else throw MoneyCurrencyStateException("money currency ${currency.getCurrency()} is not valid!")
|
?: if (fallbackRate > 0) fallbackRate else throw MoneyCurrencyStateException("money currency ${currency.getCurrency()} is not valid!")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ object MoneyConfig {
|
|||||||
|
|
||||||
// add money formatter by currency of each money value
|
// add money formatter by currency of each money value
|
||||||
fun addFormatter(currency: String, formatter: MoneyFormatProvider) = apply {
|
fun addFormatter(currency: String, formatter: MoneyFormatProvider) = apply {
|
||||||
val key = getConfigKey(currency.toUpperCase().trim())
|
val key = getConfigKey(currency.uppercase().trim())
|
||||||
if (configFormatter.containsKey(key)) {
|
if (configFormatter.containsKey(key)) {
|
||||||
configFormatter.replace(key, formatter)
|
configFormatter.replace(key, formatter)
|
||||||
} else {
|
} else {
|
||||||
@ -318,7 +318,7 @@ object MoneyConfig {
|
|||||||
fun getFormatter(currency: String? = null): MoneyFormatter {
|
fun getFormatter(currency: String? = null): MoneyFormatter {
|
||||||
// apply default formatter
|
// apply default formatter
|
||||||
val formatter = (if (!currency.isNullOrEmpty()) {
|
val formatter = (if (!currency.isNullOrEmpty()) {
|
||||||
val key = getConfigKey(currency.toUpperCase().trim())
|
val key = getConfigKey(currency.uppercase().trim())
|
||||||
configFormatter[key]
|
configFormatter[key]
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
Loading…
Reference in New Issue
Block a user