X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fdata%2FChapter.java;h=873dcb801f89b03f5ca648bd9c2f67f84ab761f6;hb=aa8b74a318769354c5cb512ead428beb372503a2;hp=839d67b7c0ad2a079cbbc28ddf7e16019031b85f;hpb=793f1071fae48daed3b545a03a286c85e527d244;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/data/Chapter.java b/src/be/nikiroo/fanfix/data/Chapter.java index 839d67b..873dcb8 100644 --- a/src/be/nikiroo/fanfix/data/Chapter.java +++ b/src/be/nikiroo/fanfix/data/Chapter.java @@ -9,13 +9,21 @@ import java.util.List; * * @author niki */ -public class Chapter implements Iterable { +public class Chapter implements Iterable, Cloneable { 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. * @@ -79,7 +87,7 @@ public class Chapter implements Iterable { /** * The included paragraphs. * - * @param paragraphes + * @param paragraphs * the paragraphs to set */ public void setParagraphs(List paragraphs) { @@ -89,12 +97,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 +112,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 +128,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; + } }