uebung08
This commit is contained in:
63
uebung08/src/doc/Book.java
Normal file
63
uebung08/src/doc/Book.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package doc;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Book{
|
||||
private String title;
|
||||
private String author;
|
||||
private List<TextComponent> contents;
|
||||
|
||||
public Book(String author, String title, List<TextComponent> contents){
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public int countWords(){
|
||||
Section helpSection = new Section("help", contents);
|
||||
return helpSection.countWords();
|
||||
}
|
||||
|
||||
public int countWordsByVisitor(){
|
||||
CountWordsVisitor countWords = new CountWordsVisitor();
|
||||
int wordCount = 0;
|
||||
for(TextComponent i : contents){
|
||||
wordCount += i.accept(countWords);
|
||||
}
|
||||
return wordCount;
|
||||
}
|
||||
|
||||
|
||||
public List<String> tableOfContents(){
|
||||
TableOfContentsVisitor contentTable = new TableOfContentsVisitor();
|
||||
List<String> returnedContent = new ArrayList<String>();
|
||||
|
||||
for(TextComponent e : contents){
|
||||
//contentTable.setPrefix(Integer.toString(itteration));
|
||||
List<String> returned = e.accept(contentTable);
|
||||
if(returned != null){
|
||||
returnedContent.addAll(returned);
|
||||
}
|
||||
}
|
||||
|
||||
return returnedContent;
|
||||
}
|
||||
|
||||
|
||||
public String toText(){
|
||||
StringBuilder st = new StringBuilder();
|
||||
ToTextVisitor textVisitor = new ToTextVisitor();
|
||||
st.append(" ");
|
||||
st.append(author);
|
||||
st.append("\n");
|
||||
st.append(title);
|
||||
st.append("\n\n");
|
||||
for(TextComponent i : contents){
|
||||
st.append(i.accept(textVisitor));
|
||||
st.append("\n");
|
||||
}
|
||||
return st.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user