X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.kt;h=34403a16c46231e5026ed12556ad97adf9878caf;hp=0000000000000000000000000000000000000000;hb=5c5bee980f9cab5792e34d1c9840f73b8b191830;hpb=faf66247a34f64946990a985d2ea3003465969cb diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt new file mode 100644 index 0000000..34403a1 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt @@ -0,0 +1,61 @@ +/** + * Sone - Sone.kt - Copyright © 2020 David ‘Bombe’ Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.data + +import net.pterodactylus.sone.template.* +import java.util.Comparator.* + +private val caseInsensitiveCompare = { left: String, right: String -> left.compareTo(right, true) } + +/** + * Comparator that sorts Sones by their [nice name][SoneAccessor.getNiceName] + * and, failing that, by [ID][Sone.id]. + */ +@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() + +/** + * 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