finished TableofContents
This commit is contained in:
parent
81ea768dca
commit
85e8396ce9
@ -29,13 +29,20 @@ public class Book {
|
||||
}
|
||||
|
||||
public String tableOfContents() {
|
||||
List<String> res = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
|
||||
for (TextComponent textComponent : content) {
|
||||
res.addAll(textComponent.accept(new TableOfContentsVisitor()));
|
||||
}
|
||||
|
||||
return res.toString();
|
||||
return gesamt.toString();
|
||||
}
|
||||
|
||||
public int countWordsByVisitor() {
|
||||
|
@ -24,6 +24,10 @@ public class Section implements TextComponent {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> visitor) { return visitor.visit(this); }
|
||||
}
|
||||
|
@ -1,10 +1,34 @@
|
||||
package uebung08.doc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TableOfContentsVisitor implements Visitor<List<String>>{
|
||||
|
||||
public List<String> visit(Image image) {
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> visit(Paragraph paragraph) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> visit(Section section) {
|
||||
List<String> gesamt = new ArrayList<>();
|
||||
|
||||
gesamt.add(section.getHeader());
|
||||
|
||||
for (int i = 0; i < section.getContent().size(); i++) {
|
||||
List<String> res = new ArrayList<>();
|
||||
res.addAll(section.getContent().get(i).accept(this));
|
||||
|
||||
for (String string : res) {
|
||||
string = i +"." + string;
|
||||
gesamt.add(string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return gesamt;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user