Merge branch 'master' into subtree
[nikiroo-utils.git] / data / Story.java
CommitLineData
08fe2e33
NR
1package be.nikiroo.fanfix.data;
2
8b152e7b 3import java.io.Serializable;
08fe2e33
NR
4import java.util.ArrayList;
5import java.util.Iterator;
6import java.util.List;
7
8/**
9 * The main data class, where the whole story resides.
10 *
11 * @author niki
12 */
8b152e7b
NR
13public class Story implements Iterable<Chapter>, Cloneable, Serializable {
14 private static final long serialVersionUID = 1L;
15
08fe2e33
NR
16 private MetaData meta;
17 private List<Chapter> chapters = new ArrayList<Chapter>();
18 private List<Chapter> empty = new ArrayList<Chapter>();
19
20 /**
21 * The metadata about this {@link Story}.
22 *
23 * @return the meta
24 */
25 public MetaData getMeta() {
26 return meta;
27 }
28
29 /**
30 * The metadata about this {@link Story}.
31 *
32 * @param meta
33 * the meta to set
34 */
35 public void setMeta(MetaData meta) {
36 this.meta = meta;
37 }
38
39 /**
40 * The chapters of the story.
41 *
42 * @return the chapters
43 */
44 public List<Chapter> getChapters() {
45 return chapters;
46 }
47
48 /**
49 * The chapters of the story.
50 *
51 * @param chapters
52 * the chapters to set
53 */
54 public void setChapters(List<Chapter> chapters) {
55 this.chapters = chapters;
56 }
57
58 /**
59 * Get an iterator on the {@link Chapter}s.
60 */
211f7ddb 61 @Override
08fe2e33
NR
62 public Iterator<Chapter> iterator() {
63 return chapters == null ? empty.iterator() : chapters.iterator();
64 }
65
66 /**
67 * Display a DEBUG {@link String} representation of this object.
68 * <p>
69 * This is not efficient, nor intended to be.
70 */
71 @Override
72 public String toString() {
b5e9855b
NR
73 if (getMeta() != null)
74 return "Story: [\n" + getMeta().toString() + "\n]";
75 return "Story: [ no metadata found ]";
08fe2e33 76 }
39cd9738
NR
77
78 @Override
79 public Story clone() {
80 Story story = null;
81 try {
82 story = (Story) super.clone();
83 } catch (CloneNotSupportedException e) {
84 // Did the clones rebel?
85 System.err.println(e);
86 }
87
88 if (meta != null) {
89 story.meta = meta.clone();
90 }
91
92 if (chapters != null) {
93 story.chapters = new ArrayList<Chapter>();
94 for (Chapter chap : chapters) {
95 story.chapters.add(chap.clone());
96 }
97 }
98
99 return story;
100 }
08fe2e33 101}