make LimitStatus and Limits to be comparable

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

View File

@ -2,6 +2,9 @@
## 0.14.0
* `LimitStatus` is `Comparable<LimitStatus>` since this update
* `Limits` is `Comparable<Limits>` since this update
## 0.13.0
* Versions:

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip

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)
}