From afa3d007f883a710a94f74d21c179a006974bc7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 16 Feb 2020 20:48:44 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Replace=20last=20activity=20compa?= =?utf8?q?rator=20with=20Kotlin=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/data/Sone.java | 9 --------- src/main/kotlin/net/pterodactylus/sone/data/Sone.kt | 8 ++++++++ .../kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 1143501..fa6f980 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -62,15 +62,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { downloading, } - /** Comparator that sorts Sones by last activity (least recent active first). */ - public static final Comparator LAST_ACTIVITY_COMPARATOR = new Comparator() { - - @Override - public int compare(Sone firstSone, Sone secondSone) { - return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, secondSone.getTime() - firstSone.getTime())); - } - }; - /** Comparator that sorts Sones by numbers of posts (descending). */ public static final Comparator POST_COUNT_COMPARATOR = new Comparator() { diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt index eb67dff..78a17f5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt @@ -29,3 +29,11 @@ private val caseInsensitiveCompare = { left: String, right: String -> left.compa @get:JvmName("niceNameComparator") // TODO: remove once Sone is 100% Kotlin val niceNameComparator: Comparator = comparing(SoneAccessor::getNiceName, caseInsensitiveCompare).thenComparing(Sone::id) + +/** + * Comparator that sorts Sones by their [last activity][Sone.getTime], least + * recently active Sones first. + */ +@get:JvmName("lastActivityComparator") // TODO: remove once Sone is 100% Kotlin +val lastActivityComparator: Comparator = + comparing(Sone::getTime).reversed() diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt index 260f35b..439a163 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt @@ -31,7 +31,7 @@ class KnownSonesPage @Inject constructor(webInterface: WebInterface, loaders: Lo "images" -> Sone.IMAGE_COUNT_COMPARATOR "name" -> niceNameComparator.reversed() "posts" -> Sone.POST_COUNT_COMPARATOR - else -> Sone.LAST_ACTIVITY_COMPARATOR + else -> lastActivityComparator }.let { comparator -> when (soneRequest.parameters["order"]) { "asc" -> comparator.reversed() -- 2.7.4