2 * Sone - Image.java - Copyright © 2011 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data;
20 import java.util.UUID;
22 import net.pterodactylus.util.validation.Validation;
25 * Container for image metadata.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class Image implements Fingerprintable {
31 /** The ID of the image. */
32 private final String id;
34 /** The Sone the image belongs to. */
37 /** The request key of the image. */
40 /** The creation time of the image. */
41 private long creationTime;
43 /** The width of the image. */
46 /** The height of the image. */
49 /** The title of the image. */
52 /** The description of the image. */
53 private String description;
56 * Creates a new image with a random ID.
59 this(UUID.randomUUID().toString());
60 setCreationTime(System.currentTimeMillis());
64 * Creates a new image.
69 public Image(String id) {
70 Validation.begin().isNotNull("Image ID", id).check();
79 * Returns the ID of this image.
81 * @return The ID of this image
83 public String getId() {
88 * Returns the Sone this image belongs to.
90 * @return The Sone this image belongs to
92 public Sone getSone() {
97 * Sets the owner of this image. The owner can only be set if no owner has
101 * The new owner of this image
104 public Image setSone(Sone sone) {
105 Validation.begin().isNull("Current Image Owner", this.sone).isNotNull("New Image Owner", sone);
111 * Returns the request key of this image.
113 * @return The request key of this image
115 public String getKey() {
120 * Sets the request key of this image. The request key can only be set as
121 * long as no request key has yet been set.
124 * The new request key of this image
127 public Image setKey(String key) {
128 Validation.begin().isNull("Current Image Key", this.key).isNotNull("New Image Key", key).check();
134 * Returns the creation time of this image.
136 * @return The creation time of this image (in milliseconds since 1970, Jan
139 public long getCreationTime() {
144 * Sets the new creation time of this image. The creation time can only be
145 * set as long as no creation time has been set yet.
147 * @param creationTime
148 * The new creation time of this image
151 public Image setCreationTime(long creationTime) {
152 Validation.begin().isEqual("Current Image Creation Time", this.creationTime, 0).isGreater("New Image Creation Time", creationTime, 0).check();
153 this.creationTime = creationTime;
158 * Returns the width of this image.
160 * @return The width of this image (in pixels)
162 public int getWidth() {
167 * Sets the width of this image. The width can only be set as long as no
168 * width has been set yet.
171 * The new width of this image
174 public Image setWidth(int width) {
175 Validation.begin().isEqual("Current Image Width", this.width, 0).isGreater("New Image Width", width, 0).check();
181 * Returns the height of this image.
183 * @return The height of this image (in pixels)
185 public int getHeight() {
190 * Sets the new height of this image. The height can only be set as long as
191 * no height has yet been set.
194 * The new height of this image
197 public Image setHeight(int height) {
198 Validation.begin().isEqual("Current Image Height", this.height, 0).isGreater("New Image Height", height, 0);
199 this.height = height;
204 * Returns the title of this image.
206 * @return The title of this image
208 public String getTitle() {
213 * Sets the title of this image.
216 * The title of this image
219 public Image setTitle(String title) {
220 Validation.begin().isNotNull("Image Title", title).check();
226 * Returns the description of this image.
228 * @return The description of this image
230 public String getDescription() {
235 * Sets the description of this image.
238 * The description of this image
241 public Image setDescription(String description) {
242 Validation.begin().isNotNull("Image Description", description).check();
243 this.description = description;
248 // FINGERPRINTABLE METHODS
255 public String getFingerprint() {
256 StringBuilder fingerprint = new StringBuilder();
257 fingerprint.append("Image(");
258 fingerprint.append("ID(").append(id).append(')');
259 fingerprint.append("Title(").append(title).append(')');
260 fingerprint.append("Description(").append(description).append(')');
261 fingerprint.append(')');
262 return fingerprint.toString();