Make all classes in be.nikiroo.fanfix.data Serializable
[fanfix.git] / src / be / nikiroo / fanfix / data / Story.java
index 7ebfbc598d945e1502352872daa8b0e55dbbbaa0..fc3f909880031910c5b1ff698b247c949d6ffe38 100644 (file)
@@ -1,5 +1,6 @@
 package be.nikiroo.fanfix.data;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -9,7 +10,9 @@ import java.util.List;
  * 
  * @author niki
  */
-public class Story implements Iterable<Chapter> {
+public class Story implements Iterable<Chapter>, Cloneable, Serializable {
+       private static final long serialVersionUID = 1L;
+       
        private MetaData meta;
        private List<Chapter> chapters = new ArrayList<Chapter>();
        private List<Chapter> empty = new ArrayList<Chapter>();
@@ -67,38 +70,32 @@ public class Story implements Iterable<Chapter> {
         */
        @Override
        public String toString() {
-               String title = "";
-               if (meta != null && meta.getTitle() != null) {
-                       title = meta.getTitle();
+               if (getMeta() != null)
+                       return "Story: [\n" + getMeta().toString() + "\n]";
+               return "Story: [ no metadata found ]";
+       }
+
+       @Override
+       public Story clone() {
+               Story story = null;
+               try {
+                       story = (Story) super.clone();
+               } catch (CloneNotSupportedException e) {
+                       // Did the clones rebel?
+                       System.err.println(e);
                }
 
-               String tags = "";
-               if (meta != null && meta.getTags() != null) {
-                       for (String tag : meta.getTags()) {
-                               if (!tags.isEmpty()) {
-                                       tags += ", ";
-                               }
-                               tags += tag;
-                       }
+               if (meta != null) {
+                       story.meta = meta.clone();
                }
 
-               String resume = "";
-               if (meta != null && meta.getResume() != null) {
-                       for (Paragraph para : meta.getResume()) {
-                               resume += "\n\t";
-                               resume += para.toString().substring(0,
-                                               Math.min(para.toString().length(), 120));
+               if (chapters != null) {
+                       story.chapters = new ArrayList<Chapter>();
+                       for (Chapter chap : chapters) {
+                               story.chapters.add(chap.clone());
                        }
-                       resume += "\n";
                }
 
-               String cover = (meta == null || meta.getCover() == null) ? "none"
-                               : meta.getCover().getWidth() + "x"
-                                               + meta.getCover().getHeight();
-               return String.format(
-                               "Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
-                                               + "Resume: [%s]\nCover: [%s]", title, meta == null ? ""
-                                               : meta.getAuthor(), meta == null ? "" : meta.getDate(),
-                               tags, resume, cover);
+               return story;
        }
 }