Fix tests
[fanfix.git] / src / be / nikiroo / fanfix / data / MetaData.java
1 package be.nikiroo.fanfix.data;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import be.nikiroo.utils.Image;
7
8 /**
9 * The meta data associated to a {@link Story} object.
10 *
11 * @author niki
12 */
13 public class MetaData implements Cloneable, Comparable<MetaData> {
14 private String title;
15 private String author;
16 private String date;
17 private Chapter resume;
18 private List<String> tags;
19 private Image cover;
20 private String subject;
21 private String source;
22 private String url;
23 private String uuid;
24 private String luid;
25 private String lang;
26 private String publisher;
27 private String type;
28 private boolean imageDocument;
29 private long words;
30 private String creationDate;
31 private boolean fakeCover;
32
33 /**
34 * The title of the story.
35 *
36 * @return the title
37 */
38 public String getTitle() {
39 return title;
40 }
41
42 /**
43 * The title of the story.
44 *
45 * @param title
46 * the title to set
47 */
48 public void setTitle(String title) {
49 this.title = title;
50 }
51
52 /**
53 * The author of the story.
54 *
55 * @return the author
56 */
57 public String getAuthor() {
58 return author;
59 }
60
61 /**
62 * The author of the story.
63 *
64 * @param author
65 * the author to set
66 */
67 public void setAuthor(String author) {
68 this.author = author;
69 }
70
71 /**
72 * The story publication date.
73 *
74 * @return the date
75 */
76 public String getDate() {
77 return date;
78 }
79
80 /**
81 * The story publication date.
82 *
83 * @param date
84 * the date to set
85 */
86 public void setDate(String date) {
87 this.date = date;
88 }
89
90 /**
91 * The tags associated with this story.
92 *
93 * @return the tags
94 */
95 public List<String> getTags() {
96 return tags;
97 }
98
99 /**
100 * The tags associated with this story.
101 *
102 * @param tags
103 * the tags to set
104 */
105 public void setTags(List<String> tags) {
106 this.tags = tags;
107 }
108
109 /**
110 * The story resume (a.k.a. description).
111 *
112 * @return the resume
113 */
114 public Chapter getResume() {
115 return resume;
116 }
117
118 /**
119 * The story resume (a.k.a. description).
120 *
121 * @param resume
122 * the resume to set
123 */
124 public void setResume(Chapter resume) {
125 this.resume = resume;
126 }
127
128 /**
129 * The cover image of the story if any (can be NULL).
130 *
131 * @return the cover
132 */
133 public Image getCover() {
134 return cover;
135 }
136
137 /**
138 * The cover image of the story if any (can be NULL).
139 *
140 * @param cover
141 * the cover to set
142 */
143 public void setCover(Image cover) {
144 this.cover = cover;
145 }
146
147 /**
148 * The subject of the story (or instance, if it is a fanfiction, what is the
149 * original work; if it is a technical text, what is the technical
150 * subject...).
151 *
152 * @return the subject
153 */
154 public String getSubject() {
155 return subject;
156 }
157
158 /**
159 * The subject of the story (for instance, if it is a fanfiction, what is
160 * the original work; if it is a technical text, what is the technical
161 * subject...).
162 *
163 * @param subject
164 * the subject to set
165 */
166 public void setSubject(String subject) {
167 this.subject = subject;
168 }
169
170 /**
171 * The source of this story (which online library it was downloaded from).
172 *
173 * @return the source
174 */
175 public String getSource() {
176 return source;
177 }
178
179 /**
180 * The source of this story (which online library it was downloaded from).
181 *
182 * @param source
183 * the source to set
184 */
185 public void setSource(String source) {
186 this.source = source;
187 }
188
189 /**
190 * The original URL from which this {@link Story} was imported.
191 *
192 * @return the url
193 */
194 public String getUrl() {
195 return url;
196 }
197
198 /**
199 * The original URL from which this {@link Story} was imported.
200 *
201 * @param url
202 * the new url to set
203 */
204 public void setUrl(String url) {
205 this.url = url;
206 }
207
208 /**
209 * A unique value representing the story (it is often a URL).
210 *
211 * @return the uuid
212 */
213 public String getUuid() {
214 return uuid;
215 }
216
217 /**
218 * A unique value representing the story (it is often a URL).
219 *
220 * @param uuid
221 * the uuid to set
222 */
223 public void setUuid(String uuid) {
224 this.uuid = uuid;
225 }
226
227 /**
228 * A unique value representing the story in the local library.
229 *
230 * @return the luid
231 */
232 public String getLuid() {
233 return luid;
234 }
235
236 /**
237 * A unique value representing the story in the local library.
238 *
239 * @param luid
240 * the luid to set
241 */
242 public void setLuid(String luid) {
243 this.luid = luid;
244 }
245
246 /**
247 * The 2-letter code language of this story.
248 *
249 * @return the lang
250 */
251 public String getLang() {
252 return lang;
253 }
254
255 /**
256 * The 2-letter code language of this story.
257 *
258 * @param lang
259 * the lang to set
260 */
261 public void setLang(String lang) {
262 this.lang = lang;
263 }
264
265 /**
266 * The story publisher (other the same as the source).
267 *
268 * @return the publisher
269 */
270 public String getPublisher() {
271 return publisher;
272 }
273
274 /**
275 * The story publisher (other the same as the source).
276 *
277 * @param publisher
278 * the publisher to set
279 */
280 public void setPublisher(String publisher) {
281 this.publisher = publisher;
282 }
283
284 /**
285 * The output type this {@link Story} is in.
286 *
287 * @return the type the type
288 */
289 public String getType() {
290 return type;
291 }
292
293 /**
294 * The output type this {@link Story} is in.
295 *
296 * @param type
297 * the new type to set
298 */
299 public void setType(String type) {
300 this.type = type;
301 }
302
303 /**
304 * Document catering mostly to image files.
305 *
306 * @return the imageDocument state
307 */
308 public boolean isImageDocument() {
309 return imageDocument;
310 }
311
312 /**
313 * Document catering mostly to image files.
314 *
315 * @param imageDocument
316 * the imageDocument state to set
317 */
318 public void setImageDocument(boolean imageDocument) {
319 this.imageDocument = imageDocument;
320 }
321
322 /**
323 * The number of words in the related {@link Story}.
324 *
325 * @return the number of words
326 */
327 public long getWords() {
328 return words;
329 }
330
331 /**
332 * The number of words in the related {@link Story}.
333 *
334 * @param words
335 * the number of words to set
336 */
337 public void setWords(long words) {
338 this.words = words;
339 }
340
341 /**
342 * The (Fanfix) {@link Story} creation date.
343 *
344 * @return the creationDate
345 */
346 public String getCreationDate() {
347 return creationDate;
348 }
349
350 /**
351 * The (Fanfix) {@link Story} creation date.
352 *
353 * @param creationDate
354 * the creationDate to set
355 */
356 public void setCreationDate(String creationDate) {
357 this.creationDate = creationDate;
358 }
359
360 /**
361 * The cover in this {@link MetaData} object is "fake", in the sens that it
362 * comes from the actual content images.
363 *
364 * @return TRUE for a fake cover
365 */
366 public boolean isFakeCover() {
367 return fakeCover;
368 }
369
370 /**
371 * The cover in this {@link MetaData} object is "fake", in the sens that it
372 * comes from the actual content images
373 *
374 * @param fakeCover
375 * TRUE for a fake cover
376 */
377 public void setFakeCover(boolean fakeCover) {
378 this.fakeCover = fakeCover;
379 }
380
381 @Override
382 public int compareTo(MetaData o) {
383 if (o == null) {
384 return 1;
385 }
386
387 String id = (getUuid() == null ? "" : getUuid())
388 + (getLuid() == null ? "" : getLuid());
389 String oId = (getUuid() == null ? "" : o.getUuid())
390 + (o.getLuid() == null ? "" : o.getLuid());
391
392 return id.compareTo(oId);
393 }
394
395 @Override
396 public boolean equals(Object obj) {
397 if (!(obj instanceof MetaData)) {
398 return false;
399 }
400
401 return compareTo((MetaData) obj) == 0;
402 }
403
404 @Override
405 public int hashCode() {
406 String uuid = getUuid();
407 if (uuid == null) {
408 uuid = "" + title + author + source;
409 }
410
411 return uuid.hashCode();
412 }
413
414 @Override
415 public MetaData clone() {
416 MetaData meta = null;
417 try {
418 meta = (MetaData) super.clone();
419 } catch (CloneNotSupportedException e) {
420 // Did the clones rebel?
421 System.err.println(e);
422 }
423
424 if (tags != null) {
425 meta.tags = new ArrayList<String>(tags);
426 }
427
428 if (resume != null) {
429 meta.resume = resume.clone();
430 }
431
432 return meta;
433 }
434 }