Add compute rate
This commit is contained in:
parent
ad27257db7
commit
cb28bc0d6a
@ -1,26 +1,23 @@
|
|||||||
package com.cubetiqs.libra.moneyutils
|
package com.cubetiqs.libra.moneyutils
|
||||||
|
|
||||||
open class Money(
|
open class Money(
|
||||||
private var value: Double,
|
var value: Double,
|
||||||
private var currency: String = "USD"
|
var currency: String = "USD"
|
||||||
) : StdMoney {
|
) : StdMoney {
|
||||||
override fun getValue(): Double {
|
|
||||||
|
//////////////////// - PROPERTIES - ////////////////////
|
||||||
|
|
||||||
|
override fun getMoneyValue(): Double {
|
||||||
return this.value
|
return this.value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setValue(value: Double) {
|
override fun getMoneyCurrency(): String {
|
||||||
this.value = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCurrency(): String {
|
|
||||||
return this.currency.toUpperCase()
|
return this.currency.toUpperCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCurrency(currency: String) {
|
//////////////////// - GENERIC - ////////////////////
|
||||||
this.currency = currency
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "Money(value=${getValue()}, currency='${getCurrency()}')"
|
return "Money(value=${getMoneyValue()}, currency='${getMoneyCurrency()}')"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.cubetiqs.libra.moneyutils
|
||||||
|
|
||||||
|
object MoneyExchangeUtils {
|
||||||
|
fun computeRate(rateFrom: Double, rateTo: Double, baseRate: Double = 1.0, amountFrom: Double = 1.0): Double {
|
||||||
|
return amountFrom * ((baseRate / rateFrom) / (baseRate / rateTo))
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.cubetiqs.libra.moneyutils
|
package com.cubetiqs.libra.moneyutils
|
||||||
|
|
||||||
operator fun Money.unaryMinus() = (-value)
|
operator fun Money.unaryMinus() = (-getMoneyValue())
|
||||||
operator fun Money.unaryPlus() = (+value)
|
operator fun Money.unaryPlus() = (+getMoneyValue())
|
||||||
operator fun Money.inc() = Money(value++)
|
operator fun Money.inc() = Money(value++)
|
||||||
operator fun Money.dec() = Money(value--)
|
operator fun Money.dec() = Money(value--)
|
||||||
operator fun Money.plus(other: Money) = Money(value + other.value)
|
operator fun Money.plus(other: Money) = Money(value + other.value)
|
||||||
|
@ -13,12 +13,12 @@ interface StdMoney {
|
|||||||
*
|
*
|
||||||
* @return Double
|
* @return Double
|
||||||
*/
|
*/
|
||||||
fun getValue(): Double
|
fun getMoneyValue(): Double
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get money's currency from current state.
|
* Get money's currency from current state.
|
||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
fun getCurrency(): String
|
fun getMoneyCurrency(): String
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user