🔀 Merge “release/v81” into “master”
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Image.java
index 385c23d..8414f3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - Image.java - Copyright © 2011 David Roden
+ * Sone - Image.java - Copyright © 2011–2020 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 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 {
-
-       /** 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;
-
-       /** The creation time of the image. */
-       private final long creationTime;
-
-       /** The width of the image. */
-       private final int width;
-
-       /** The height of the image. */
-       private final int height;
-
-       /** The title of the image. */
-       private String title;
-
-       /** The description of the image. */
-       private String description;
+public interface Image extends Identified, Fingerprintable {
 
        /**
-        * Creates a new image.
+        * Returns the ID of this image.
         *
-        * @param sone
-        *            The Sone the image belongs to
-        * @param key
-        *            The key of the image
-        * @param creationTime
-        *            The creation time of the image
-        * @param width
-        *            The width of the image
-        * @param height
-        *            The height of the image
+        * @return The ID of this image
         */
-       public Image(Sone sone, String key, long creationTime, int width, int height) {
-               this(UUID.randomUUID().toString(), sone, key, creationTime, width, height);
-       }
+       String getId();
 
        /**
-        * Creates a new image.
+        * Returns the Sone this image belongs to.
         *
-        * @param id
-        *            The ID of the image
-        * @param sone
-        *            The Sone the image belongs to
-        * @param key
-        *            The key of the image
-        * @param creationTime
-        *            The creation time of the image
-        * @param width
-        *            The width of the image
-        * @param height
-        *            The height of the image
+        * @return The Sone this image belongs to
         */
-       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;
-               this.height = height;
-       }
+       Sone getSone();
 
-       //
-       // ACCESSORS
-       //
+       /**
+        * Returns the album this image belongs to.
+        *
+        * @return The album this image belongs to
+        */
+       Album getAlbum();
 
        /**
-        * Returns the ID of this image.
+        * Sets the album this image belongs to. The album of an image can only be
+        * set once, and it is usually called by {@link Album#addImage(Image)}.
         *
-        * @return The ID of this image
+        * @param album
+        *            The album this image belongs to
+        * @return This image
         */
-       public String getId() {
-               return id;
-       }
+       Image setAlbum(Album album);
 
        /**
-        * Returns the Sone this image belongs to.
+        * Returns the request key of this image.
         *
-        * @return The Sone this image belongs to
+        * @return The request key of this image
         */
-       public Sone getSone() {
-               return sone;
-       }
+       String getKey();
 
        /**
-        * Returns the key of this image.
+        * Returns whether the image has already been inserted. An image is
+        * considered as having been inserted it its {@link #getKey() key} is not
+        * {@code null}.
         *
-        * @return The key of this image
+        * @return {@code true} if there is a key for this image, {@code false}
+        *         otherwise
         */
-       public String getKey() {
-               return key;
-       }
+       boolean isInserted();
 
        /**
         * Returns the creation time of this image.
@@ -133,70 +76,64 @@ public class Image {
         * @return The creation time of this image (in milliseconds since 1970, Jan
         *         1, UTC)
         */
-       public long getCreationTime() {
-               return creationTime;
-       }
+       long getCreationTime();
 
        /**
         * Returns the width of this image.
         *
         * @return The width of this image (in pixels)
         */
-       public int getWidth() {
-               return width;
-       }
+       int getWidth();
 
        /**
         * Returns the height of this image.
         *
         * @return The height of this image (in pixels)
         */
-       public int getHeight() {
-               return height;
-       }
+       int getHeight();
 
        /**
         * Returns the title of this image.
         *
         * @return The title of this image
         */
-       public String getTitle() {
-               return title;
-       }
-
-       /**
-        * Sets the title of this image.
-        *
-        * @param title
-        *            The title of this image
-        * @return This image
-        */
-       public Image setTitle(String title) {
-               Validation.begin().isNotNull("Image Title", title).check();
-               this.title = title;
-               return this;
-       }
+       String getTitle();
 
        /**
         * Returns the description of this image.
         *
         * @return The description of this image
         */
-       public String getDescription() {
-               return description;
-       }
+       String getDescription();
 
        /**
-        * Sets the description of this image.
-        *
-        * @param description
-        *            The description of this image
-        * @return This image
+        * {@inheritDoc}
         */
-       public Image setDescription(String description) {
-               Validation.begin().isNotNull("Image Description", description).check();
-               this.description = description;
-               return this;
+       @Override
+       String getFingerprint();
+
+       Modifier modify() throws IllegalStateException;
+
+       interface Modifier {
+
+               Modifier setSone(Sone sone);
+
+               Modifier setCreationTime(long creationTime);
+
+               Modifier setKey(String key);
+
+               Modifier setTitle(String title);
+
+               Modifier setDescription(String description);
+
+               Modifier setWidth(int width);
+
+               Modifier setHeight(int height);
+
+               Image update() throws IllegalStateException;
+
+               class ImageTitleMustNotBeEmpty extends IllegalStateException { }
+
        }
 
 }