moneyutils/src/main/kotlin/com/cubetiqs/libra/moneyutils/Money.kt

29 lines
655 B
Kotlin
Raw Normal View History

2020-08-26 20:02:36 +07:00
package com.cubetiqs.libra.moneyutils
2020-08-26 21:19:31 +07:00
open class Money(
2020-08-26 21:32:06 +07:00
var value: Double,
private var currency: String = "USD"
2020-08-26 21:19:31 +07:00
) : StdMoney {
2020-08-26 20:02:36 +07:00
2020-08-26 21:32:06 +07:00
//////////////////// - PROPERTIES - ////////////////////
override fun getMoneyValue(): Double {
return this.value
2020-08-26 21:19:31 +07:00
}
2020-08-26 21:32:06 +07:00
override fun getMoneyCurrency(): String {
2020-08-26 21:19:31 +07:00
return this.currency.toUpperCase()
}
2020-08-26 21:32:06 +07:00
//////////////////// - GENERIC - ////////////////////
2020-08-26 21:19:31 +07:00
override fun toString(): String {
2020-08-26 21:32:06 +07:00
return "Money(value=${getMoneyValue()}, currency='${getMoneyCurrency()}')"
2020-08-26 21:19:31 +07:00
}
companion object {
val ZERO: StdMoney
get() = Money(value = 0.0)
}
2020-08-26 21:19:31 +07:00
}