+ Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
+ return sortedPosts;
+ }
+
+ /**
+ * Sets all posts of this Sone at once.
+ *
+ * @param posts
+ * The new (and only) posts of this Sone
+ * @return This Sone (for method chaining)
+ */
+ public Sone setPosts(Collection<Post> posts) {
+ synchronized (this) {
+ this.posts.clear();
+ this.posts.addAll(posts);
+ }
+ return this;
+ }
+
+ /**
+ * Adds the given post to this Sone. The post will not be added if its {@link
+ * Post#getSone() Sone} is not this Sone.
+ *
+ * @param post
+ * The post to add
+ */
+ public void addPost(Post post) {
+ if (post.getSone().equals(this) && posts.add(post)) {
+ logger.log(Level.FINEST, String.format("Adding %s to “%s”.", post, getName()));
+ }
+ }
+
+ /**
+ * Removes the given post from this Sone.
+ *
+ * @param post
+ * The post to remove
+ */
+ public void removePost(Post post) {
+ if (post.getSone().equals(this)) {
+ posts.remove(post);
+ }
+ }
+
+ /**
+ * Returns all replies this Sone made.
+ *
+ * @return All replies this Sone made
+ */
+ public Set<PostReply> getReplies() {
+ return Collections.unmodifiableSet(replies);
+ }
+
+ /**
+ * Sets all replies of this Sone at once.
+ *
+ * @param replies
+ * The new (and only) replies of this Sone
+ * @return This Sone (for method chaining)
+ */
+ public Sone setReplies(Collection<PostReply> replies) {
+ this.replies.clear();
+ this.replies.addAll(replies);
+ return this;
+ }
+
+ /**
+ * Adds a reply to this Sone. If the given reply was not made by this Sone,
+ * nothing is added to this Sone.
+ *
+ * @param reply
+ * The reply to add
+ */
+ public void addReply(PostReply reply) {
+ if (reply.getSone().equals(this)) {
+ replies.add(reply);
+ }
+ }
+
+ /**
+ * Removes a reply from this Sone.
+ *
+ * @param reply
+ * The reply to remove
+ */
+ public void removeReply(PostReply reply) {
+ if (reply.getSone().equals(this)) {
+ replies.remove(reply);
+ }
+ }
+
+ /**
+ * Returns the IDs of all liked posts.
+ *
+ * @return All liked posts’ IDs
+ */
+ public Set<String> getLikedPostIds() {
+ return Collections.unmodifiableSet(likedPostIds);
+ }
+
+ /**
+ * Sets the IDs of all liked posts.
+ *
+ * @param likedPostIds
+ * All liked posts’ IDs
+ * @return This Sone (for method chaining)
+ */
+ public Sone setLikePostIds(Set<String> likedPostIds) {
+ this.likedPostIds.clear();
+ this.likedPostIds.addAll(likedPostIds);
+ return this;
+ }
+
+ /**
+ * Checks whether the given post ID is liked by this Sone.
+ *
+ * @param postId
+ * The ID of the post
+ * @return {@code true} if this Sone likes the given post, {@code false}
+ * otherwise
+ */
+ public boolean isLikedPostId(String postId) {
+ return likedPostIds.contains(postId);
+ }
+
+ /**
+ * Adds the given post ID to the list of posts this Sone likes.
+ *
+ * @param postId
+ * The ID of the post
+ * @return This Sone (for method chaining)
+ */
+ public Sone addLikedPostId(String postId) {
+ likedPostIds.add(postId);
+ return this;
+ }
+
+ /**
+ * Removes the given post ID from the list of posts this Sone likes.
+ *
+ * @param postId
+ * The ID of the post
+ * @return This Sone (for method chaining)
+ */
+ public Sone removeLikedPostId(String postId) {
+ likedPostIds.remove(postId);