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

Commit 8247954

Browse files
giorgigajazzido
authored andcommitted
Cosmetic changes
Removed several redundant casts and type parameters
1 parent c4fa2d8 commit 8247954

28 files changed

Lines changed: 187 additions & 190 deletions

src/main/java/technology/tabula/CommandLineApp.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void extractFile(File pdfFile, Appendable outFile) throws ParseException
151151
try {
152152
pdfDocument = this.password == null ? PDDocument.load(pdfFile) : PDDocument.load(pdfFile, this.password);
153153
PageIterator pageIterator = getPageIterator(pdfDocument);
154-
List<Table> tables = new ArrayList<Table>();
154+
List<Table> tables = new ArrayList<>();
155155

156156
while (pageIterator.hasNext()) {
157157
Page page = pageIterator.next();
@@ -262,7 +262,6 @@ private static void printHelp() {
262262
formatter.printHelp("tabula", BANNER, buildOptions(), "", true);
263263
}
264264

265-
@SuppressWarnings("static-access")
266265
public static Options buildOptions() {
267266
Options o = new Options();
268267

@@ -362,7 +361,7 @@ public List<Table> extractTables(Page page) {
362361
case SPREADSHEET:
363362
return extractTablesSpreadsheet(page);
364363
default:
365-
return new ArrayList<Table>();
364+
return new ArrayList<>();
366365
}
367366
}
368367

@@ -372,7 +371,7 @@ public List<Table> extractTablesBasic(Page page) {
372371
// currently we only have a detector that uses spreadsheets to find table areas
373372
DetectionAlgorithm detector = new NurminenDetectionAlgorithm();
374373
List<Rectangle> guesses = detector.detect(page);
375-
List<Table> tables = new ArrayList<Table>();
374+
List<Table> tables = new ArrayList<>();
376375

377376
for (Rectangle guessRect : guesses) {
378377
Page guess = page.getArea(guessRect);
@@ -389,7 +388,7 @@ public List<Table> extractTablesBasic(Page page) {
389388

390389
public List<Table> extractTablesSpreadsheet(Page page) {
391390
// TODO add useLineReturns
392-
return (List<Table>) spreadsheetExtractor.extract(page);
391+
return spreadsheetExtractor.extract(page);
393392
}
394393
}
395394

src/main/java/technology/tabula/Line.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@SuppressWarnings("serial")
99
public class Line extends Rectangle {
1010

11-
List<TextChunk> textChunks = new ArrayList<TextChunk>();
11+
List<TextChunk> textChunks = new ArrayList<>();
1212
public static final Character[] WHITE_SPACE_CHARS = { ' ', '\t', '\r', '\n', '\f' };
1313

1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ObjectExtractor {
99

1010
private final PDDocument pdfDocument;
1111

12-
public ObjectExtractor(PDDocument pdfDocument) throws IOException {
12+
public ObjectExtractor(PDDocument pdfDocument) {
1313
this.pdfDocument = pdfDocument;
1414
}
1515

src/main/java/technology/tabula/ObjectExtractorStreamEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected ObjectExtractorStreamEngine(PDPage page) {
4141

4242
this.log = LoggerFactory.getLogger(ObjectExtractorStreamEngine.class);
4343

44-
this.rulings = new ArrayList<Ruling>();
44+
this.rulings = new ArrayList<>();
4545
this.pageTransform = null;
4646

4747
// calculate page transform

src/main/java/technology/tabula/Page.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public int compare(TextElement te1, TextElement te2) {
6666
}}).height;
6767
}
6868
Page rv = new Page(
69-
(float) area.getTop(),
70-
(float) area.getLeft(),
69+
area.getTop(),
70+
area.getLeft(),
7171
(float) area.getWidth(),
7272
(float) area.getHeight(),
7373
rotation,
@@ -155,30 +155,30 @@ public List<Ruling> getRulings() {
155155
}
156156

157157
if (this.rulings == null || this.rulings.isEmpty()) {
158-
this.verticalRulingLines = new ArrayList<Ruling>();
159-
this.horizontalRulingLines = new ArrayList<Ruling>();
160-
return new ArrayList<Ruling>();
158+
this.verticalRulingLines = new ArrayList<>();
159+
this.horizontalRulingLines = new ArrayList<>();
160+
return new ArrayList<>();
161161
}
162162

163163
Utils.snapPoints(this.rulings, this.minCharWidth, this.minCharHeight);
164164

165-
List<Ruling> vrs = new ArrayList<Ruling>();
165+
List<Ruling> vrs = new ArrayList<>();
166166
for (Ruling vr: this.rulings) {
167167
if (vr.vertical()) {
168168
vrs.add(vr);
169169
}
170170
}
171171
this.verticalRulingLines = Ruling.collapseOrientedRulings(vrs);
172172

173-
List<Ruling> hrs = new ArrayList<Ruling>();
173+
List<Ruling> hrs = new ArrayList<>();
174174
for (Ruling hr: this.rulings) {
175175
if (hr.horizontal()) {
176176
hrs.add(hr);
177177
}
178178
}
179179
this.horizontalRulingLines = Ruling.collapseOrientedRulings(hrs);
180180

181-
this.cleanRulings = new ArrayList<Ruling>(this.verticalRulingLines);
181+
this.cleanRulings = new ArrayList<>(this.verticalRulingLines);
182182
this.cleanRulings.addAll(this.horizontalRulingLines);
183183

184184
return this.cleanRulings;

src/main/java/technology/tabula/ProjectionProfile.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public float[] getHorizontalProjection() {
7373
public float[] findVerticalSeparators(float minColumnWidth) {
7474
boolean foundNarrower = false;
7575

76-
List<Integer> verticalSeparators = new ArrayList<Integer>();
76+
List<Integer> verticalSeparators = new ArrayList<>();
7777
for (Ruling r: area.getVerticalRulings()) {
7878
if (r.length() / this.textBounds.getHeight() >= 0.95) {
7979
verticalSeparators.add(toFixed(r.getPosition() - this.areaLeft));
@@ -167,7 +167,7 @@ public static float[] smooth(float[] data, int kernelSize) {
167167
+ kernelSize / 2, data.length); j++) {
168168
s += data[j];
169169
}
170-
rv[i] = (float) Math.floor(s / (float) kernelSize);
170+
rv[i] = (float) Math.floor(s / kernelSize);
171171
}
172172
}
173173
return rv;
@@ -213,7 +213,7 @@ private static int toFixed(double value) {
213213
}
214214

215215
private static double toDouble(int value) {
216-
return (double) value / Math.pow(10, DECIMAL_PLACES);
216+
return value / Math.pow(10, DECIMAL_PLACES);
217217
}
218218

219219
}

src/main/java/technology/tabula/Rectangle.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public float getArea() {
5757
}
5858

5959
public float verticalOverlap(Rectangle other) {
60-
return (float) Math.max(0, Math.min(this.getBottom(), other.getBottom()) - Math.max(this.getTop(), other.getTop()));
60+
return Math.max(0, Math.min(this.getBottom(), other.getBottom()) - Math.max(this.getTop(), other.getTop()));
6161
}
6262

6363
public boolean verticallyOverlaps(Rectangle other) {
6464
return verticalOverlap(other) > 0;
6565
}
6666

6767
public float horizontalOverlap(Rectangle other) {
68-
return (float) Math.max(0, Math.min(this.getRight(), other.getRight()) - Math.max(this.getLeft(), other.getLeft()));
68+
return Math.max(0, Math.min(this.getRight(), other.getRight()) - Math.max(this.getLeft(), other.getLeft()));
6969
}
7070

7171
public boolean horizontallyOverlaps(Rectangle other) {
@@ -74,19 +74,19 @@ public boolean horizontallyOverlaps(Rectangle other) {
7474

7575
public float verticalOverlapRatio(Rectangle other) {
7676
float rv = 0,
77-
delta = (float) Math.min(this.getBottom() - this.getTop(), other.getBottom() - other.getTop());
77+
delta = Math.min(this.getBottom() - this.getTop(), other.getBottom() - other.getTop());
7878

7979
if (other.getTop() <= this.getTop() && this.getTop() <= other.getBottom() && other.getBottom() <= this.getBottom()) {
80-
rv = (float) ((other.getBottom() - this.getTop()) / delta);
80+
rv = (other.getBottom() - this.getTop()) / delta;
8181
}
8282
else if (this.getTop() <= other.getTop() && other.getTop() <= this.getBottom() && this.getBottom() <= other.getBottom()) {
83-
rv = (float) ((this.getBottom() - other.getTop()) / delta);
83+
rv = (this.getBottom() - other.getTop()) / delta;
8484
}
8585
else if (this.getTop() <= other.getTop() && other.getTop() <= other.getBottom() && other.getBottom() <= this.getBottom()) {
86-
rv = (float) ((other.getBottom() - other.getTop()) / delta);
86+
rv = (other.getBottom() - other.getTop()) / delta;
8787
}
8888
else if (other.getTop() <= this.getTop() && this.getTop() <= this.getBottom() && this.getBottom() <= other.getBottom()) {
89-
rv = (float) ((this.getBottom() - this.getTop()) / delta);
89+
rv = (this.getBottom() - this.getTop()) / delta;
9090
}
9191

9292
return rv;
@@ -143,10 +143,10 @@ public void setBottom(float bottom) {
143143

144144
public Point2D[] getPoints() {
145145
return new Point2D[] {
146-
new Point2D.Float((float) this.getLeft(), (float) this.getTop()),
147-
new Point2D.Float((float) this.getRight(), (float) this.getTop()),
148-
new Point2D.Float((float) this.getRight(), (float) this.getBottom()),
149-
new Point2D.Float((float) this.getLeft(), (float) this.getBottom())
146+
new Point2D.Float(this.getLeft(), this.getTop()),
147+
new Point2D.Float(this.getRight(), this.getTop()),
148+
new Point2D.Float(this.getRight(), this.getBottom()),
149+
new Point2D.Float(this.getLeft(), this.getBottom())
150150
};
151151
}
152152

src/main/java/technology/tabula/RectangleSpatialIndex.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
class RectangleSpatialIndex<T extends Rectangle> {
1212

1313
class SaveToListProcedure implements TIntProcedure {
14-
private List<Integer> ids = new ArrayList<Integer>();
14+
private List<Integer> ids = new ArrayList<>();
1515

16-
public boolean execute(int id) {
16+
@Override public boolean execute(int id) {
1717
ids.add(id);
1818
return true;
1919
}
2020

21-
private List<Integer> getIds() {
21+
List<Integer> getIds() {
2222
return ids;
2323
}
2424
}
@@ -30,7 +30,7 @@ private List<Integer> getIds() {
3030
public RectangleSpatialIndex() {
3131
si = new RTree();
3232
si.init(null);
33-
rectangles = new ArrayList<T>();
33+
rectangles = new ArrayList<>();
3434
}
3535

3636
public void add(T te) {
@@ -48,7 +48,7 @@ public void add(T te) {
4848
public List<T> contains(Rectangle r) {
4949
SaveToListProcedure proc = new SaveToListProcedure();
5050
si.contains(rectangleToSpatialIndexRectangle(r), proc);
51-
ArrayList<T> rv = new ArrayList<T>();
51+
ArrayList<T> rv = new ArrayList<>();
5252
for (int i : proc.getIds()) {
5353
rv.add(rectangles.get(i));
5454
}
@@ -59,7 +59,7 @@ public List<T> contains(Rectangle r) {
5959
public List<T> intersects(Rectangle r) {
6060
SaveToListProcedure proc = new SaveToListProcedure();
6161
si.intersects(rectangleToSpatialIndexRectangle(r), proc);
62-
ArrayList<T> rv = new ArrayList<T>();
62+
ArrayList<T> rv = new ArrayList<>();
6363
for (int i : proc.getIds()) {
6464
rv.add(rectangles.get(i));
6565
}

src/main/java/technology/tabula/Ruling.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public String toString() {
297297
}
298298

299299
public static List<Ruling> cropRulingsToArea(List<Ruling> rulings, Rectangle2D area) {
300-
ArrayList<Ruling> rv = new ArrayList<Ruling>();
300+
ArrayList<Ruling> rv = new ArrayList<>();
301301
for (Ruling r : rulings) {
302302
if (r.intersects(area)) {
303303
rv.add(r.intersect(area));
@@ -322,15 +322,15 @@ public SortObject(SOType type, float position, Ruling ruling) {
322322
}
323323
}
324324

325-
List<SortObject> sos = new ArrayList<SortObject>();
325+
List<SortObject> sos = new ArrayList<>();
326326

327-
TreeMap<Ruling, Boolean> tree = new TreeMap<Ruling, Boolean>(new Comparator<Ruling>() {
327+
TreeMap<Ruling, Boolean> tree = new TreeMap<>(new Comparator<Ruling>() {
328328
@Override
329329
public int compare(Ruling o1, Ruling o2) {
330330
return java.lang.Double.compare(o1.getTop(), o2.getTop());
331331
}});
332332

333-
TreeMap<Point2D, Ruling[]> rv = new TreeMap<Point2D, Ruling[]>(new Comparator<Point2D>() {
333+
TreeMap<Point2D, Ruling[]> rv = new TreeMap<>(new Comparator<Point2D>() {
334334
@Override
335335
public int compare(Point2D o1, Point2D o2) {
336336
if (o1.getY() > o2.getY()) return 1;
@@ -409,7 +409,7 @@ public static List<Ruling> collapseOrientedRulings(List<Ruling> lines) {
409409
}
410410

411411
public static List<Ruling> collapseOrientedRulings(List<Ruling> lines, int expandAmount) {
412-
ArrayList<Ruling> rv = new ArrayList<Ruling>();
412+
ArrayList<Ruling> rv = new ArrayList<>();
413413
Collections.sort(lines, new Comparator<Ruling>() {
414414
@Override
415415
public int compare(Ruling a, Ruling b) {

src/main/java/technology/tabula/Table.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public RectangularTextContainer get(int row, int col) {
5757
}
5858

5959
public List<RectangularTextContainer> getRow(int row) {
60-
return new ArrayList<RectangularTextContainer>(this.subMap(new CellPosition(row, 0), new CellPosition(row, maxRow+1)).values());
60+
return new ArrayList<>(this.subMap(new CellPosition(row, 0), new CellPosition(row, maxRow+1)).values());
6161
}
6262

6363
@Override
@@ -110,9 +110,9 @@ public List<List<RectangularTextContainer>> getRows() {
110110
return this.rows;
111111
}
112112

113-
this.rows = new ArrayList<List<RectangularTextContainer>>();
113+
this.rows = new ArrayList<>();
114114
for (int i = 0; i <= this.cellContainer.maxRow; i++) {
115-
List<RectangularTextContainer> lastRow = new ArrayList<RectangularTextContainer>();
115+
List<RectangularTextContainer> lastRow = new ArrayList<>();
116116
this.rows.add(lastRow);
117117
for (int j = 0; j <= this.cellContainer.maxCol; j++) {
118118
lastRow.add(this.cellContainer.containsKey(i, j) ? this.cellContainer.get(i, j) : TextChunk.EMPTY);
@@ -138,7 +138,7 @@ public ExtractionAlgorithm getExtractionAlgorithm() {
138138
}
139139

140140
public List<RectangularTextContainer> getCells() {
141-
return (List<RectangularTextContainer>) new ArrayList<RectangularTextContainer>(this.cellContainer.values());
141+
return new ArrayList<>(this.cellContainer.values());
142142
}
143143

144144

0 commit comments

Comments
 (0)