*
* @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>();
*/
@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;
}
}