Add albums to Sone.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Image.java
index cae2520..6b7b1dd 100644 (file)
@@ -19,16 +19,21 @@ package net.pterodactylus.sone.data;
 
 import java.util.UUID;
 
+import net.pterodactylus.util.validation.Validation;
+
 /**
  * Container for image metadata.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class Image {
+public class Image implements Fingerprintable {
 
        /** The ID of the image. */
        private final String id;
 
+       /** The Sone the image belongs to. */
+       private final Sone sone;
+
        /** The key of the image. */
        private final String key;
 
@@ -50,6 +55,8 @@ public class Image {
        /**
         * Creates a new image.
         *
+        * @param sone
+        *            The Sone the image belongs to
         * @param key
         *            The key of the image
         * @param creationTime
@@ -59,8 +66,8 @@ public class Image {
         * @param height
         *            The height of the image
         */
-       public Image(String key, long creationTime, int width, int height) {
-               this(UUID.randomUUID().toString(), key, creationTime, width, height);
+       public Image(Sone sone, String key, long creationTime, int width, int height) {
+               this(UUID.randomUUID().toString(), sone, key, creationTime, width, height);
        }
 
        /**
@@ -68,6 +75,8 @@ public class Image {
         *
         * @param id
         *            The ID of the image
+        * @param sone
+        *            The Sone the image belongs to
         * @param key
         *            The key of the image
         * @param creationTime
@@ -77,8 +86,10 @@ public class Image {
         * @param height
         *            The height of the image
         */
-       public Image(String id, String key, long creationTime, int width, int height) {
+       public Image(String id, Sone sone, String key, long creationTime, int width, int height) {
+               Validation.begin().isNotNull("Image ID", id).isNotNull("Image Owner", sone).isNotNull("Image Key", key).isGreater("Image Creation Time", creationTime, 0).isGreater("Image Width", width, 0).isGreater("Image Height", height, 0).check();
                this.id = id;
+               this.sone = sone;
                this.key = key;
                this.creationTime = creationTime;
                this.width = width;
@@ -99,6 +110,15 @@ public class Image {
        }
 
        /**
+        * Returns the Sone this image belongs to.
+        *
+        * @return The Sone this image belongs to
+        */
+       public Sone getSone() {
+               return sone;
+       }
+
+       /**
         * Returns the key of this image.
         *
         * @return The key of this image
@@ -152,6 +172,7 @@ public class Image {
         * @return This image
         */
        public Image setTitle(String title) {
+               Validation.begin().isNotNull("Image Title", title).check();
                this.title = title;
                return this;
        }
@@ -173,8 +194,27 @@ public class Image {
         * @return This image
         */
        public Image setDescription(String description) {
+               Validation.begin().isNotNull("Image Description", description).check();
                this.description = description;
                return this;
        }
 
+       //
+       // FINGERPRINTABLE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public String getFingerprint() {
+               StringBuilder fingerprint = new StringBuilder();
+               fingerprint.append("Image(");
+               fingerprint.append("ID(").append(id).append(')');
+               fingerprint.append("Title(").append(title).append(')');
+               fingerprint.append("Description(").append(description).append(')');
+               fingerprint.append(')');
+               return fingerprint.toString();
+       }
+
 }