diff --git a/bin/uebung08/doc/Book.class b/bin/uebung08/doc/Book.class index 7d5e4a7..02d8ec9 100644 Binary files a/bin/uebung08/doc/Book.class and b/bin/uebung08/doc/Book.class differ diff --git a/bin/uebung08/doc/BookDemo.class b/bin/uebung08/doc/BookDemo.class index 7ea6d41..2e4914a 100644 Binary files a/bin/uebung08/doc/BookDemo.class and b/bin/uebung08/doc/BookDemo.class differ diff --git a/bin/uebung08/doc/CountWordsVisitor.class b/bin/uebung08/doc/CountWordsVisitor.class index 858c0bd..a355834 100644 Binary files a/bin/uebung08/doc/CountWordsVisitor.class and b/bin/uebung08/doc/CountWordsVisitor.class differ diff --git a/bin/uebung08/doc/Image.class b/bin/uebung08/doc/Image.class index 07ae1c0..2c54a73 100644 Binary files a/bin/uebung08/doc/Image.class and b/bin/uebung08/doc/Image.class differ diff --git a/bin/uebung08/doc/Paragraph.class b/bin/uebung08/doc/Paragraph.class index 1357da9..060a743 100644 Binary files a/bin/uebung08/doc/Paragraph.class and b/bin/uebung08/doc/Paragraph.class differ diff --git a/bin/uebung08/doc/Section.class b/bin/uebung08/doc/Section.class index 3fdefa8..5193575 100644 Binary files a/bin/uebung08/doc/Section.class and b/bin/uebung08/doc/Section.class differ diff --git a/bin/uebung08/doc/TableOfContentsVisitor.class b/bin/uebung08/doc/TableOfContentsVisitor.class new file mode 100644 index 0000000..3dda68a Binary files /dev/null and b/bin/uebung08/doc/TableOfContentsVisitor.class differ diff --git a/bin/uebung08/doc/TextComponent.class b/bin/uebung08/doc/TextComponent.class index b029aac..a89fa07 100644 Binary files a/bin/uebung08/doc/TextComponent.class and b/bin/uebung08/doc/TextComponent.class differ diff --git a/bin/uebung08/doc/ToTextVisitor.class b/bin/uebung08/doc/ToTextVisitor.class new file mode 100644 index 0000000..65e8418 Binary files /dev/null and b/bin/uebung08/doc/ToTextVisitor.class differ diff --git a/bin/uebung08/doc/Visitor.class b/bin/uebung08/doc/Visitor.class index 106cc33..d98e72a 100644 Binary files a/bin/uebung08/doc/Visitor.class and b/bin/uebung08/doc/Visitor.class differ diff --git a/src/uebung08/doc/Book.java b/src/uebung08/doc/Book.java index 6b0c412..c8a467b 100644 --- a/src/uebung08/doc/Book.java +++ b/src/uebung08/doc/Book.java @@ -25,7 +25,20 @@ public class Book { } public String toText() { - return ""; + List gesamt = new ArrayList<>(); + + for (int i = 0; i < content.size(); i++) { + List res = new ArrayList<>(); + res.add(content.get(i).accept(new ToTextVisitor())); + + for (String string : res) { + string = i +"." + string; + gesamt.add(string); + } + + } + + return gesamt.toString(); } public String tableOfContents() { diff --git a/src/uebung08/doc/BookDemo.java b/src/uebung08/doc/BookDemo.java index 5645f2b..1910342 100644 --- a/src/uebung08/doc/BookDemo.java +++ b/src/uebung08/doc/BookDemo.java @@ -106,7 +106,8 @@ public class BookDemo { // Aufgabe 2 System.out.println("Buch enthält " + book.countWordsByVisitor() + " Wörter"); - System.out.println("Inhalt: " + book.tableOfContents()); + System.out.println("TOC:\n" + book.tableOfContents()); + System.out.println("Inhalt:"); System.out.println(book.toText()); } diff --git a/src/uebung08/doc/Image.java b/src/uebung08/doc/Image.java index a9efdea..5c6ee75 100644 --- a/src/uebung08/doc/Image.java +++ b/src/uebung08/doc/Image.java @@ -14,6 +14,10 @@ public class Image implements TextComponent { return 0; } + public String getCaption() { + return caption; + } + // immer diese accept methode verwenden @Override public T accept(Visitor visitor) { return visitor.visit(this); } diff --git a/src/uebung08/doc/TableOfContentsVisitor.java b/src/uebung08/doc/TableOfContentsVisitor.java index f3a7e57..59d6635 100644 --- a/src/uebung08/doc/TableOfContentsVisitor.java +++ b/src/uebung08/doc/TableOfContentsVisitor.java @@ -16,7 +16,7 @@ public class TableOfContentsVisitor implements Visitor>{ public List visit(Section section) { List gesamt = new ArrayList<>(); - gesamt.add(section.getHeader()); + gesamt.add(" "+ section.getHeader()); for (int i = 0; i < section.getContent().size(); i++) { List res = new ArrayList<>(); diff --git a/src/uebung08/doc/ToTextVisitor.java b/src/uebung08/doc/ToTextVisitor.java new file mode 100644 index 0000000..903b94d --- /dev/null +++ b/src/uebung08/doc/ToTextVisitor.java @@ -0,0 +1,35 @@ +package uebung08.doc; + +import java.util.ArrayList; +import java.util.List; + +public class ToTextVisitor implements Visitor{ + + public String visit(Image image) { + return image.getCaption(); + } + + public String visit(Paragraph paragraph) { + return ""; + } + + public String visit(Section section) { + List gesamt = new ArrayList<>(); + + gesamt.add(" "+ section.getHeader()); + + for (int i = 0; i < section.getContent().size(); i++) { + + List res = new ArrayList<>(); + res.add(section.getContent().get(i).accept(this)); + + for (String string : res) { + string = i +"." + string; + gesamt.add(string); + } + + } + + return gesamt.toString(); + } +}