Compare commits

..

2 Commits

3 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,8 @@
package com.cubetiqs.money
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
/**
* Default money config in static object.
* Sample parse format: USD=1,KHR=4000,EUR=0.99
@ -14,10 +17,10 @@ object MoneyConfig {
* Key is the currency
* Value is the rate
*/
private val config: MutableMap<String, Double> = mutableMapOf()
private val config: ConcurrentMap<String, Double> = ConcurrentHashMap()
// use to format the money for each value, if have
private val configFormatter: MutableMap<String, MoneyFormatProvider> = mutableMapOf()
private val configFormatter: ConcurrentMap<String, MoneyFormatProvider> = ConcurrentHashMap()
// use to identified for config dataset with prefix mode
private var configPrefix: String = ""

View File

@ -1,5 +1,7 @@
package com.cubetiqs.money
import java.util.*
infix fun StdMoney.exchangeTo(currency: StdMoney.Currency): StdMoney {
return MoneyExchangeUtils.exchange(this, currency)
}
@ -126,4 +128,9 @@ fun MoneyView.asStdMoney(): StdMoney {
return this@asStdMoney.getValue()
}
}
}
// detect currency symbol, if needed
fun StdMoney.Currency.findCurrency(): Currency? {
return Currency.getInstance(this.getCurrency())
}

View File

@ -4,9 +4,12 @@ open class MoneyView(
private var value: Number? = null,
private var currency: String? = null,
) : MoneyMixin {
private var _currency: StdMoney.Currency? = null
constructor(money: StdMoney) : this() {
this._currency = money.getCurrency()
this.value = money.getValue()
this.currency = money.getCurrency().getCurrency()
this.currency = this._currency?.getCurrency()
}
fun getValue(): Double {
@ -17,6 +20,10 @@ open class MoneyView(
return currency
}
fun getSymbol(): String? {
return this._currency?.findCurrency()?.symbol
}
fun getFormat(): String {
return MoneyConfig
.getFormatter(getCurrency())