Don’t check for Sones but for their IDs.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index 4195484..b14c28f 100644 (file)
@@ -82,7 +82,7 @@ public class Sone {
        private volatile Profile profile;
 
        /** All friend Sones. */
-       private final Set<Sone> friendSones = Collections.synchronizedSet(new HashSet<Sone>());
+       private final Set<String> friendSones = Collections.synchronizedSet(new HashSet<String>());
 
        /** All posts. */
        private final Set<Post> posts = Collections.synchronizedSet(new HashSet<Post>());
@@ -164,7 +164,7 @@ public class Sone {
         * @return The request URI of this Sone
         */
        public FreenetURI getRequestUri() {
-               return requestUri.setSuggestedEdition(latestEdition);
+               return (requestUri != null) ? requestUri.setSuggestedEdition(latestEdition) : null;
        }
 
        /**
@@ -289,9 +289,8 @@ public class Sone {
         *
         * @return The friend Sones of this Sone
         */
-       public List<Sone> getFriends() {
-               List<Sone> friends = new ArrayList<Sone>(friendSones);
-               Collections.sort(friends, NICE_NAME_COMPARATOR);
+       public List<String> getFriends() {
+               List<String> friends = new ArrayList<String>(friendSones);
                return friends;
        }
 
@@ -302,7 +301,7 @@ public class Sone {
         *            The new (and only) friends of this Sone
         * @return This Sone (for method chaining)
         */
-       public Sone setFriends(Collection<Sone> friends) {
+       public Sone setFriends(Collection<String> friends) {
                friendSones.clear();
                friendSones.addAll(friends);
                return this;
@@ -311,13 +310,13 @@ public class Sone {
        /**
         * Returns whether this Sone has the given Sone as a friend Sone.
         *
-        * @param friendSone
-        *            The friend Sone to check for
+        * @param friendSoneId
+        *            The ID of the Sone to check for
         * @return {@code true} if this Sone has the given Sone as a friend,
         *         {@code false} otherwise
         */
-       public boolean hasFriend(Sone friendSone) {
-               return friendSones.contains(friendSone);
+       public boolean hasFriend(String friendSoneId) {
+               return friendSones.contains(friendSoneId);
        }
 
        /**
@@ -327,8 +326,8 @@ public class Sone {
         *            The friend Sone to add
         * @return This Sone (for method chaining)
         */
-       public Sone addFriend(Sone friendSone) {
-               if (!friendSone.equals(this)) {
+       public Sone addFriend(String friendSone) {
+               if (!friendSone.equals(id)) {
                        friendSones.add(friendSone);
                }
                return this;
@@ -337,12 +336,12 @@ public class Sone {
        /**
         * Removes the given Sone as a friend Sone.
         *
-        * @param friendSone
-        *            The friend Sone to remove
+        * @param friendSoneId
+        *            The ID of the friend Sone to remove
         * @return This Sone (for method chaining)
         */
-       public Sone removeFriend(Sone friendSone) {
-               friendSones.remove(friendSone);
+       public Sone removeFriend(String friendSoneId) {
+               friendSones.remove(friendSoneId);
                return this;
        }
 
@@ -621,7 +620,7 @@ public class Sone {
         */
        @Override
        public String toString() {
-               return getClass().getName() + "[identity=" + identity + ",requestUri=" + requestUri + ",insertUri=" + insertUri + ",friends(" + friendSones.size() + "),posts(" + posts.size() + "),replies(" + replies.size() + ")]";
+               return getClass().getName() + "[identity=" + identity + ",requestUri=" + requestUri + ",insertUri(" + String.valueOf(insertUri).length() + "),friends(" + friendSones.size() + "),posts(" + posts.size() + "),replies(" + replies.size() + ")]";
        }
 
 }