money-module/src/main/kotlin/com/cubetiqs/money/MoneyObject.kt
Sambo Chea 31760ee901 Add and updated for whole the money modules with new style and some operators and computation
But money object not full implementation yet, because we need the exchange and filter the object states for money
2021-02-08 12:39:52 +07:00

47 lines
1.1 KiB
Kotlin

package com.cubetiqs.money
import java.io.Serializable
sealed class MoneyObject : Serializable, StdMoney {
private var value: Double = 0.0
private var currency: MoneyCurrency = MoneyCurrency.USD
private val moneyStates: MutableMap<MoneyCurrency, MoneyState> = mutableMapOf()
constructor(value: Double, currency: MoneyCurrency) {
this.value = value
this.currency = currency
isComputed = false
}
/**
* Check if computed, set it to true. Because we no need to add the same value again after once
* computed.
*/
@Transient
var isComputed = false
private set
@Transient
var isInit = false
private set
/** Calculate the value. Must be call after complete add money. */
fun compute(): MoneyObject = apply {
}
companion object {
@JvmStatic
private fun defaultCurrency(): MoneyCurrency {
return MoneyExchangeUtils.getBaseCurrency()
}
}
override fun getMoneyValue(): Double {
return value
}
override fun getMoneyCurrency(): StdMoney.Currency {
return currency
}
}