F10 now wired into custom code
[nikiroo-utils.git] / src / be / nikiroo / fanfix / data / Chapter.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 * A chapter in the story (or the resume/description).
9 *
10 * @author niki
11 */
39cd9738 12public class Chapter implements Iterable<Paragraph>, Cloneable {
08fe2e33
NR
13 private String name;
14 private int number;
15 private List<Paragraph> paragraphs = new ArrayList<Paragraph>();
16 private List<Paragraph> empty = new ArrayList<Paragraph>();
793f1071 17 private long words;
08fe2e33 18
b0e88ebd
NR
19 /**
20 * Empty constructor, not to use.
21 */
211f7ddb 22 @SuppressWarnings("unused")
b0e88ebd
NR
23 private Chapter() {
24 // for serialisation purposes
25 }
26
08fe2e33
NR
27 /**
28 * Create a new {@link Chapter} with the given information.
29 *
30 * @param number
31 * the chapter number, or 0 for the description/resume.
32 * @param name
33 * the chapter name
34 */
35 public Chapter(int number, String name) {
36 this.number = number;
37 this.name = name;
38 }
39
40 /**
41 * The chapter name.
42 *
43 * @return the name
44 */
45 public String getName() {
46 return name;
47 }
48
49 /**
50 * The chapter name.
51 *
52 * @param name
53 * the name to set
54 */
55 public void setName(String name) {
56 this.name = name;
57 }
58
59 /**
60 * The chapter number, or 0 for the description/resume.
61 *
62 * @return the number
63 */
64 public int getNumber() {
65 return number;
66 }
67
68 /**
69 * The chapter number, or 0 for the description/resume.
70 *
71 * @param number
72 * the number to set
73 */
74 public void setNumber(int number) {
75 this.number = number;
76 }
77
78 /**
79 * The included paragraphs.
80 *
81 * @return the paragraphs
82 */
83 public List<Paragraph> getParagraphs() {
84 return paragraphs;
85 }
86
87 /**
88 * The included paragraphs.
89 *
0efd25e3 90 * @param paragraphs
08fe2e33
NR
91 * the paragraphs to set
92 */
93 public void setParagraphs(List<Paragraph> paragraphs) {
94 this.paragraphs = paragraphs;
95 }
96
97 /**
98 * Get an iterator on the {@link Paragraph}s.
99 */
211f7ddb 100 @Override
08fe2e33
NR
101 public Iterator<Paragraph> iterator() {
102 return paragraphs == null ? empty.iterator() : paragraphs.iterator();
103 }
104
793f1071 105 /**
c8faa52a 106 * The number of words (or images) in this {@link Chapter}.
793f1071
NR
107 *
108 * @return the number of words
109 */
110 public long getWords() {
111 return words;
112 }
113
114 /**
c8faa52a 115 * The number of words (or images) in this {@link Chapter}.
793f1071
NR
116 *
117 * @param words
118 * the number of words to set
119 */
120 public void setWords(long words) {
121 this.words = words;
122 }
123
08fe2e33
NR
124 /**
125 * Display a DEBUG {@link String} representation of this object.
126 */
127 @Override
128 public String toString() {
129 return "Chapter " + number + ": " + name;
130 }
39cd9738
NR
131
132 @Override
133 public Chapter clone() {
134 Chapter chap = null;
135 try {
136 chap = (Chapter) super.clone();
137 } catch (CloneNotSupportedException e) {
138 // Did the clones rebel?
139 System.err.println(e);
140 }
141
142 if (paragraphs != null) {
143 chap.paragraphs = new ArrayList<Paragraph>();
144 for (Paragraph para : paragraphs) {
145 chap.paragraphs.add(para.clone());
146 }
147 }
148
149 return chap;
150 }
08fe2e33 151}