X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FImage.java;h=55b0094465e43cea9362c1f05bb0b3c1f67e5451;hb=fdc047dd37e982776d55d827ca405868efe32c5a;hp=d8a8ab192d9770c693b64caa7949fc80b2f375ee;hpb=7017646bf42cb265b6df539bb6def40b91d2f968;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 d8a8ab1..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â2013 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,112 +17,33 @@
package net.pterodactylus.sone.data;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
-import java.util.UUID;
-
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-
/**
* Container for image metadata.
*
- * @author David âBombeâ Roden
+ * @author David Roden
*/
-public class Image implements Identified, 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) {
- this.id = checkNotNull(id, "id must not be null");
- }
-
- //
- // 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) {
- checkNotNull(sone, "sone must not be null");
- checkArgument((this.sone == null) || this.sone.equals(sone), "sone must not already be set to another 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
@@ -132,36 +53,14 @@ public class Image implements Identified, Fingerprintable {
* The album this image belongs to
* @return This image
*/
- public Image setAlbum(Album album) {
- checkNotNull(album, "album must not be null");
- checkNotNull(album.getSone().equals(getSone()), "album must belong to the same Sone as this image");
- 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) {
- checkNotNull(key, "key must not be null");
- checkState((this.key == null) || this.key.equals(key), "key must not be already set to another key");
- this.key = key;
- return this;
- }
+ String getKey();
/**
* Returns whether the image has already been inserted. An image is
@@ -171,9 +70,7 @@ public class Image implements Identified, 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.
@@ -181,154 +78,64 @@ public class Image implements Identified, 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) {
- checkArgument(creationTime > 0, "creationTime must be > 0");
- checkState((this.creationTime == 0) || (this.creationTime == creationTime), "creationTime must not already be set");
- 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) {
- checkArgument(width > 0, "width must be > 0");
- checkState((this.width == 0) || (this.width == width), "width must not already be set to another width");
- 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) {
- checkArgument(height > 0, "height must be > 0");
- checkState((this.height == 0) || (this.height == height), "height must not already be set to another height");
- 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) {
- this.title = checkNotNull(title, "title must not be null");
- 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) {
- this.description = checkNotNull(description, "description must not be null");
- return this;
- }
-
- //
- // FINGERPRINTABLE METHODS
- //
+ String getDescription();
/**
* {@inheritDoc}
*/
@Override
- public String getFingerprint() {
- Hasher hash = Hashing.sha256().newHasher();
- hash.putString("Image(");
- hash.putString("ID(").putString(id).putString(")");
- hash.putString("Title(").putString(title).putString(")");
- hash.putString("Description(").putString(description).putString(")");
- hash.putString(")");
- return hash.hash().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);
}
}