Commit | Line | Data |
---|---|---|
08fe2e33 NR |
1 | package be.nikiroo.fanfix.data; |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Iterator; | |
5 | import java.util.List; | |
6 | ||
7 | /** | |
8 | * A chapter in the story (or the resume/description). | |
9 | * | |
10 | * @author niki | |
11 | */ | |
12 | public class Chapter implements Iterable<Paragraph> { | |
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 NR |
18 | |
19 | /** | |
20 | * Create a new {@link Chapter} with the given information. | |
21 | * | |
22 | * @param number | |
23 | * the chapter number, or 0 for the description/resume. | |
24 | * @param name | |
25 | * the chapter name | |
26 | */ | |
27 | public Chapter(int number, String name) { | |
28 | this.number = number; | |
29 | this.name = name; | |
30 | } | |
31 | ||
32 | /** | |
33 | * The chapter name. | |
34 | * | |
35 | * @return the name | |
36 | */ | |
37 | public String getName() { | |
38 | return name; | |
39 | } | |
40 | ||
41 | /** | |
42 | * The chapter name. | |
43 | * | |
44 | * @param name | |
45 | * the name to set | |
46 | */ | |
47 | public void setName(String name) { | |
48 | this.name = name; | |
49 | } | |
50 | ||
51 | /** | |
52 | * The chapter number, or 0 for the description/resume. | |
53 | * | |
54 | * @return the number | |
55 | */ | |
56 | public int getNumber() { | |
57 | return number; | |
58 | } | |
59 | ||
60 | /** | |
61 | * The chapter number, or 0 for the description/resume. | |
62 | * | |
63 | * @param number | |
64 | * the number to set | |
65 | */ | |
66 | public void setNumber(int number) { | |
67 | this.number = number; | |
68 | } | |
69 | ||
70 | /** | |
71 | * The included paragraphs. | |
72 | * | |
73 | * @return the paragraphs | |
74 | */ | |
75 | public List<Paragraph> getParagraphs() { | |
76 | return paragraphs; | |
77 | } | |
78 | ||
79 | /** | |
80 | * The included paragraphs. | |
81 | * | |
0efd25e3 | 82 | * @param paragraphs |
08fe2e33 NR |
83 | * the paragraphs to set |
84 | */ | |
85 | public void setParagraphs(List<Paragraph> paragraphs) { | |
86 | this.paragraphs = paragraphs; | |
87 | } | |
88 | ||
89 | /** | |
90 | * Get an iterator on the {@link Paragraph}s. | |
91 | */ | |
92 | public Iterator<Paragraph> iterator() { | |
93 | return paragraphs == null ? empty.iterator() : paragraphs.iterator(); | |
94 | } | |
95 | ||
793f1071 NR |
96 | /** |
97 | * The number of words in this {@link Chapter}. | |
98 | * | |
99 | * @return the number of words | |
100 | */ | |
101 | public long getWords() { | |
102 | return words; | |
103 | } | |
104 | ||
105 | /** | |
106 | * The number of words in this {@link Chapter}. | |
107 | * | |
108 | * @param words | |
109 | * the number of words to set | |
110 | */ | |
111 | public void setWords(long words) { | |
112 | this.words = words; | |
113 | } | |
114 | ||
08fe2e33 NR |
115 | /** |
116 | * Display a DEBUG {@link String} representation of this object. | |
117 | */ | |
118 | @Override | |
119 | public String toString() { | |
120 | return "Chapter " + number + ": " + name; | |
121 | } | |
122 | } |