make LimitStatus and Limits to be comparable

This commit is contained in:
2022-12-22 13:25:34 +06:00
parent eec32de472
commit 7727d2400e
3 changed files with 19 additions and 4 deletions

View File

@@ -29,15 +29,27 @@ val Header.accountInfo
data class LimitStatus(
val remain: Int = Int.MAX_VALUE,
val limit: Int = Int.MAX_VALUE
)
) : Comparable<LimitStatus> {
override fun compareTo(other: LimitStatus): Int = when {
limit == other.limit && remain == other.remain -> 0
else -> remain.compareTo(other.remain)
}
}
data class Limits(
val short: LimitStatus = LimitStatus(),
val long: LimitStatus = LimitStatus()
)
) : Comparable<Limits> {
override fun compareTo(other: Limits): Int = when {
long == other.long && short == other.short -> 0
else -> short.remain.compareTo(other.short.remain)
}
}
data class AccountInfo(
val accountType: AccountType = defaultAccountType,
val userId: UserId? = null,
val limits: Limits = Limits()
)
) : Comparable<AccountInfo> {
override fun compareTo(other: AccountInfo): Int = limits.compareTo(other.limits)
}