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:
parent
4ba041f2d9
commit
7497e11ee3
@ -94,8 +94,21 @@ fun String?.fromStringToMoney(): StdMoney {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun StdMoney.isMatchedCurrency(currency: StdMoney.Currency) =
|
// check the money currency
|
||||||
this.getCurrency().getCurrency().equals(currency.getCurrency(), ignoreCase = true)
|
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(
|
inline fun buildMoneyConfigProperties(
|
||||||
builderAction: MoneyConfig.MoneyConfigProperties.MoneyConfigPropertiesBuilder.() -> Unit
|
builderAction: MoneyConfig.MoneyConfigProperties.MoneyConfigPropertiesBuilder.() -> Unit
|
||||||
|
9
src/main/kotlin/com/cubetiqs/money/MoneyMixin.kt
Normal file
9
src/main/kotlin/com/cubetiqs/money/MoneyMixin.kt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.cubetiqs.money
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money Mixin Interface
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
* @author sombochea
|
||||||
|
*/
|
||||||
|
interface MoneyMixin
|
@ -8,15 +8,15 @@ import java.util.*
|
|||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @author sombochea
|
* @author sombochea
|
||||||
*/
|
*/
|
||||||
class MoneyObject(
|
open class MoneyObject(
|
||||||
private var value: Double,
|
private var value: Double,
|
||||||
private var currency: String,
|
private var currency: String,
|
||||||
|
|
||||||
// operator, used with "with" below
|
// operator, used with "with" below
|
||||||
// example: if we have next we will use this operator to compute the value with
|
// 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
|
// the value to compute with current object
|
||||||
var with: MoneyObject? = null,
|
private var with: MoneyObject? = null,
|
||||||
) : StdMoney {
|
) : StdMoney {
|
||||||
override fun getCurrency(): StdMoney.Currency {
|
override fun getCurrency(): StdMoney.Currency {
|
||||||
return StdMoney.initCurrency(currency)
|
return StdMoney.initCurrency(currency)
|
||||||
@ -26,6 +26,9 @@ class MoneyObject(
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun getOperator(): MoneyOperator? = operator
|
||||||
|
open fun getWith(): MoneyObject? = with
|
||||||
|
|
||||||
fun appendWithNext(with: MoneyObject?) {
|
fun appendWithNext(with: MoneyObject?) {
|
||||||
if (with == null) {
|
if (with == null) {
|
||||||
return
|
return
|
||||||
|
@ -7,7 +7,7 @@ package com.cubetiqs.money
|
|||||||
* @author sombochea
|
* @author sombochea
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
interface StdMoney {
|
interface StdMoney : MoneyMixin {
|
||||||
/**
|
/**
|
||||||
* Get money's value from current state.
|
* Get money's value from current state.
|
||||||
*
|
*
|
||||||
@ -27,6 +27,10 @@ interface StdMoney {
|
|||||||
*/
|
*/
|
||||||
interface Currency {
|
interface Currency {
|
||||||
fun getCurrency(): String
|
fun getCurrency(): String
|
||||||
|
|
||||||
|
fun isEquals(other: Currency): Boolean {
|
||||||
|
return this.getCurrency().equals(other.getCurrency(), ignoreCase = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ExchangeOperator {
|
interface ExchangeOperator {
|
||||||
|
Loading…
Reference in New Issue
Block a user