X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FImage.java;h=55b0094465e43cea9362c1f05bb0b3c1f67e5451;hb=1a2e2a402b62923a68b09eea463ca3952c5505b0;hp=6b7b1ddbf90906cb95f1d23fb02fd5e3457abcd8;hpb=0157d6ead52bd7c3052b368bed7026075be7cb33;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/data/Image.java b/src/main/java/net/pterodactylus/sone/data/Image.java
index 6b7b1dd..55b0094 100644
--- a/src/main/java/net/pterodactylus/sone/data/Image.java
+++ b/src/main/java/net/pterodactylus/sone/data/Image.java
@@ -1,5 +1,5 @@
/*
- * Sone - Image.java - Copyright © 2011 David Roden
+ * Sone - Image.java - Copyright © 2011â2016 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
@@ -17,115 +17,60 @@
package net.pterodactylus.sone.data;
-import java.util.UUID;
-
-import net.pterodactylus.util.validation.Validation;
-
/**
* Container for image metadata.
*
- * @author David âBombeâ Roden
+ * @author David Roden
*/
-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;
-
- /** 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,88 +78,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;
- }
+ 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;
- }
-
- /**
- * 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();
+
+ 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 { }
+
}
}