1 package be
.nikiroo
.fanfix
.data
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
8 * A chapter in the story (or the resume/description).
12 public class Chapter
implements Iterable
<Paragraph
>, Cloneable
{
15 private List
<Paragraph
> paragraphs
= new ArrayList
<Paragraph
>();
16 private List
<Paragraph
> empty
= new ArrayList
<Paragraph
>();
20 * Empty constructor, not to use.
22 @SuppressWarnings("unused")
24 // for serialisation purposes
28 * Create a new {@link Chapter} with the given information.
31 * the chapter number, or 0 for the description/resume.
35 public Chapter(int number
, String name
) {
45 public String
getName() {
55 public void setName(String name
) {
60 * The chapter number, or 0 for the description/resume.
64 public int getNumber() {
69 * The chapter number, or 0 for the description/resume.
74 public void setNumber(int number
) {
79 * The included paragraphs.
81 * @return the paragraphs
83 public List
<Paragraph
> getParagraphs() {
88 * The included paragraphs.
91 * the paragraphs to set
93 public void setParagraphs(List
<Paragraph
> paragraphs
) {
94 this.paragraphs
= paragraphs
;
98 * Get an iterator on the {@link Paragraph}s.
101 public Iterator
<Paragraph
> iterator() {
102 return paragraphs
== null ? empty
.iterator() : paragraphs
.iterator();
106 * The number of words (or images) in this {@link Chapter}.
108 * @return the number of words
110 public long getWords() {
115 * The number of words (or images) in this {@link Chapter}.
118 * the number of words to set
120 public void setWords(long words
) {
125 * Display a DEBUG {@link String} representation of this object.
128 public String
toString() {
129 return "Chapter " + number
+ ": " + name
;
133 public Chapter
clone() {
136 chap
= (Chapter
) super.clone();
137 } catch (CloneNotSupportedException e
) {
138 // Did the clones rebel?
139 System
.err
.println(e
);
142 if (paragraphs
!= null) {
143 chap
.paragraphs
= new ArrayList
<Paragraph
>();
144 for (Paragraph para
: paragraphs
) {
145 chap
.paragraphs
.add(para
.clone());