finished CountWordsVisitor
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package uebung08.doc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Book {
|
||||
@@ -28,10 +29,22 @@ public class Book {
|
||||
}
|
||||
|
||||
public String tableOfContents() {
|
||||
return "";
|
||||
List<String> res = new ArrayList<>();
|
||||
|
||||
for (TextComponent textComponent : content) {
|
||||
res.addAll(textComponent.accept(new TableOfContentsVisitor()));
|
||||
}
|
||||
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
public int countWordsByVisitor() {
|
||||
return 0;
|
||||
int count = 0;
|
||||
|
||||
for (TextComponent textComponent : content) {
|
||||
count += textComponent.accept(new CountWordsVisitor());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user