From 7727d2400e99a022d24fb4d74039542434d61339 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 22 Dec 2022 13:25:34 +0600 Subject: [PATCH] make LimitStatus and Limits to be comparable --- CHANGELOG.md | 3 +++ gradle/wrapper/gradle-wrapper.properties | 2 +- .../additional/header/AccountInfo.kt | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2208003..ac432b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.14.0 +* `LimitStatus` is `Comparable` since this update +* `Limits` is `Comparable` since this update + ## 0.13.0 * Versions: diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0e98979..ae83846 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/src/commonMain/kotlin/dev/inmo/saucenaoapi/additional/header/AccountInfo.kt b/src/commonMain/kotlin/dev/inmo/saucenaoapi/additional/header/AccountInfo.kt index d9603d6..bb48d99 100644 --- a/src/commonMain/kotlin/dev/inmo/saucenaoapi/additional/header/AccountInfo.kt +++ b/src/commonMain/kotlin/dev/inmo/saucenaoapi/additional/header/AccountInfo.kt @@ -29,15 +29,27 @@ val Header.accountInfo data class LimitStatus( val remain: Int = Int.MAX_VALUE, val limit: Int = Int.MAX_VALUE -) +) : Comparable { + 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 { + 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 { + override fun compareTo(other: AccountInfo): Int = limits.compareTo(other.limits) +}