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