58 lines
1.3 KiB
Java
58 lines
1.3 KiB
Java
package uebung08.doc;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Book {
|
|
|
|
private String title;
|
|
private String author;
|
|
|
|
List<TextComponent> content;
|
|
|
|
public Book(String author, String title, List<TextComponent> 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<String> gesamt = new ArrayList<>();
|
|
|
|
for (int i = 0; i < content.size(); i++) {
|
|
List<String> 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;
|
|
}
|
|
}
|