1 package be
.nikiroo
.fanfix
.data
;
3 import java
.io
.Serializable
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Iterator
;
9 * The main data class, where the whole story resides.
13 public class Story
implements Iterable
<Chapter
>, Cloneable
, Serializable
{
14 private static final long serialVersionUID
= 1L;
16 private MetaData meta
;
17 private List
<Chapter
> chapters
= new ArrayList
<Chapter
>();
18 private List
<Chapter
> empty
= new ArrayList
<Chapter
>();
21 * The metadata about this {@link Story}.
25 public MetaData
getMeta() {
30 * The metadata about this {@link Story}.
35 public void setMeta(MetaData meta
) {
40 * The chapters of the story.
42 * @return the chapters
44 public List
<Chapter
> getChapters() {
49 * The chapters of the story.
54 public void setChapters(List
<Chapter
> chapters
) {
55 this.chapters
= chapters
;
59 * Get an iterator on the {@link Chapter}s.
62 public Iterator
<Chapter
> iterator() {
63 return chapters
== null ? empty
.iterator() : chapters
.iterator();
67 * Display a DEBUG {@link String} representation of this object.
69 * This is not efficient, nor intended to be.
72 public String
toString() {
73 if (getMeta() != null)
74 return "Story: [\n" + getMeta().toString() + "\n]";
75 return "Story: [ no metadata found ]";
79 public Story
clone() {
82 story
= (Story
) super.clone();
83 } catch (CloneNotSupportedException e
) {
84 // Did the clones rebel?
85 System
.err
.println(e
);
89 story
.meta
= meta
.clone();
92 if (chapters
!= null) {
93 story
.chapters
= new ArrayList
<Chapter
>();
94 for (Chapter chap
: chapters
) {
95 story
.chapters
.add(chap
.clone());