1 package be
.nikiroo
.fanfix
.data
;
3 import java
.io
.Serializable
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Iterator
;
9 * A chapter in the story (or the resume/description).
13 public class Chapter
implements Iterable
<Paragraph
>, Cloneable
, Serializable
{
14 private static final long serialVersionUID
= 1L;
18 private List
<Paragraph
> paragraphs
= new ArrayList
<Paragraph
>();
19 private List
<Paragraph
> empty
= new ArrayList
<Paragraph
>();
23 * Empty constructor, not to use.
25 @SuppressWarnings("unused")
27 // for serialisation purposes
31 * Create a new {@link Chapter} with the given information.
34 * the chapter number, or 0 for the description/resume.
38 public Chapter(int number
, String name
) {
48 public String
getName() {
58 public void setName(String name
) {
63 * The chapter number, or 0 for the description/resume.
67 public int getNumber() {
72 * The chapter number, or 0 for the description/resume.
77 public void setNumber(int number
) {
82 * The included paragraphs.
84 * @return the paragraphs
86 public List
<Paragraph
> getParagraphs() {
91 * The included paragraphs.
94 * the paragraphs to set
96 public void setParagraphs(List
<Paragraph
> paragraphs
) {
97 this.paragraphs
= paragraphs
;
101 * Get an iterator on the {@link Paragraph}s.
104 public Iterator
<Paragraph
> iterator() {
105 return paragraphs
== null ? empty
.iterator() : paragraphs
.iterator();
109 * The number of words (or images) in this {@link Chapter}.
111 * @return the number of words
113 public long getWords() {
118 * The number of words (or images) in this {@link Chapter}.
121 * the number of words to set
123 public void setWords(long words
) {
128 * Display a DEBUG {@link String} representation of this object.
131 public String
toString() {
132 return "Chapter " + number
+ ": " + name
;
136 public Chapter
clone() {
139 chap
= (Chapter
) super.clone();
140 } catch (CloneNotSupportedException e
) {
141 // Did the clones rebel?
142 System
.err
.println(e
);
145 if (paragraphs
!= null) {
146 chap
.paragraphs
= new ArrayList
<Paragraph
>();
147 for (Paragraph para
: paragraphs
) {
148 chap
.paragraphs
.add(para
.clone());