Store the originating Sone in the post.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index 8b2367b..27c7852 100644 (file)
 
 package net.pterodactylus.sone.data;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
@@ -47,9 +49,15 @@ public class Sone {
        /* This will be null for remote Sones! */
        private final FreenetURI insertUri;
 
+       /** The profile of this Sone. */
+       private Profile profile;
+
        /** All friend Sones. */
        private final Set<Sone> friendSones = new HashSet<Sone>();
 
+       /** All posts. */
+       private final List<Post> posts = new ArrayList<Post>();
+
        /** Modification count. */
        private volatile long modificationCounter = 0;
 
@@ -127,6 +135,30 @@ public class Sone {
        }
 
        /**
+        * Returns a copy of the profile. If you want to update values in the
+        * profile of this Sone, update the values in the returned {@link Profile}
+        * and use {@link #setProfile(Profile)} to change the profile in this Sone.
+        *
+        * @return A copy of the profile
+        */
+       public Profile getProfile() {
+               return new Profile(profile);
+       }
+
+       /**
+        * Sets the profile of this Sone. A copy of the given profile is stored so
+        * that subsequent modifications of the given profile are not reflected in
+        * this Sone!
+        *
+        * @param profile
+        *            The profile to set
+        */
+       public synchronized void setProfile(Profile profile) {
+               this.profile = new Profile(profile);
+               modificationCounter++;
+       }
+
+       /**
         * Returns all friend Sones of this Sone.
         *
         * @return The friend Sones of this Sone
@@ -176,6 +208,40 @@ public class Sone {
        }
 
        /**
+        * Returns the list of posts of this Sone.
+        *
+        * @return All posts of this Sone
+        */
+       public List<Post> getPosts() {
+               return Collections.unmodifiableList(posts);
+       }
+
+       /**
+        * Adds a post with the given text to this Sone.
+        *
+        * @param text
+        *            The text to post
+        */
+       public synchronized void addPost(String text) {
+               Post post = new Post(this, System.currentTimeMillis(), text);
+               if (posts.add(post)) {
+                       modificationCounter++;
+               }
+       }
+
+       /**
+        * Removes the given post from this Sone.
+        *
+        * @param post
+        *            The post to remove
+        */
+       public synchronized void removePost(Post post) {
+               if (posts.remove(post)) {
+                       modificationCounter++;
+               }
+       }
+
+       /**
         * Returns the modification counter.
         *
         * @return The modification counter