Merge branch 'next' into image-management
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Image.java
1 /*
2  * Sone - Image.java - Copyright © 2011 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.data;
19
20 import java.util.UUID;
21
22 import net.pterodactylus.util.validation.Validation;
23
24 /**
25  * Container for image metadata.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public class Image implements Fingerprintable {
30
31         /** The ID of the image. */
32         private final String id;
33
34         /** The Sone the image belongs to. */
35         private final Sone sone;
36
37         /** The key of the image. */
38         private final String key;
39
40         /** The creation time of the image. */
41         private final long creationTime;
42
43         /** The width of the image. */
44         private final int width;
45
46         /** The height of the image. */
47         private final int height;
48
49         /** The title of the image. */
50         private String title;
51
52         /** The description of the image. */
53         private String description;
54
55         /**
56          * Creates a new image.
57          *
58          * @param sone
59          *            The Sone the image belongs to
60          * @param key
61          *            The key of the image
62          * @param creationTime
63          *            The creation time of the image
64          * @param width
65          *            The width of the image
66          * @param height
67          *            The height of the image
68          */
69         public Image(Sone sone, String key, long creationTime, int width, int height) {
70                 this(UUID.randomUUID().toString(), sone, key, creationTime, width, height);
71         }
72
73         /**
74          * Creates a new image.
75          *
76          * @param id
77          *            The ID of the image
78          * @param sone
79          *            The Sone the image belongs to
80          * @param key
81          *            The key of the image
82          * @param creationTime
83          *            The creation time of the image
84          * @param width
85          *            The width of the image
86          * @param height
87          *            The height of the image
88          */
89         public Image(String id, Sone sone, String key, long creationTime, int width, int height) {
90                 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();
91                 this.id = id;
92                 this.sone = sone;
93                 this.key = key;
94                 this.creationTime = creationTime;
95                 this.width = width;
96                 this.height = height;
97         }
98
99         //
100         // ACCESSORS
101         //
102
103         /**
104          * Returns the ID of this image.
105          *
106          * @return The ID of this image
107          */
108         public String getId() {
109                 return id;
110         }
111
112         /**
113          * Returns the Sone this image belongs to.
114          *
115          * @return The Sone this image belongs to
116          */
117         public Sone getSone() {
118                 return sone;
119         }
120
121         /**
122          * Returns the key of this image.
123          *
124          * @return The key of this image
125          */
126         public String getKey() {
127                 return key;
128         }
129
130         /**
131          * Returns the creation time of this image.
132          *
133          * @return The creation time of this image (in milliseconds since 1970, Jan
134          *         1, UTC)
135          */
136         public long getCreationTime() {
137                 return creationTime;
138         }
139
140         /**
141          * Returns the width of this image.
142          *
143          * @return The width of this image (in pixels)
144          */
145         public int getWidth() {
146                 return width;
147         }
148
149         /**
150          * Returns the height of this image.
151          *
152          * @return The height of this image (in pixels)
153          */
154         public int getHeight() {
155                 return height;
156         }
157
158         /**
159          * Returns the title of this image.
160          *
161          * @return The title of this image
162          */
163         public String getTitle() {
164                 return title;
165         }
166
167         /**
168          * Sets the title of this image.
169          *
170          * @param title
171          *            The title of this image
172          * @return This image
173          */
174         public Image setTitle(String title) {
175                 Validation.begin().isNotNull("Image Title", title).check();
176                 this.title = title;
177                 return this;
178         }
179
180         /**
181          * Returns the description of this image.
182          *
183          * @return The description of this image
184          */
185         public String getDescription() {
186                 return description;
187         }
188
189         /**
190          * Sets the description of this image.
191          *
192          * @param description
193          *            The description of this image
194          * @return This image
195          */
196         public Image setDescription(String description) {
197                 Validation.begin().isNotNull("Image Description", description).check();
198                 this.description = description;
199                 return this;
200         }
201
202         //
203         // FINGERPRINTABLE METHODS
204         //
205
206         /**
207          * {@inheritDoc}
208          */
209         @Override
210         public String getFingerprint() {
211                 StringBuilder fingerprint = new StringBuilder();
212                 fingerprint.append("Image(");
213                 fingerprint.append("ID(").append(id).append(')');
214                 fingerprint.append("Title(").append(title).append(')');
215                 fingerprint.append("Description(").append(description).append(')');
216                 fingerprint.append(')');
217                 return fingerprint.toString();
218         }
219
220 }