Store IDs of like replies in Sone.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 Oct 2010 11:23:24 +0000 (13:23 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 Oct 2010 11:23:24 +0000 (13:23 +0200)
src/main/java/net/pterodactylus/sone/data/Sone.java

index 2e23ed1..661a13c 100644 (file)
@@ -79,6 +79,9 @@ public class Sone {
        /** The IDs of all liked posts. */
        private final Set<String> likedPostIds = new HashSet<String>();
 
+       /** The IDs of all liked replies. */
+       private final Set<String> likedReplyIds = new HashSet<String>();
+
        /** Modification count. */
        private volatile long modificationCounter = 0;
 
@@ -502,6 +505,69 @@ public class Sone {
        }
 
        /**
+        * Returns the IDs of all liked replies.
+        *
+        * @return All liked replies’ IDs
+        */
+       public Set<String> getLikedReplyIds() {
+               return Collections.unmodifiableSet(likedReplyIds);
+       }
+
+       /**
+        * Sets the IDs of all liked replies.
+        *
+        * @param likedReplyIds
+        *            All liked replies’ IDs
+        * @return This Sone (for method chaining)
+        */
+       public synchronized Sone setLikeReplyIds(Set<String> likedReplyIds) {
+               this.likedReplyIds.clear();
+               this.likedReplyIds.addAll(likedReplyIds);
+               modificationCounter++;
+               return this;
+       }
+
+       /**
+        * Checks whether the given reply ID is liked by this Sone.
+        *
+        * @param replyId
+        *            The ID of the reply
+        * @return {@code true} if this Sone likes the given reply, {@code false}
+        *         otherwise
+        */
+       public boolean isLikedReplyId(String replyId) {
+               return likedReplyIds.contains(replyId);
+       }
+
+       /**
+        * Adds the given reply ID to the list of replies this Sone likes.
+        *
+        * @param replyId
+        *            The ID of the reply
+        * @return This Sone (for method chaining)
+        */
+       public synchronized Sone addLikedReplyId(String replyId) {
+               if (likedReplyIds.add(replyId)) {
+                       modificationCounter++;
+               }
+               return this;
+       }
+
+       /**
+        * Removes the given post ID from the list of replies this Sone likes.
+        *
+        * @param replyId
+        *            The ID of the reply
+        * @return This Sone (for method chaining)
+        */
+       public synchronized Sone removeLikedReplyId(String replyId) {
+               if (likedReplyIds.remove(replyId)) {
+                       modificationCounter++;
+               }
+               return this;
+       }
+
+       /**
         * Returns the modification counter.
         *
         * @return The modification counter