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>() {
@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()
"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()