0
|
1 package de.mpiwg.anteater.text;
|
|
2
|
|
3 import java.util.ArrayList;
|
|
4 import java.util.List;
|
|
5
|
|
6 public class TextPart {
|
|
7
|
|
8 private int type;
|
|
9 private int textIdx;
|
|
10 private List<Paragraph> paragraphs;
|
|
11 private String text;
|
|
12 private String date;
|
|
13
|
|
14 public int getType() {
|
|
15 return type;
|
|
16 }
|
|
17 public void setType(int type) {
|
|
18 this.type = type;
|
|
19 }
|
|
20 public int getTextIdx() {
|
|
21 return textIdx;
|
|
22 }
|
|
23 public void setTextIdx(int textIdx) {
|
|
24 this.textIdx = textIdx;
|
|
25 }
|
|
26
|
|
27 public List<Paragraph> getParagraphsOfInterest() {
|
|
28 List<Paragraph> paragraphsOfInterest = new ArrayList<Paragraph>();
|
|
29 for (Paragraph p : paragraphs)
|
|
30 if (p.getParagraphType() != ParagraphType.TYPE_SIGNATURE)
|
|
31 paragraphsOfInterest.add(p);
|
|
32 return paragraphsOfInterest;
|
|
33 }
|
|
34
|
|
35 public List<Paragraph> getParagraphs() {
|
|
36 return paragraphs;
|
|
37 }
|
|
38
|
|
39 public void setParagraphs(List<Paragraph> paragraphs) {
|
|
40 this.paragraphs = paragraphs;
|
|
41 }
|
|
42 public String getText() {
|
|
43
|
|
44 if (text == null) {
|
|
45 StringBuffer sb = new StringBuffer();
|
|
46 for (Paragraph p : getParagraphsOfInterest()) {
|
|
47 sb.append(p.getParagraphText() + "\n");
|
|
48 }
|
|
49 text = sb.toString();
|
|
50 }
|
|
51
|
|
52 return text;
|
|
53 }
|
|
54 public int getPositionInTextFromParagraph(Paragraph paragraph, int posInParagraph) {
|
|
55 int textcounter = 0;
|
|
56 for (Paragraph para : paragraphs) {
|
|
57 if (para != paragraph) {
|
|
58 textcounter += para.getParagraphText().length() + 1;
|
|
59 }
|
|
60 else {
|
|
61 textcounter += posInParagraph;
|
|
62 break;
|
|
63 }
|
|
64 }
|
|
65 return textcounter;
|
|
66 }
|
|
67
|
|
68 public int getPositionInParagraphFromText(int posInText) {
|
|
69 int textcounter = 0;
|
|
70 for (Paragraph para : paragraphs) {
|
|
71 int paraLength = para.getParagraphText().length() + 1;
|
|
72 if (posInText >= textcounter + paraLength)
|
|
73 textcounter += paraLength;
|
|
74 else
|
|
75 return posInText - textcounter;
|
|
76 }
|
|
77 return -1;
|
|
78 }
|
|
79
|
|
80 public Paragraph getParagraphOfIndex(int posInText) {
|
|
81 int textcounter = 0;
|
|
82 for (Paragraph para : paragraphs) {
|
|
83 int paraLength = para.getParagraphText().length() + 1;
|
|
84 if (posInText >= textcounter + paraLength)
|
|
85 textcounter += paraLength;
|
|
86 else
|
|
87 return para;
|
|
88 }
|
|
89 return null;
|
|
90 }
|
|
91 public void setDate(String date) {
|
|
92 this.date = date;
|
|
93 }
|
|
94 public String getDate() {
|
|
95 return date;
|
|
96 }
|
|
97
|
|
98 }
|