X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.kt;h=34403a16c46231e5026ed12556ad97adf9878caf;hb=HEAD;hp=78a17f55ddcbefa75f0998218931821b4c8a1afb;hpb=afa3d007f883a710a94f74d21c179a006974bc7e;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt index 78a17f5..34403a1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt +++ b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt @@ -37,3 +37,25 @@ val niceNameComparator: Comparator = @get:JvmName("lastActivityComparator") // TODO: remove once Sone is 100% Kotlin val lastActivityComparator: Comparator = 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 = + comparing { it.posts.size } + .thenComparing { it.replies.size } + .reversed() + +val imageCountComparator: Comparator = + comparing { it.rootAlbum.allImages.size }.reversed() + +val Sone.allAlbums: List + get() = + rootAlbum.albums.flatMap(Album::allAlbums) + +val Sone.allImages: Collection + get() = + rootAlbum.allImages