From 4dc6ae521c17d97e9aaed65f0911476dd9265928 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Thu, 27 Aug 2020 10:48:31 +0700 Subject: [PATCH] Add money extension and operator --- .../cubetiqs/libra/moneyutils/MoneyExtension.kt | 3 +++ .../cubetiqs/libra/moneyutils/MoneyOperator.kt | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyExtension.kt diff --git a/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyExtension.kt b/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyExtension.kt new file mode 100644 index 0000000..05caf96 --- /dev/null +++ b/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyExtension.kt @@ -0,0 +1,3 @@ +package com.cubetiqs.libra.moneyutils + +fun StdMoney \ No newline at end of file diff --git a/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyOperator.kt b/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyOperator.kt index 83f1bb8..f9a15df 100644 --- a/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyOperator.kt +++ b/src/main/kotlin/com/cubetiqs/libra/moneyutils/MoneyOperator.kt @@ -1,13 +1,12 @@ package com.cubetiqs.libra.moneyutils -operator fun Money.unaryMinus() = (-getMoneyValue()) -operator fun Money.unaryPlus() = (+getMoneyValue()) +operator fun StdMoney.unaryMinus() = (-getMoneyValue()) +operator fun StdMoney.unaryPlus() = (+getMoneyValue()) operator fun Money.inc() = Money(value++) operator fun Money.dec() = Money(value--) -operator fun Money.plus(other: Money) = Money(value + other.value) -operator fun Money.times(other: Money) = Money(value * other.value) -operator fun Money.div(other: Money) = Money(value / other.value) -operator fun Money.timesAssign(other: Money) { - this.value = this.value * other.value -} -operator fun Money.not() = this.value != this.value \ No newline at end of file +operator fun StdMoney.plus(other: StdMoney) = Money(getMoneyValue() + other.getMoneyValue()) +operator fun StdMoney.times(other: StdMoney) = Money(getMoneyValue() * other.getMoneyValue()) +operator fun StdMoney.div(other: StdMoney) = Money(getMoneyValue() / other.getMoneyValue()) +operator fun Money.timesAssign(other: StdMoney) { + this.value = this.getMoneyValue() * other.getMoneyValue() +} \ No newline at end of file