Store a copy of the given profile.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index bb36a9c..b70dbdb 100644 (file)
@@ -27,6 +27,8 @@ import freenet.keys.FreenetURI;
 /**
  * A Sone defines everything about a user: the {@link User} itself, her profile,
  * her status updates.
+ * <p>
+ * Operations that modify the Sone need to synchronize on the Sone in question.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
@@ -45,6 +47,9 @@ 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>();
 
@@ -125,6 +130,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
@@ -204,4 +233,15 @@ public class Sone {
                return id.hashCode();
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof Sone)) {
+                       return false;
+               }
+               return ((Sone) object).id.equals(id);
+       }
+
 }