Implement getDirectedSones() differently, adhere to new post provider interface.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 12:28:12 +0000 (13:28 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 12:28:12 +0000 (13:28 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java

index 582a5fd..bafe7a8 100644 (file)
@@ -523,26 +523,21 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        }
 
        /**
-        * Returns all posts that have the given Sone as recipient.
-        *
-        * @see Post#getRecipient()
-        * @param recipient
-        *            The recipient of the posts
-        * @return All posts that have the given Sone as recipient
+        * {@inheritDoc}
         */
-       public Set<Post> getDirectedPosts(Sone recipient) {
-               checkNotNull(recipient, "recipient must not be null");
-               Set<Post> directedPosts = new HashSet<Post>();
+       @Override
+       public Collection<Post> getDirectedPosts(final String recipientId) {
+               checkNotNull(recipientId, "recipient must not be null");
                synchronized (posts) {
-                       for (Post post : posts.values()) {
-                               if (recipient.equals(post.getRecipient())) {
-                                       directedPosts.add(post);
+                       return Collections2.filter(posts.values(), new Predicate<Post>() {
+
+                               @Override
+                               public boolean apply(Post post) {
+                                       return (post.getRecipient() != null) && (post.getRecipient().getId().equals(recipientId));
                                }
-                       }
+                       });
                }
-               return directedPosts;
        }
-
        /**
         * Returns a post reply builder.
         *
index f842ac4..0fc7eda 100644 (file)
@@ -68,7 +68,7 @@ public class GetPostFeedCommand extends AbstractSoneCommand {
                        }
                        allPosts.addAll(getCore().getSone(friendSoneId).getPosts());
                }
-               allPosts.addAll(getCore().getDirectedPosts(sone));
+               allPosts.addAll(getCore().getDirectedPosts(sone.getId()));
                allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);
 
                List<Post> sortedPosts = new ArrayList<Post>(allPosts);
index ddc0231..f216431 100644 (file)
@@ -87,7 +87,7 @@ public class ViewSonePage extends SoneTemplatePage {
                        return;
                }
                List<Post> sonePosts = sone.getPosts();
-               sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone));
+               sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.getId()));
                Collections.sort(sonePosts, Post.TIME_COMPARATOR);
                Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
                templateContext.set("postPagination", postPagination);