From: David ‘Bombe’ Roden Date: Thu, 20 Oct 2016 17:22:07 +0000 (+0200) Subject: Rename comparator for posts X-Git-Tag: 0.9.6^2~6 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=87d9d82c6f671d69cba305b5ddf3cd81ecedc115;p=Sone.git Rename comparator for posts --- diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 7cea6fd..26135ea 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -307,7 +307,7 @@ public class SoneInserter extends AbstractService { soneProperties.put("time", currentTimeMillis()); soneProperties.put("requestUri", sone.getRequestUri()); soneProperties.put("profile", sone.getProfile()); - soneProperties.put("posts", Ordering.from(Post.TIME_COMPARATOR).sortedCopy(sone.getPosts())); + soneProperties.put("posts", Ordering.from(Post.NEWEST_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())); diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index 990e20d..5a1c2c5 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -33,7 +33,7 @@ import com.google.common.base.Predicate; public interface Post extends Identified { /** Comparator for posts, sorts descending by time. */ - public static final Comparator TIME_COMPARATOR = new Comparator() { + public static final Comparator NEWEST_FIRST = new Comparator() { @Override public int compare(Post leftPost, Post rightPost) { 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 8a6dd80..04a5bcc 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java @@ -368,7 +368,7 @@ public class SoneImpl implements Sone { synchronized (this) { sortedPosts = new ArrayList(posts); } - Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Collections.sort(sortedPosts, Post.NEWEST_FIRST); 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 bbff5ed..dea5156 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java @@ -74,7 +74,7 @@ public class GetPostFeedCommand extends AbstractSoneCommand { allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER); List sortedPosts = new ArrayList(allPosts); - Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Collections.sort(sortedPosts, Post.NEWEST_FIRST); if (sortedPosts.size() < startPost) { return new Response("PostFeed", encodePosts(Collections. emptyList(), "Posts.", false)); diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java index d4b8980..b273bdb 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -71,7 +71,7 @@ public class BookmarksPage extends SoneTemplatePage { } }); List sortedPosts = new ArrayList(loadedPosts); - Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Collections.sort(sortedPosts, Post.NEWEST_FIRST); Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index 030ec3d..1d40f45 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -78,7 +78,7 @@ public class IndexPage extends SoneTemplatePage { } allPosts = Collections2.filter(allPosts, postVisibilityFilter.isVisible(currentSone)); List sortedPosts = new ArrayList(allPosts); - Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Collections.sort(sortedPosts, Post.NEWEST_FIRST); Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); diff --git a/src/main/java/net/pterodactylus/sone/web/NewPage.java b/src/main/java/net/pterodactylus/sone/web/NewPage.java index 133a9d1..406054d 100644 --- a/src/main/java/net/pterodactylus/sone/web/NewPage.java +++ b/src/main/java/net/pterodactylus/sone/web/NewPage.java @@ -71,7 +71,7 @@ public class NewPage extends SoneTemplatePage { /* filter and sort them. */ List sortedPosts = new ArrayList(posts); - Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Collections.sort(sortedPosts, Post.NEWEST_FIRST); /* paginate them. */ Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index 119456f..f2c9c91 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -90,7 +90,7 @@ public class ViewSonePage extends SoneTemplatePage { } List sonePosts = sone.get().getPosts(); sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.get().getId())); - Collections.sort(sonePosts, Post.TIME_COMPARATOR); + Collections.sort(sonePosts, Post.NEWEST_FIRST); Pagination postPagination = new Pagination(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("postPage"), 0)); templateContext.set("postPagination", postPagination); templateContext.set("posts", postPagination.getItems());