1 package be
.nikiroo
.fanfix
.data
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
8 * The main data class, where the whole story resides.
12 public class Story
implements Iterable
<Chapter
>, Cloneable
{
13 private MetaData meta
;
14 private List
<Chapter
> chapters
= new ArrayList
<Chapter
>();
15 private List
<Chapter
> empty
= new ArrayList
<Chapter
>();
18 * The metadata about this {@link Story}.
22 public MetaData
getMeta() {
27 * The metadata about this {@link Story}.
32 public void setMeta(MetaData meta
) {
37 * The chapters of the story.
39 * @return the chapters
41 public List
<Chapter
> getChapters() {
46 * The chapters of the story.
51 public void setChapters(List
<Chapter
> chapters
) {
52 this.chapters
= chapters
;
56 * Get an iterator on the {@link Chapter}s.
59 public Iterator
<Chapter
> iterator() {
60 return chapters
== null ? empty
.iterator() : chapters
.iterator();
64 * Display a DEBUG {@link String} representation of this object.
66 * This is not efficient, nor intended to be.
69 public String
toString() {
70 if (getMeta() != null)
71 return "Story: [\n" + getMeta().toString() + "\n]";
72 return "Story: [ no metadata found ]";
76 public Story
clone() {
79 story
= (Story
) super.clone();
80 } catch (CloneNotSupportedException e
) {
81 // Did the clones rebel?
82 System
.err
.println(e
);
86 story
.meta
= meta
.clone();
89 if (chapters
!= null) {
90 story
.chapters
= new ArrayList
<Chapter
>();
91 for (Chapter chap
: chapters
) {
92 story
.chapters
.add(chap
.clone());