Initial commit (working)
[fanfix.git] / src / be / nikiroo / fanfix / data / Chapter.java
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>();
17
18 /**
19 * Create a new {@link Chapter} with the given information.
20 *
21 * @param number
22 * the chapter number, or 0 for the description/resume.
23 * @param name
24 * the chapter name
25 */
26 public Chapter(int number, String name) {
27 this.number = number;
28 this.name = name;
29 }
30
31 /**
32 * The chapter name.
33 *
34 * @return the name
35 */
36 public String getName() {
37 return name;
38 }
39
40 /**
41 * The chapter name.
42 *
43 * @param name
44 * the name to set
45 */
46 public void setName(String name) {
47 this.name = name;
48 }
49
50 /**
51 * The chapter number, or 0 for the description/resume.
52 *
53 * @return the number
54 */
55 public int getNumber() {
56 return number;
57 }
58
59 /**
60 * The chapter number, or 0 for the description/resume.
61 *
62 * @param number
63 * the number to set
64 */
65 public void setNumber(int number) {
66 this.number = number;
67 }
68
69 /**
70 * The included paragraphs.
71 *
72 * @return the paragraphs
73 */
74 public List<Paragraph> getParagraphs() {
75 return paragraphs;
76 }
77
78 /**
79 * The included paragraphs.
80 *
81 * @param paragraphes
82 * the paragraphs to set
83 */
84 public void setParagraphs(List<Paragraph> paragraphs) {
85 this.paragraphs = paragraphs;
86 }
87
88 /**
89 * Get an iterator on the {@link Paragraph}s.
90 */
91 public Iterator<Paragraph> iterator() {
92 return paragraphs == null ? empty.iterator() : paragraphs.iterator();
93 }
94
95 /**
96 * Display a DEBUG {@link String} representation of this object.
97 */
98 @Override
99 public String toString() {
100 return "Chapter " + number + ": " + name;
101 }
102 }