Add method to get all posts that have a certain Sone as recipient.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 5 Apr 2011 07:49:59 +0000 (09:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 5 Apr 2011 08:06:14 +0000 (10:06 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java

index 005524e..731fcbd 100644 (file)
@@ -576,6 +576,27 @@ public class Core implements IdentityListener, UpdateListener {
        }
 
        /**
+        * 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
+        */
+       public Set<Post> getDirectedPosts(Sone recipient) {
+               Validation.begin().isNotNull("Recipient", recipient).check();
+               Set<Post> directedPosts = new HashSet<Post>();
+               synchronized (posts) {
+                       for (Post post : posts.values()) {
+                               if (recipient.equals(post.getRecipient())) {
+                                       directedPosts.add(post);
+                               }
+                       }
+               }
+               return directedPosts;
+       }
+
+       /**
         * Returns the reply with the given ID. If there is no reply with the given
         * ID yet, a new one is created.
         *