🎨 Replace last activity comparator with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 16 Feb 2020 19:48:44 +0000 (20:48 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 16 Feb 2020 19:48:44 +0000 (20:48 +0100)
src/main/java/net/pterodactylus/sone/data/Sone.java
src/main/kotlin/net/pterodactylus/sone/data/Sone.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt

index 1143501..fa6f980 100644 (file)
@@ -62,15 +62,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
                downloading,
        }
 
-       /** Comparator that sorts Sones by last activity (least recent active first). */
-       public static final Comparator<Sone> LAST_ACTIVITY_COMPARATOR = new Comparator<Sone>() {
-
-               @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<Sone> POST_COUNT_COMPARATOR = new Comparator<Sone>() {
 
index eb67dff..78a17f5 100644 (file)
@@ -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<Sone> =
                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<Sone> =
+               comparing(Sone::getTime).reversed()
index 260f35b..439a163 100644 (file)
@@ -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()