projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7be5373
)
🎨 Replace last activity comparator with Kotlin version
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sun, 16 Feb 2020 19:48:44 +0000
(20:48 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sun, 16 Feb 2020 19:48:44 +0000
(20:48 +0100)
src/main/java/net/pterodactylus/sone/data/Sone.java
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/data/Sone.kt
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/data/Sone.java
b/src/main/java/net/pterodactylus/sone/data/Sone.java
index
1143501
..
fa6f980
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Sone.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Sone.java
@@
-62,15
+62,6
@@
public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
downloading,
}
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>() {
/** Comparator that sorts Sones by numbers of posts (descending). */
public static final Comparator<Sone> POST_COUNT_COMPARATOR = new Comparator<Sone>() {
diff --git
a/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt
b/src/main/kotlin/net/pterodactylus/sone/data/Sone.kt
index
eb67dff
..
78a17f5
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/data/Sone.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/data/Sone.kt
@@
-29,3
+29,11
@@
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)
@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()
diff --git
a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt
b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt
index
260f35b
..
439a163
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt
@@
-31,7
+31,7
@@
class KnownSonesPage @Inject constructor(webInterface: WebInterface, loaders: Lo
"images" -> Sone.IMAGE_COUNT_COMPARATOR
"name" -> niceNameComparator.reversed()
"posts" -> Sone.POST_COUNT_COMPARATOR
"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()
}.let { comparator ->
when (soneRequest.parameters["order"]) {
"asc" -> comparator.reversed()