🎨 Replace post count comparator with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / data / Sone.kt
index 78a17f5..c44d6e8 100644 (file)
@@ -37,3 +37,14 @@ val niceNameComparator: Comparator<Sone> =
 @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()