forked from tabulapdf/tabula-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.java
More file actions
76 lines (61 loc) · 1.96 KB
/
Line.java
File metadata and controls
76 lines (61 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package technology.tabula;
import java.util.ArrayList;
import java.util.List;
// TODO this class seems superfluous - get rid of it
@SuppressWarnings("serial")
public class Line extends Rectangle {
List<TextChunk> textChunks = new ArrayList<>();
public static final Character[] WHITE_SPACE_CHARS = { ' ', '\t', '\r', '\n', '\f' };
public List<TextChunk> getTextElements() {
return textChunks;
}
public void setTextElements(List<TextChunk> textChunks) {
this.textChunks = textChunks;
}
public void addTextChunk(int i, TextChunk textChunk) {
if (i < 0) {
throw new IllegalArgumentException("i can't be less than 0");
}
int s = this.textChunks.size();
if (s < i + 1) {
for (; s <= i; s++) {
this.textChunks.add(null);
}
this.textChunks.set(i, textChunk);
}
else {
this.textChunks.set(i, this.textChunks.get(i).merge(textChunk));
}
this.merge(textChunk);
}
public void addTextChunk(TextChunk textChunk) {
if (this.textChunks.isEmpty()) {
this.setRect(textChunk);
}
else {
this.merge(textChunk);
}
this.textChunks.add(textChunk);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
String s = super.toString();
sb.append(s, 0, s.length() - 1);
sb.append(",chunks=");
for (TextChunk te: this.textChunks) {
sb.append("'" + te.getText() + "', ");
}
sb.append(']');
return sb.toString();
}
static Line removeRepeatedCharacters(Line line, Character c, int minRunLength) {
Line rv = new Line();
for(TextChunk t: line.getTextElements()) {
for (TextChunk r: t.squeeze(c, minRunLength)) {
rv.addTextChunk(r);
}
}
return rv;
}
}