import freenet.keys.FreenetURI;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
private volatile Profile profile = new Profile(this);
/** The client used by the Sone. */
- private volatile Client client;
+ private final Client client;
/** Whether this Sone is known. */
private volatile boolean known;
/** All posts. */
- private final Set<Post> posts = new CopyOnWriteArraySet<Post>();
+ private final ImmutableSet<Post> posts;
/** All replies. */
- private final Set<PostReply> replies = new CopyOnWriteArraySet<PostReply>();
+ private final ImmutableSet<PostReply> replies;
/** The IDs of all liked posts. */
private final Set<String> likedPostIds = new CopyOnWriteArraySet<String>();
* @param local
* {@code true} if the Sone is a local Sone, {@code false} otherwise
*/
- public SoneImpl(Database database, Identity identity, boolean local, long time) {
+ public SoneImpl(Database database, Identity identity, boolean local, long time, Client client, Collection<Post> posts, Collection<PostReply> postReplies) {
this.database = database;
this.id = identity.getId();
this.identity = identity;
this.local = local;
this.time = time;
+ this.client = client;
+ this.posts = ImmutableSet.copyOf(posts);
+ this.replies = ImmutableSet.copyOf(postReplies);
}
//
}
/**
- * Sets the time of the last inserted update of this Sone.
- *
- * @param time
- * The time of the update (in milliseconds since Jan 1, 1970 UTC)
- * @return This Sone (for method chaining)
- */
- public Sone setTime(long time) {
- return this;
- }
-
- /**
* Returns the status of this Sone.
*
* @return The status of this Sone
* @return This Sone (for method chaining)
*/
public Sone setClient(Client client) {
- this.client = client;
return this;
}
* @return All posts of this Sone
*/
public List<Post> getPosts() {
- List<Post> sortedPosts;
- synchronized (this) {
- sortedPosts = new ArrayList<Post>(posts);
- }
- 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);
- }
+ return FluentIterable.from(posts).toSortedList(Post.TIME_COMPARATOR);
}
/**