*
* @author niki
*/
-public class Chapter implements Iterable<Paragraph> {
+public class Chapter implements Iterable<Paragraph>, Cloneable {
private String name;
private int number;
private List<Paragraph> paragraphs = new ArrayList<Paragraph>();
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<Paragraph>();
+ for (Paragraph para : paragraphs) {
+ chap.paragraphs.add(para.clone());
+ }
+ }
+
+ return chap;
+ }
}
}
if (tags != null) {
- meta.tags = new ArrayList<String>();
- meta.tags.addAll(tags);
+ meta.tags = new ArrayList<String>(tags);
}
+
if (resume != null) {
- meta.resume = new Chapter(resume.getNumber(), resume.getName());
- for (Paragraph para : resume) {
- meta.resume.getParagraphs().add(para);
- }
+ meta.resume = resume.clone();
}
return meta;
*
* @author niki
*/
-public class Paragraph {
+public class Paragraph implements Cloneable {
/**
* A paragraph type, that will dictate how the paragraph will be handled.
*
public String toString() {
return String.format("%s: [%s]", "" + type, "" + content);
}
+
+ @Override
+ public Paragraph clone() {
+ Paragraph para = null;
+ try {
+ para = (Paragraph) super.clone();
+ } catch (CloneNotSupportedException e) {
+ // Did the clones rebel?
+ System.err.println(e);
+ }
+
+ return para;
+ }
}
*
* @author niki
*/
-public class Story implements Iterable<Chapter> {
+public class Story implements Iterable<Chapter>, Cloneable {
private MetaData meta;
private List<Chapter> chapters = new ArrayList<Chapter>();
private List<Chapter> empty = new ArrayList<Chapter>();
: meta.getAuthor(), meta == null ? "" : meta.getDate(),
tags, resume, cover);
}
+
+ @Override
+ public Story clone() {
+ Story story = null;
+ try {
+ story = (Story) super.clone();
+ } catch (CloneNotSupportedException e) {
+ // Did the clones rebel?
+ System.err.println(e);
+ }
+
+ if (meta != null) {
+ story.meta = meta.clone();
+ }
+
+ if (chapters != null) {
+ story.chapters = new ArrayList<Chapter>();
+ for (Chapter chap : chapters) {
+ story.chapters.add(chap.clone());
+ }
+ }
+
+ return story;
+ }
}