Network server and Library + nikiroo-utils update
[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 */
12public 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 18
b0e88ebd
NR
19 /**
20 * Empty constructor, not to use.
21 */
22 private Chapter() {
23 // for serialisation purposes
24 }
25
08fe2e33
NR
26 /**
27 * Create a new {@link Chapter} with the given information.
28 *
29 * @param number
30 * the chapter number, or 0 for the description/resume.
31 * @param name
32 * the chapter name
33 */
34 public Chapter(int number, String name) {
35 this.number = number;
36 this.name = name;
37 }
38
39 /**
40 * The chapter name.
41 *
42 * @return the name
43 */
44 public String getName() {
45 return name;
46 }
47
48 /**
49 * The chapter name.
50 *
51 * @param name
52 * the name to set
53 */
54 public void setName(String name) {
55 this.name = name;
56 }
57
58 /**
59 * The chapter number, or 0 for the description/resume.
60 *
61 * @return the number
62 */
63 public int getNumber() {
64 return number;
65 }
66
67 /**
68 * The chapter number, or 0 for the description/resume.
69 *
70 * @param number
71 * the number to set
72 */
73 public void setNumber(int number) {
74 this.number = number;
75 }
76
77 /**
78 * The included paragraphs.
79 *
80 * @return the paragraphs
81 */
82 public List<Paragraph> getParagraphs() {
83 return paragraphs;
84 }
85
86 /**
87 * The included paragraphs.
88 *
0efd25e3 89 * @param paragraphs
08fe2e33
NR
90 * the paragraphs to set
91 */
92 public void setParagraphs(List<Paragraph> paragraphs) {
93 this.paragraphs = paragraphs;
94 }
95
96 /**
97 * Get an iterator on the {@link Paragraph}s.
98 */
99 public Iterator<Paragraph> iterator() {
100 return paragraphs == null ? empty.iterator() : paragraphs.iterator();
101 }
102
793f1071
NR
103 /**
104 * The number of words in this {@link Chapter}.
105 *
106 * @return the number of words
107 */
108 public long getWords() {
109 return words;
110 }
111
112 /**
113 * The number of words in this {@link Chapter}.
114 *
115 * @param words
116 * the number of words to set
117 */
118 public void setWords(long words) {
119 this.words = words;
120 }
121
08fe2e33
NR
122 /**
123 * Display a DEBUG {@link String} representation of this object.
124 */
125 @Override
126 public String toString() {
127 return "Chapter " + number + ": " + name;
128 }
129}