🎨 Replace image count comparator with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / data / Sone.kt
index eb67dff..3f70ad7 100644 (file)
@@ -29,3 +29,25 @@ 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()
+
+/**
+ * Comparator that sorts Sones by their [post count][Sone.getPosts] (most posts
+ * first) and, failing that, by their [reply count][Sone.getReplies] (most
+ * replies first).
+ */
+@get:JvmName("postCountComparator") // TODO: remove once Sone is 100% Kotlin
+val postCountComparator: Comparator<Sone> =
+               comparing<Sone, Int> { it.posts.size }
+                               .thenComparing<Int> { it.replies.size }
+                               .reversed()
+
+val imageCountComparator: Comparator<Sone> =
+               comparing<Sone, Int> { it.rootAlbum.allImages.size }.reversed()