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