Store avatar image in Sone.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index ca970c2..e36a306 100644 (file)
@@ -115,6 +115,15 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
 
        };
 
+       /** Filter that matches Sones that have at least one album. */
+       public static final Filter<Sone> HAS_ALBUM_FILTER = new Filter<Sone>() {
+
+               @Override
+               public boolean filterObject(Sone sone) {
+                       return !sone.getAlbums().isEmpty();
+               }
+       };
+
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Sone.class);
 
@@ -164,6 +173,9 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        /** Sone-specific options. */
        private final Options options = new Options();
 
+       /** The avatar of this Sone. */
+       private volatile String avatar;
+
        /**
         * Creates a new Sone.
         *
@@ -380,19 +392,6 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
-        * Sets all friends of this Sone at once.
-        *
-        * @param friends
-        *            The new (and only) friends of this Sone
-        * @return This Sone (for method chaining)
-        */
-       public Sone setFriends(Collection<String> friends) {
-               friendSones.clear();
-               friendSones.addAll(friends);
-               return this;
-       }
-
-       /**
         * Returns whether this Sone has the given Sone as a friend Sone.
         *
         * @param friendSoneId
@@ -768,6 +767,34 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
+        * Returns the ID of the currently selected avatar image.
+        *
+        * @return The ID of the currently selected avatar image, or {@code null} if
+        *         no avatar is selected.
+        */
+       public String getAvatar() {
+               return avatar;
+       }
+
+       /**
+        * Sets the avatar image.
+        *
+        * @param avatar
+        *            The new avatar image, or {@code null} to not select an avatar
+        *            image.
+        * @return This Sone
+        */
+       public Sone setAvatar(Image avatar) {
+               if (avatar == null) {
+                       this.avatar = null;
+                       return this;
+               }
+               Validation.begin().isEqual("Image Owner", avatar.getSone(), this).check();
+               this.avatar = avatar.getId();
+               return this;
+       }
+
+       /**
         * Returns Sone-specific options.
         *
         * @return The options of this Sone
@@ -824,6 +851,8 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
                }
                fingerprint.append(')');
 
+               fingerprint.append("Avatar(").append(avatar).append(')');
+
                return fingerprint.toString();
        }