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 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());
63 * Creates a new image.
68 public Image(String id) {
69 Validation.begin().isNotNull("Image ID", id).check();
78 * Returns the ID of this image.
80 * @return The ID of this image
82 public String getId() {
87 * Returns the Sone this image belongs to.
89 * @return The Sone this image belongs to
91 public Sone getSone() {
96 * Sets the owner of this image. The owner can only be set if no owner has
100 * The new owner of this image
103 public Image setSone(Sone sone) {
104 Validation.begin().isNull("Current Image Owner", this.sone).isNotNull("New Image Owner", sone);
110 * Returns the key of this image.
112 * @return The key of this image
114 public String getKey() {
119 * Sets the key of this image. The key can only be set as long as no key has
123 * The new key of this image
126 public Image setKey(String key) {
127 Validation.begin().isNull("Current Image Key", this.key).isNotNull("New Image Key", key).check();
133 * Returns the creation time of this image.
135 * @return The creation time of this image (in milliseconds since 1970, Jan
138 public long getCreationTime() {
143 * Sets the new creation time of this image. The creation time can only be
144 * set as long as no creation time has been set yet.
146 * @param creationTime
147 * The new creation time of this image
150 public Image setCreationTime(long creationTime) {
151 Validation.begin().isEqual("Current Image Creation Time", this.creationTime, 0).isGreater("New Image Creation Time", creationTime, 0).check();
152 this.creationTime = creationTime;
157 * Returns the width of this image.
159 * @return The width of this image (in pixels)
161 public int getWidth() {
166 * Sets the width of this image. The width can only be set as long as no
167 * width has been set yet.
170 * The new width of this image
173 public Image setWidth(int width) {
174 Validation.begin().isEqual("Current Image Width", this.width, 0).isGreater("New Image Width", width, 0).check();
180 * Returns the height of this image.
182 * @return The height of this image (in pixels)
184 public int getHeight() {
189 * Sets the new height of this image. The height can only be set as long as
190 * no height has yet been set.
193 * The new height of this image
196 public Image setHeight(int height) {
197 Validation.begin().isEqual("Current Image Height", this.height, 0).isGreater("New Image Height", height, 0);
198 this.height = height;
203 * Returns the title of this image.
205 * @return The title of this image
207 public String getTitle() {
212 * Sets the title of this image.
215 * The title of this image
218 public Image setTitle(String title) {
219 Validation.begin().isNotNull("Image Title", title).check();
225 * Returns the description of this image.
227 * @return The description of this image
229 public String getDescription() {
234 * Sets the description of this image.
237 * The description of this image
240 public Image setDescription(String description) {
241 Validation.begin().isNotNull("Image Description", description).check();
242 this.description = description;
247 // FINGERPRINTABLE METHODS
254 public String getFingerprint() {
255 StringBuilder fingerprint = new StringBuilder();
256 fingerprint.append("Image(");
257 fingerprint.append("ID(").append(id).append(')');
258 fingerprint.append("Title(").append(title).append(')');
259 fingerprint.append("Description(").append(description).append(')');
260 fingerprint.append(')');
261 return fingerprint.toString();