Add money create for static funcs
This commit is contained in:
parent
a8841a537d
commit
377809383d
@ -24,5 +24,27 @@ open class Money(
|
|||||||
companion object {
|
companion object {
|
||||||
val ZERO: StdMoney
|
val ZERO: StdMoney
|
||||||
get() = Money(value = 0.0)
|
get() = Money(value = 0.0)
|
||||||
|
val ONE: StdMoney
|
||||||
|
get() = Money(value = 1.0)
|
||||||
|
val TEN: StdMoney
|
||||||
|
get() = Money(value = 10.0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new money object with custom value
|
||||||
|
*
|
||||||
|
* @param value Double
|
||||||
|
* @param currency String
|
||||||
|
*/
|
||||||
|
fun create(value: Double, currency: String = MoneyCurrency.USD.name): StdMoney {
|
||||||
|
return Money(value = value, currency = currency)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new money object with custom value
|
||||||
|
*
|
||||||
|
* @param value Double
|
||||||
|
* @param currency MoneyCurrency
|
||||||
|
*/
|
||||||
|
fun create(value: Double, currency: MoneyCurrency = MoneyCurrency.USD): StdMoney = create(value, currency.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.cubetiqs.libra.moneyutils
|
||||||
|
|
||||||
|
enum class MoneyCurrency {
|
||||||
|
USD,
|
||||||
|
KHR,
|
||||||
|
EUR
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import com.cubetiqs.libra.moneyutils.Money
|
import com.cubetiqs.libra.moneyutils.Money
|
||||||
import com.cubetiqs.libra.moneyutils.MoneyConfig
|
import com.cubetiqs.libra.moneyutils.MoneyConfig
|
||||||
|
import com.cubetiqs.libra.moneyutils.MoneyCurrency
|
||||||
import com.cubetiqs.libra.moneyutils.MoneyExchangeUtils
|
import com.cubetiqs.libra.moneyutils.MoneyExchangeUtils
|
||||||
import com.cubetiqs.libra.moneyutils.plus
|
import com.cubetiqs.libra.moneyutils.plus
|
||||||
import com.cubetiqs.libra.moneyutils.times
|
import com.cubetiqs.libra.moneyutils.times
|
||||||
@ -39,4 +40,18 @@ class MoneyTests {
|
|||||||
|
|
||||||
Assert.assertEquals(8000.0, moneyKhr.getMoneyValue(), 0.0)
|
Assert.assertEquals(8000.0, moneyKhr.getMoneyValue(), 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun money_exchange_config_builder_test() {
|
||||||
|
MoneyConfig.propertiesBuilder
|
||||||
|
.setDeliEqual('=')
|
||||||
|
.setDeliSplit(';')
|
||||||
|
|
||||||
|
MoneyConfig.parse("USD=1,KHR=4000,EUR=0.99")
|
||||||
|
|
||||||
|
val moneyUsd = Money.ONE
|
||||||
|
val moneyKhr = Money.create(20000.0, MoneyCurrency.KHR)
|
||||||
|
|
||||||
|
val result = moneyUsd
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user