Minor: some minor tweaks to IRSUtils types

This commit is contained in:
Mike Hearn 2016-07-27 14:37:32 +02:00
parent 889b74ca9b
commit 62e91000e9

View File

@ -11,21 +11,10 @@ import java.util.*
/**
* A utility class to prevent the various mixups between percentages, decimals, bips etc.
*/
open class RatioUnit(value: BigDecimal) { // TODO: Discuss this type
val value = value
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
other as RatioUnit
if (value != other.value) return false
return true
}
open class RatioUnit(val value: BigDecimal) { // TODO: Discuss this type
override fun equals(other: Any?) = (other as? RatioUnit)?.value == value
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
}
/**
@ -63,21 +52,16 @@ open class Rate(val ratioUnit: RatioUnit? = null) {
* for equality.
*/
override fun hashCode() = ratioUnit?.hashCode() ?: 0
override fun toString() = ratioUnit.toString()
}
/**
* A very basic subclass to represent a fixed rate.
*/
class FixedRate(ratioUnit: RatioUnit) : Rate(ratioUnit) {
constructor(otherRate: Rate) : this(ratioUnit = otherRate.ratioUnit!!)
override fun toString(): String = "$ratioUnit"
fun isPositive(): Boolean = ratioUnit!!.value > BigDecimal("0.0")
override fun equals(other: Any?) = other?.javaClass == javaClass && super.equals(other)
override fun hashCode() = super.hashCode()
}