projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
9d47ddb
)
🎨 Rename “newest first” post comparator
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sat, 22 Feb 2020 22:31:52 +0000
(23:31 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sat, 22 Feb 2020 22:31:52 +0000
(23:31 +0100)
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/data/Post.kt
patch
|
blob
|
history
src/test/kotlin/net/pterodactylus/sone/data/PostTest.kt
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java
b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java
index
fff3052
..
ffbed4d
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
+++ b/
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
@@
-22,7
+22,7
@@
import static java.lang.System.currentTimeMillis;
import static java.util.concurrent.TimeUnit.*;
import static java.util.logging.Logger.getLogger;
import static java.util.stream.Collectors.toList;
import static java.util.concurrent.TimeUnit.*;
import static java.util.logging.Logger.getLogger;
import static java.util.stream.Collectors.toList;
-import static net.pterodactylus.sone.data.PostKt.newestFirst;
+import static net.pterodactylus.sone.data.PostKt.newest
Post
First;
import java.io.*;
import java.nio.charset.Charset;
import java.io.*;
import java.nio.charset.Charset;
@@
-309,7
+309,7
@@
public class SoneInserter extends AbstractService {
soneProperties.put("name", sone.getName());
soneProperties.put("time", currentTimeMillis());
soneProperties.put("profile", sone.getProfile());
soneProperties.put("name", sone.getName());
soneProperties.put("time", currentTimeMillis());
soneProperties.put("profile", sone.getProfile());
- soneProperties.put("posts", Ordering.from(newestFirst()).sortedCopy(sone.getPosts()));
+ soneProperties.put("posts", Ordering.from(newest
Post
First()).sortedCopy(sone.getPosts()));
soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
soneProperties.put("likedPostIds", new HashSet<>(sone.getLikedPostIds()));
soneProperties.put("likedReplyIds", new HashSet<>(sone.getLikedReplyIds()));
soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
soneProperties.put("likedPostIds", new HashSet<>(sone.getLikedPostIds()));
soneProperties.put("likedReplyIds", new HashSet<>(sone.getLikedReplyIds()));
diff --git
a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java
b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java
index
df8832f
..
9baaba9
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java
@@
-21,7
+21,7
@@
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.logging.Logger.getLogger;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.logging.Logger.getLogger;
-import static net.pterodactylus.sone.data.PostKt.newestFirst;
+import static net.pterodactylus.sone.data.PostKt.newest
Post
First;
import static net.pterodactylus.sone.data.SoneKt.*;
import java.net.MalformedURLException;
import static net.pterodactylus.sone.data.SoneKt.*;
import java.net.MalformedURLException;
@@
-366,7
+366,7
@@
public class SoneImpl implements Sone {
synchronized (this) {
sortedPosts = new ArrayList<>(posts);
}
synchronized (this) {
sortedPosts = new ArrayList<>(posts);
}
- sortedPosts.sort(newestFirst());
+ sortedPosts.sort(newest
Post
First());
return sortedPosts;
}
return sortedPosts;
}
diff --git
a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
index
d340426
..
05c2349
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
+++ b/
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
@@
-32,7
+32,7
@@
import com.google.common.collect.Collections2;
import freenet.support.SimpleFieldSet;
import freenet.support.SimpleFieldSet;
-import static net.pterodactylus.sone.data.PostKt.newestFirst;
+import static net.pterodactylus.sone.data.PostKt.newest
Post
First;
import static net.pterodactylus.sone.data.PostKt.noFuturePost;
/**
import static net.pterodactylus.sone.data.PostKt.noFuturePost;
/**
@@
-73,7
+73,7
@@
public class GetPostFeedCommand extends AbstractSoneCommand {
allPosts = Collections2.filter(allPosts, noFuturePost()::invoke);
List<Post> sortedPosts = new ArrayList<>(allPosts);
allPosts = Collections2.filter(allPosts, noFuturePost()::invoke);
List<Post> sortedPosts = new ArrayList<>(allPosts);
- sortedPosts.sort(newestFirst());
+ sortedPosts.sort(newest
Post
First());
if (sortedPosts.size() < startPost) {
return new Response("PostFeed", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
if (sortedPosts.size() < startPost) {
return new Response("PostFeed", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
diff --git
a/src/main/kotlin/net/pterodactylus/sone/data/Post.kt
b/src/main/kotlin/net/pterodactylus/sone/data/Post.kt
index
955196a
..
d87bd3c
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/data/Post.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/data/Post.kt
@@
-12,5
+12,5
@@
val noFuturePost: (Post) -> Boolean = { it.time <= System.currentTimeMillis() }
/**
* Comparator that orders posts by their time, newest posts first.
*/
/**
* Comparator that orders posts by their time, newest posts first.
*/
-@get:JvmName("newestFirst")
-val newestFirst: Comparator<Post> = comparing(Post::getTime).reversed()
+@get:JvmName("newest
Post
First")
+val newest
Post
First: Comparator<Post> = comparing(Post::getTime).reversed()
diff --git
a/src/test/kotlin/net/pterodactylus/sone/data/PostTest.kt
b/src/test/kotlin/net/pterodactylus/sone/data/PostTest.kt
index
ebf96b1
..
73f8498
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/data/PostTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/data/PostTest.kt
@@
-29,21
+29,21
@@
class PostTest {
fun `newestFirst comparator returns less-than 0 if first is newer than second`() {
val newerPost = createPost(time = 2000)
val olderPost = createPost(time = 1000)
fun `newestFirst comparator returns less-than 0 if first is newer than second`() {
val newerPost = createPost(time = 2000)
val olderPost = createPost(time = 1000)
- assertThat(newestFirst.compare(newerPost, olderPost), lessThan(0))
+ assertThat(newest
Post
First.compare(newerPost, olderPost), lessThan(0))
}
@Test
fun `newestFirst comparator returns greater-than 0 if first is older than second`() {
val newerPost = createPost(time = 2000)
val olderPost = createPost(time = 1000)
}
@Test
fun `newestFirst comparator returns greater-than 0 if first is older than second`() {
val newerPost = createPost(time = 2000)
val olderPost = createPost(time = 1000)
- assertThat(newestFirst.compare(olderPost, newerPost), greaterThan(0))
+ assertThat(newest
Post
First.compare(olderPost, newerPost), greaterThan(0))
}
@Test
fun `newestFirst comparator returns 0 if first and second are the same age`() {
val post1 = createPost(time = 1000)
val post2 = createPost(time = 1000)
}
@Test
fun `newestFirst comparator returns 0 if first and second are the same age`() {
val post1 = createPost(time = 1000)
val post2 = createPost(time = 1000)
- assertThat(newestFirst.compare(post2, post1), equalTo(0))
+ assertThat(newest
Post
First.compare(post2, post1), equalTo(0))
}
}
}
}