+ /**
+ * 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 synchronized void addPost(Post post) {
+ if (post.getSone().equals(this) && posts.add(post)) {
+ logger.log(Level.FINEST, "Adding %s to “%s”.", new Object[] { post, getName() });
+ modificationCounter++;
+ }
+ }
+
+ /**
+ * Removes the given post from this Sone.
+ *
+ * @param post
+ * The post to remove
+ */
+ public synchronized void removePost(Post post) {
+ if (post.getSone().equals(this) && posts.remove(post)) {
+ modificationCounter++;
+ }
+ }
+
+ /**
+ * Returns all replies this Sone made.
+ *
+ * @return All replies this Sone made
+ */
+ public Set<Reply> getReplies() {
+ logger.log(Level.FINEST, "Friends of %s: %s", new Object[] { this, friendSones });
+ 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 synchronized Sone setReplies(Collection<Reply> replies) {
+ this.replies.clear();
+ this.replies.addAll(replies);
+ modificationCounter++;
+ 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 synchronized void addReply(Reply reply) {
+ if (reply.getSone().equals(this) && replies.add(reply)) {
+ modificationCounter++;
+ }
+ }
+
+ /**
+ * Removes a reply from this Sone.
+ *
+ * @param reply
+ * The reply to remove
+ */
+ public synchronized void removeReply(Reply reply) {
+ if (reply.getSone().equals(this) && replies.remove(reply)) {
+ modificationCounter++;
+ }
+ }
+
+ /**
+ * Returns the IDs of all blocked Sones. These Sones will not propagated
+ * using the “known Sones” mechanism.
+ *
+ * @return The IDs of all blocked Sones
+ */
+ public Set<String> getBlockedSoneIds() {
+ return Collections.unmodifiableSet(blockedSoneIds);
+ }
+
+ /**
+ * Returns whether the given Sone ID is blocked.
+ *
+ * @param soneId
+ * The Sone ID to check
+ * @return {@code true} if the given Sone ID is blocked, {@code false}
+ * otherwise
+ */
+ public boolean isSoneBlocked(String soneId) {
+ return blockedSoneIds.contains(soneId);
+ }
+
+ /**
+ * Adds the given ID to the list of blocked IDs.
+ *
+ * @param soneId
+ * The Sone ID to block
+ */
+ public synchronized void addBlockedSoneId(String soneId) {
+ if (blockedSoneIds.add(soneId)) {
+ modificationCounter++;
+ }
+ }
+
+ /**
+ * Removes the given ID from the list of blocked IDs.
+ *
+ * @param soneId
+ * The Sone ID to unblock
+ */
+ public synchronized void removeBlockedSoneId(String soneId) {
+ if (blockedSoneIds.remove(soneId)) {
+ modificationCounter++;
+ }
+ }
+
+ /**
+ * Returns the modification counter.
+ *
+ * @return The modification counter
+ */
+ public synchronized long getModificationCounter() {
+ return modificationCounter;
+ }
+
+ /**
+ * Sets the modification counter.
+ *
+ * @param modificationCounter
+ * The new modification counter
+ */
+ public synchronized void setModificationCounter(long modificationCounter) {
+ this.modificationCounter = modificationCounter;
+ }
+
+ /**
+ * Updates the suggested edition in both the request URI and the insert URI.
+ *
+ * @param requestUri
+ * The request URI that resulted from an insert
+ */
+ public void updateUris(FreenetURI requestUri) {
+ /* TODO - check for the correct URI. */
+ long latestEdition = requestUri.getSuggestedEdition();
+ this.requestUri = this.requestUri.setSuggestedEdition(latestEdition);
+ if (this.insertUri != null) {
+ this.insertUri = this.insertUri.setSuggestedEdition(latestEdition);
+ }
+ }
+