X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fdata%2FChapter.java;h=d490058a4703b51e042bb369effdf4b4fa511be6;hb=8b152e7b4b89b6bda319c96a1371e766b8a51adc;hp=7d0a51b306b62bfc7f821065a0c10e358be82075;hpb=0efd25e3aa839ba82da1054a470c27830b9ed94a;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/data/Chapter.java b/src/be/nikiroo/fanfix/data/Chapter.java index 7d0a51b..d490058 100644 --- a/src/be/nikiroo/fanfix/data/Chapter.java +++ b/src/be/nikiroo/fanfix/data/Chapter.java @@ -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,13 +10,23 @@ import java.util.List; * * @author niki */ -public class Chapter implements Iterable { +public class Chapter implements Iterable, Cloneable, Serializable { + private static final long serialVersionUID = 1L; + private String name; private int number; private List paragraphs = new ArrayList(); private List empty = new ArrayList(); private long words; + /** + * Empty constructor, not to use. + */ + @SuppressWarnings("unused") + private Chapter() { + // for serialisation purposes + } + /** * Create a new {@link Chapter} with the given information. * @@ -89,12 +100,13 @@ public class Chapter implements Iterable { /** * Get an iterator on the {@link Paragraph}s. */ + @Override public Iterator iterator() { return paragraphs == null ? empty.iterator() : paragraphs.iterator(); } /** - * The number of words in this {@link Chapter}. + * The number of words (or images) in this {@link Chapter}. * * @return the number of words */ @@ -103,7 +115,7 @@ public class Chapter implements Iterable { } /** - * The number of words in this {@link Chapter}. + * The number of words (or images) in this {@link Chapter}. * * @param words * the number of words to set @@ -119,4 +131,24 @@ public class Chapter implements Iterable { public String toString() { return "Chapter " + number + ": " + name; } + + @Override + public Chapter clone() { + Chapter chap = null; + try { + chap = (Chapter) super.clone(); + } catch (CloneNotSupportedException e) { + // Did the clones rebel? + System.err.println(e); + } + + if (paragraphs != null) { + chap.paragraphs = new ArrayList(); + for (Paragraph para : paragraphs) { + chap.paragraphs.add(para.clone()); + } + } + + return chap; + } }