Skip to content
This repository was archived by the owner on Nov 17, 2024. It is now read-only.

Commit af0ce5e

Browse files
giorgigajazzido
authored andcommitted
Rectangle no longer Comparable
1 parent db985d2 commit af0ce5e

12 files changed

Lines changed: 257 additions & 261 deletions

src/main/java/technology/tabula/Cell.java

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,69 @@
77

88
@SuppressWarnings("serial")
99
public class Cell extends RectangularTextContainer<TextChunk> {
10-
private boolean spanning;
11-
private boolean placeholder;
12-
private List<TextChunk> textElements;
13-
14-
public Cell(float top, float left, float width, float height) {
15-
super(top, left, width, height);
16-
this.setPlaceholder(false);
17-
this.setSpanning(false);
18-
this.setTextElements(new ArrayList<TextChunk>());
19-
}
20-
21-
public Cell(Point2D topLeft, Point2D bottomRight) {
22-
super((float) topLeft.getY(), (float) topLeft.getX(), (float) (bottomRight.getX() - topLeft.getX()), (float) (bottomRight.getY() - topLeft.getY()));
23-
this.setPlaceholder(false);
24-
this.setSpanning(false);
25-
this.setTextElements(new ArrayList<TextChunk>());
26-
}
27-
28-
@Override
29-
public String getText(boolean useLineReturns) {
30-
if (this.textElements.size() == 0) {
31-
return "";
32-
}
33-
StringBuilder sb = new StringBuilder();
34-
Collections.sort(this.textElements);
35-
double curTop = this.textElements.get(0).getTop();
36-
for (TextChunk tc: this.textElements) {
37-
if (useLineReturns && tc.getTop() > curTop) {
38-
sb.append('\r');
39-
}
40-
sb.append(tc.getText());
41-
curTop = tc.getTop();
42-
}
43-
return sb.toString().trim();
44-
}
4510

46-
public String getText() {
47-
return getText(true);
48-
}
11+
public Cell(float top, float left, float width, float height) {
12+
super(top, left, width, height);
13+
this.setPlaceholder(false);
14+
this.setSpanning(false);
15+
this.setTextElements(new ArrayList<TextChunk>());
16+
}
4917

50-
public boolean isSpanning() {
51-
return spanning;
52-
}
18+
public Cell(Point2D topLeft, Point2D bottomRight) {
19+
super((float) topLeft.getY(), (float) topLeft.getX(), (float) (bottomRight.getX() - topLeft.getX()), (float) (bottomRight.getY() - topLeft.getY()));
20+
this.setPlaceholder(false);
21+
this.setSpanning(false);
22+
this.setTextElements(new ArrayList<TextChunk>());
23+
}
5324

54-
public void setSpanning(boolean spanning) {
55-
this.spanning = spanning;
56-
}
25+
private boolean spanning;
26+
private boolean placeholder;
27+
private List<TextChunk> textElements;
5728

58-
public boolean isPlaceholder() {
59-
return placeholder;
60-
}
29+
@Override
30+
public String getText(boolean useLineReturns) {
31+
if (this.textElements.size() == 0) {
32+
return "";
33+
}
34+
StringBuilder sb = new StringBuilder();
35+
Collections.sort(this.textElements, Rectangle.ILL_DEFINED_ORDER);
36+
double curTop = this.textElements.get(0).getTop();
37+
for (TextChunk tc : this.textElements) {
38+
if (useLineReturns && tc.getTop() > curTop) {
39+
sb.append('\r');
40+
}
41+
sb.append(tc.getText());
42+
curTop = tc.getTop();
43+
}
44+
return sb.toString().trim();
45+
}
6146

62-
public void setPlaceholder(boolean placeholder) {
63-
this.placeholder = placeholder;
64-
}
47+
public String getText() {
48+
return getText(true);
49+
}
6550

51+
public boolean isSpanning() {
52+
return spanning;
53+
}
6654

67-
public List<TextChunk> getTextElements() {
68-
return textElements;
69-
}
55+
public void setSpanning(boolean spanning) {
56+
this.spanning = spanning;
57+
}
7058

71-
public void setTextElements(List<TextChunk> textElements) {
72-
this.textElements = textElements;
73-
}
59+
public boolean isPlaceholder() {
60+
return placeholder;
61+
}
62+
63+
public void setPlaceholder(boolean placeholder) {
64+
this.placeholder = placeholder;
65+
}
66+
67+
public List<TextChunk> getTextElements() {
68+
return textElements;
69+
}
70+
71+
public void setTextElements(List<TextChunk> textElements) {
72+
this.textElements = textElements;
73+
}
7474

7575
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package technology.tabula;
22

33
public interface HasText {
4-
5-
String getText();
4+
5+
String getText();
66

77
}

src/main/java/technology/tabula/ObjectExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected Page extractPage(Integer pageNumber) throws IOException {
3030

3131
pdfTextStripper.process();
3232

33-
Utils.sort(pdfTextStripper.textElements);
33+
Utils.sort(pdfTextStripper.textElements, Rectangle.ILL_DEFINED_ORDER);
3434

3535
float w, h;
3636
int pageRotation = p.getRotation();

src/main/java/technology/tabula/QuickSort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static <T extends Comparable<? super T>> void sort(List<T> list) {
4545
/**
4646
* Sorts the given list using the given comparator.
4747
*/
48-
public static <T> void sort(List<T> list, Comparator<T> comparator) {
48+
public static <T> void sort(List<T> list, Comparator<? super T> comparator) {
4949
if (list instanceof RandomAccess) {
5050
quicksort(list, comparator);
5151
} else {
@@ -56,7 +56,7 @@ public static <T> void sort(List<T> list, Comparator<T> comparator) {
5656
}
5757
}
5858

59-
private static <T> void quicksort(List<T> list, Comparator<T> cmp) {
59+
private static <T> void quicksort(List<T> list, Comparator<? super T> cmp) {
6060
Stack<Integer> stack = new Stack<>();
6161
stack.push(0);
6262
stack.push(list.size());
@@ -76,7 +76,7 @@ private static <T> void quicksort(List<T> list, Comparator<T> cmp) {
7676
}
7777
}
7878

79-
private static <T> int partition(List<T> list, Comparator<T> cmp, int p, int start, int end) {
79+
private static <T> int partition(List<T> list, Comparator<? super T> cmp, int p, int start, int end) {
8080
int l = start;
8181
int h = end - 2;
8282
T piv = list.get(p);

0 commit comments

Comments
 (0)