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.
58 public Iterator
<Chapter
> iterator() {
59 return chapters
== null ? empty
.iterator() : chapters
.iterator();
63 * Display a DEBUG {@link String} representation of this object.
65 * This is not efficient, nor intended to be.
68 public String
toString() {
70 if (meta
!= null && meta
.getTitle() != null) {
71 title
= meta
.getTitle();
75 if (meta
!= null && meta
.getTags() != null) {
76 for (String tag
: meta
.getTags()) {
77 if (!tags
.isEmpty()) {
85 if (meta
!= null && meta
.getResume() != null) {
86 for (Paragraph para
: meta
.getResume()) {
88 resume
+= para
.toString().substring(0,
89 Math
.min(para
.toString().length(), 120));
94 String cover
= (meta
== null || meta
.getCover() == null) ?
"none"
95 : meta
.getCover().getWidth() + "x"
96 + meta
.getCover().getHeight();
98 "Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
99 + "Resume: [%s]\nCover: [%s]", title
, meta
== null ?
""
100 : meta
.getAuthor(), meta
== null ?
"" : meta
.getDate(),
101 tags
, resume
, cover
);