Add money mixin cast to and updated money extension and add money view for view in web deployer and try to updated and look around the casting

This commit is contained in:
Sambo Chea 2021-02-09 09:38:11 +07:00
parent 4ba041f2d9
commit 7497e11ee3
4 changed files with 35 additions and 6 deletions

View File

@ -94,8 +94,21 @@ fun String?.fromStringToMoney(): StdMoney {
}
}
fun StdMoney.isMatchedCurrency(currency: StdMoney.Currency) =
this.getCurrency().getCurrency().equals(currency.getCurrency(), ignoreCase = true)
// check the money currency
fun StdMoney.isMatchedCurrency(currency: StdMoney.Currency) = this.getCurrency().isEquals(currency)
// transfer to any money mixin
fun StdMoney.tryToCastToMixin(): MoneyMixin {
return object : MoneyMixin {
fun getValue(): Double {
return this@tryToCastToMixin.getValue()
}
fun getCurrency(): String {
return this@tryToCastToMixin.getCurrency().getCurrency()
}
}
}
inline fun buildMoneyConfigProperties(
builderAction: MoneyConfig.MoneyConfigProperties.MoneyConfigPropertiesBuilder.() -> Unit

View File

@ -0,0 +1,9 @@
package com.cubetiqs.money
/**
* Money Mixin Interface
*
* @since 1.0
* @author sombochea
*/
interface MoneyMixin

View File

@ -8,15 +8,15 @@ import java.util.*
* @since 1.0
* @author sombochea
*/
class MoneyObject(
open class MoneyObject(
private var value: Double,
private var currency: String,
// operator, used with "with" below
// example: if we have next we will use this operator to compute the value with
var operator: MoneyOperator? = null,
private var operator: MoneyOperator? = null,
// the value to compute with current object
var with: MoneyObject? = null,
private var with: MoneyObject? = null,
) : StdMoney {
override fun getCurrency(): StdMoney.Currency {
return StdMoney.initCurrency(currency)
@ -26,6 +26,9 @@ class MoneyObject(
return value
}
open fun getOperator(): MoneyOperator? = operator
open fun getWith(): MoneyObject? = with
fun appendWithNext(with: MoneyObject?) {
if (with == null) {
return

View File

@ -7,7 +7,7 @@ package com.cubetiqs.money
* @author sombochea
* @since 1.0
*/
interface StdMoney {
interface StdMoney : MoneyMixin {
/**
* Get money's value from current state.
*
@ -27,6 +27,10 @@ interface StdMoney {
*/
interface Currency {
fun getCurrency(): String
fun isEquals(other: Currency): Boolean {
return this.getCurrency().equals(other.getCurrency(), ignoreCase = true)
}
}
interface ExchangeOperator {