Update year in copyright lines
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Image.java
index 6c37633..93d0702 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - Image.java - Copyright © 2011 David Roden
+ * Sone - Image.java - Copyright © 2011–2019 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 implements Fingerprintable {
-
-       /** The ID of the image. */
-       private final String id;
-
-       /** The Sone the image belongs to. */
-       private Sone sone;
-
-       /** The album this image belongs to. */
-       private Album album;
-
-       /** The request key of the image. */
-       private String key;
-
-       /** The creation time of the image. */
-       private long creationTime;
-
-       /** The width of the image. */
-       private int width;
-
-       /** The height of the image. */
-       private int height;
-
-       /** The title of the image. */
-       private String title;
-
-       /** The description of the image. */
-       private String description;
-
-       /**
-        * Creates a new image with a random ID.
-        */
-       public Image() {
-               this(UUID.randomUUID().toString());
-               setCreationTime(System.currentTimeMillis());
-       }
-
-       /**
-        * Creates a new image.
-        *
-        * @param id
-        *            The ID of the image
-        */
-       public Image(String id) {
-               Validation.begin().isNotNull("Image ID", id).check();
-               this.id = id;
-       }
-
-       //
-       // ACCESSORS
-       //
+public interface Image extends Identified, Fingerprintable {
 
        /**
         * Returns the ID of this image.
         *
         * @return The ID of this image
         */
-       public String getId() {
-               return id;
-       }
+       String getId();
 
        /**
         * Returns the Sone this image belongs to.
         *
         * @return The Sone this image belongs to
         */
-       public Sone getSone() {
-               return sone;
-       }
-
-       /**
-        * Sets the owner of this image. The owner can only be set if no owner has
-        * yet been set.
-        *
-        * @param sone
-        *            The new owner of this image
-        * @return This image
-        */
-       public Image setSone(Sone sone) {
-               Validation.begin().isNotNull("New Image Owner", sone);
-               this.sone = sone;
-               return this;
-       }
+       Sone getSone();
 
        /**
         * Returns the album this image belongs to.
         *
         * @return The album this image belongs to
         */
-       public Album getAlbum() {
-               return album;
-       }
+       Album getAlbum();
 
        /**
         * Sets the album this image belongs to. The album of an image can only be
@@ -127,34 +51,14 @@ public class Image implements Fingerprintable {
         *            The album this image belongs to
         * @return This image
         */
-       public Image setAlbum(Album album) {
-               Validation.begin().isNotNull("New Album", album).check().isEqual("Album Owner and Image Owner", album.getSone(), getSone()).check();
-               this.album = album;
-               return this;
-       }
+       Image setAlbum(Album album);
 
        /**
         * Returns the request key of this image.
         *
         * @return The request key of this image
         */
-       public String getKey() {
-               return key;
-       }
-
-       /**
-        * Sets the request key of this image. The request key can only be set as
-        * long as no request key has yet been set.
-        *
-        * @param key
-        *            The new request key of this image
-        * @return This image
-        */
-       public Image setKey(String key) {
-               Validation.begin().isNotNull("New Image Key", key).check();
-               this.key = key;
-               return this;
-       }
+       String getKey();
 
        /**
         * Returns whether the image has already been inserted. An image is
@@ -164,9 +68,7 @@ public class Image implements Fingerprintable {
         * @return {@code true} if there is a key for this image, {@code false}
         *         otherwise
         */
-       public boolean isInserted() {
-               return key != null;
-       }
+       boolean isInserted();
 
        /**
         * Returns the creation time of this image.
@@ -174,153 +76,64 @@ public class Image implements Fingerprintable {
         * @return The creation time of this image (in milliseconds since 1970, Jan
         *         1, UTC)
         */
-       public long getCreationTime() {
-               return creationTime;
-       }
-
-       /**
-        * Sets the new creation time of this image. The creation time can only be
-        * set as long as no creation time has been set yet.
-        *
-        * @param creationTime
-        *            The new creation time of this image
-        * @return This image
-        */
-       public Image setCreationTime(long creationTime) {
-               Validation.begin().isGreater("New Image Creation Time", creationTime, 0).check();
-               this.creationTime = creationTime;
-               return this;
-       }
+       long getCreationTime();
 
        /**
         * Returns the width of this image.
         *
         * @return The width of this image (in pixels)
         */
-       public int getWidth() {
-               return width;
-       }
-
-       /**
-        * Sets the width of this image. The width can only be set as long as no
-        * width has been set yet.
-        *
-        * @param width
-        *            The new width of this image
-        * @return This image
-        */
-       public Image setWidth(int width) {
-               Validation.begin().isGreater("New Image Width", width, 0).check();
-               this.width = width;
-               return this;
-       }
+       int getWidth();
 
        /**
         * Returns the height of this image.
         *
         * @return The height of this image (in pixels)
         */
-       public int getHeight() {
-               return height;
-       }
-
-       /**
-        * Sets the new height of this image. The height can only be set as long as
-        * no height has yet been set.
-        *
-        * @param height
-        *            The new height of this image
-        * @return This image
-        */
-       public Image setHeight(int height) {
-               Validation.begin().isGreater("New Image Height", height, 0);
-               this.height = height;
-               return this;
-       }
+       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;
-       }
-
-       /**
-        * Sets the description of this image.
-        *
-        * @param description
-        *            The description of this image
-        * @return This image
-        */
-       public Image setDescription(String description) {
-               Validation.begin().isNotNull("Image Description", description).check();
-               this.description = description;
-               return this;
-       }
-
-       //
-       // FINGERPRINTABLE METHODS
-       //
+       String getDescription();
 
        /**
         * {@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();
-       }
+       String getFingerprint();
 
-       //
-       // OBJECT METHODS
-       //
+       Modifier modify() throws IllegalStateException;
 
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public int hashCode() {
-               return id.hashCode();
-       }
+       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 { }
 
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean equals(Object object) {
-               if (!(object instanceof Image)) {
-                       return false;
-               }
-               return ((Image) object).id.equals(id);
        }
 
 }