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
> {
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() {
71 if (meta
!= null && meta
.getTitle() != null) {
72 title
= meta
.getTitle();
76 if (meta
!= null && meta
.getTags() != null) {
77 for (String tag
: meta
.getTags()) {
78 if (!tags
.isEmpty()) {
86 if (meta
!= null && meta
.getResume() != null) {
87 for (Paragraph para
: meta
.getResume()) {
89 resume
+= para
.toString().substring(0,
90 Math
.min(para
.toString().length(), 120));
95 String cover
= (meta
== null || meta
.getCover() == null) ?
"none"
96 : meta
.getCover().getWidth() + "x"
97 + meta
.getCover().getHeight();
99 "Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
100 + "Resume: [%s]\nCover: [%s]", title
, meta
== null ?
""
101 : meta
.getAuthor(), meta
== null ?
"" : meta
.getDate(),
102 tags
, resume
, cover
);