From: David ‘Bombe’ Roden Date: Sun, 16 Feb 2020 19:48:44 +0000 (+0100) Subject: 🎨 Replace last activity comparator with Kotlin version X-Git-Tag: v82^2~65 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=afa3d007f883a710a94f74d21c179a006974bc7e 🎨 Replace last activity comparator with Kotlin version --- 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()