package uebung08.doc; import java.util.ArrayList; import java.util.List; public class Book { private String title; private String author; List content; public Book(String author, String title, List content) { this.author = author; this.title = title; this.content = content; } public int countWords() { int wordcount = 0; for (TextComponent textComponent : content) { wordcount += textComponent.countWords(); } return wordcount; } public String toText() { return ""; } public String tableOfContents() { List gesamt = new ArrayList<>(); for (int i = 0; i < content.size(); i++) { List res = new ArrayList<>(); res.addAll(content.get(i).accept(new TableOfContentsVisitor())); for (String string : res) { string = i +"." + string; gesamt.add(string); } } return gesamt.toString(); } public int countWordsByVisitor() { int count = 0; for (TextComponent textComponent : content) { count += textComponent.accept(new CountWordsVisitor()); } return count; } }