Skip to content

Commit 25201eb

Browse files
committed
Addressing checkstyle
Enable checkstyle on more modules and adressing violations
1 parent 9c7af56 commit 25201eb

File tree

223 files changed

+2536
-2171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+2536
-2171
lines changed

document-readers/pdf-reader/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
3737
</scm>
3838

39+
<properties>
40+
<disable.checks>false</disable.checks>
41+
</properties>
42+
3943
<dependencies>
4044
<dependency>
4145
<groupId>org.springframework.ai</groupId>

document-readers/pdf-reader/src/main/java/org/springframework/ai/reader/pdf/PagePdfDocumentReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.ai.reader.pdf;
1818

19-
import java.awt.*;
19+
import java.awt.Rectangle;
2020
import java.io.IOException;
2121
import java.util.ArrayList;
2222
import java.util.List;
@@ -112,7 +112,7 @@ public List<Document> get() {
112112
for (PDPage page : this.document.getDocumentCatalog().getPages()) {
113113
lastPage = page;
114114
if (counter % logFrequency == 0 && counter / logFrequency < 10) {
115-
this.logger.info("Processing PDF page: {}", (counter + 1));
115+
logger.info("Processing PDF page: {}", (counter + 1));
116116
}
117117
counter++;
118118

@@ -154,7 +154,7 @@ public List<Document> get() {
154154
readDocuments.add(toDocument(lastPage, pageTextGroupList.stream().collect(Collectors.joining()),
155155
startPageNumber, pageNumber));
156156
}
157-
this.logger.info("Processing {} pages", totalPages);
157+
logger.info("Processing {} pages", totalPages);
158158
return readDocuments;
159159

160160
}

document-readers/pdf-reader/src/main/java/org/springframework/ai/reader/pdf/ParagraphPdfDocumentReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.ai.reader.pdf;
1818

19-
import java.awt.*;
19+
import java.awt.Rectangle;
2020
import java.util.ArrayList;
2121
import java.util.Iterator;
2222
import java.util.List;
@@ -133,7 +133,7 @@ public List<Document> get() {
133133
List<Document> documents = new ArrayList<>(paragraphs.size());
134134

135135
if (!CollectionUtils.isEmpty(paragraphs)) {
136-
this.logger.info("Start processing paragraphs from PDF");
136+
logger.info("Start processing paragraphs from PDF");
137137
Iterator<Paragraph> itr = paragraphs.iterator();
138138

139139
var current = itr.next();
@@ -152,7 +152,7 @@ public List<Document> get() {
152152
}
153153
}
154154
}
155-
this.logger.info("End processing paragraphs from PDF");
155+
logger.info("End processing paragraphs from PDF");
156156
return documents;
157157
}
158158

document-readers/pdf-reader/src/main/java/org/springframework/ai/reader/pdf/aot/PdfReaderRuntimeHints.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
4545
"/org/apache/pdfbox/resources/icc/**", "/org/apache/pdfbox/resources/text/**",
4646
"/org/apache/pdfbox/resources/ttf/**", "/org/apache/pdfbox/resources/version.properties");
4747

48-
for (var pattern : patterns)
49-
for (var resourceMatch : resolver.getResources(pattern))
48+
for (var pattern : patterns) {
49+
for (var resourceMatch : resolver.getResources(pattern)) {
5050
hints.resources().registerResource(resourceMatch);
51+
}
52+
}
5153

5254
}
5355
catch (IOException e) {

document-readers/pdf-reader/src/main/java/org/springframework/ai/reader/pdf/config/PdfDocumentReaderConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Christian Tzolov
2929
*/
30-
public class PdfDocumentReaderConfig {
30+
public final class PdfDocumentReaderConfig {
3131

3232
public static final int ALL_PAGES = 0;
3333

@@ -65,7 +65,7 @@ public static PdfDocumentReaderConfig defaultConfig() {
6565
return builder().build();
6666
}
6767

68-
public static class Builder {
68+
public static final class Builder {
6969

7070
private int pagesPerDocument = 1;
7171

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.reader.pdf.layout;
18+
19+
class Character {
20+
21+
private char characterValue;
22+
23+
private int index;
24+
25+
private boolean isCharacterPartOfPreviousWord;
26+
27+
private boolean isFirstCharacterOfAWord;
28+
29+
private boolean isCharacterAtTheBeginningOfNewLine;
30+
31+
private boolean isCharacterCloseToPreviousWord;
32+
33+
Character(char characterValue, int index, boolean isCharacterPartOfPreviousWord, boolean isFirstCharacterOfAWord,
34+
boolean isCharacterAtTheBeginningOfNewLine, boolean isCharacterPartOfASentence) {
35+
this.characterValue = characterValue;
36+
this.index = index;
37+
this.isCharacterPartOfPreviousWord = isCharacterPartOfPreviousWord;
38+
this.isFirstCharacterOfAWord = isFirstCharacterOfAWord;
39+
this.isCharacterAtTheBeginningOfNewLine = isCharacterAtTheBeginningOfNewLine;
40+
this.isCharacterCloseToPreviousWord = isCharacterPartOfASentence;
41+
if (ForkPDFLayoutTextStripper.DEBUG) {
42+
System.out.println(this.toString());
43+
}
44+
}
45+
46+
public char getCharacterValue() {
47+
return this.characterValue;
48+
}
49+
50+
public int getIndex() {
51+
return this.index;
52+
}
53+
54+
public void setIndex(int index) {
55+
this.index = index;
56+
}
57+
58+
public boolean isCharacterPartOfPreviousWord() {
59+
return this.isCharacterPartOfPreviousWord;
60+
}
61+
62+
public boolean isFirstCharacterOfAWord() {
63+
return this.isFirstCharacterOfAWord;
64+
}
65+
66+
public boolean isCharacterAtTheBeginningOfNewLine() {
67+
return this.isCharacterAtTheBeginningOfNewLine;
68+
}
69+
70+
public boolean isCharacterCloseToPreviousWord() {
71+
return this.isCharacterCloseToPreviousWord;
72+
}
73+
74+
public String toString() {
75+
String toString = "";
76+
toString += this.index;
77+
toString += " ";
78+
toString += this.characterValue;
79+
toString += " isCharacterPartOfPreviousWord=" + this.isCharacterPartOfPreviousWord;
80+
toString += " isFirstCharacterOfAWord=" + this.isFirstCharacterOfAWord;
81+
toString += " isCharacterAtTheBeginningOfNewLine=" + this.isCharacterAtTheBeginningOfNewLine;
82+
toString += " isCharacterPartOfASentence=" + this.isCharacterCloseToPreviousWord;
83+
toString += " isCharacterCloseToPreviousWord=" + this.isCharacterCloseToPreviousWord;
84+
return toString;
85+
}
86+
87+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.reader.pdf.layout;
18+
19+
import org.apache.pdfbox.text.TextPosition;
20+
21+
class CharacterFactory {
22+
23+
private TextPosition previousTextPosition;
24+
25+
private boolean firstCharacterOfLineFound;
26+
27+
private boolean isCharacterPartOfPreviousWord;
28+
29+
private boolean isFirstCharacterOfAWord;
30+
31+
private boolean isCharacterAtTheBeginningOfNewLine;
32+
33+
private boolean isCharacterCloseToPreviousWord;
34+
35+
CharacterFactory(boolean firstCharacterOfLineFound) {
36+
this.firstCharacterOfLineFound = firstCharacterOfLineFound;
37+
}
38+
39+
public Character createCharacterFromTextPosition(final TextPosition textPosition,
40+
final TextPosition previousTextPosition) {
41+
this.setPreviousTextPosition(previousTextPosition);
42+
this.isCharacterPartOfPreviousWord = this.isCharacterPartOfPreviousWord(textPosition);
43+
this.isFirstCharacterOfAWord = this.isFirstCharacterOfAWord(textPosition);
44+
this.isCharacterAtTheBeginningOfNewLine = this.isCharacterAtTheBeginningOfNewLine(textPosition);
45+
this.isCharacterCloseToPreviousWord = this.isCharacterCloseToPreviousWord(textPosition);
46+
char character = this.getCharacterFromTextPosition(textPosition);
47+
int index = (int) textPosition.getX() / ForkPDFLayoutTextStripper.OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT;
48+
return new Character(character, index, this.isCharacterPartOfPreviousWord, this.isFirstCharacterOfAWord,
49+
this.isCharacterAtTheBeginningOfNewLine, this.isCharacterCloseToPreviousWord);
50+
}
51+
52+
private boolean isCharacterAtTheBeginningOfNewLine(final TextPosition textPosition) {
53+
if (!this.firstCharacterOfLineFound) {
54+
return true;
55+
}
56+
TextPosition previousTextPosition = this.getPreviousTextPosition();
57+
float previousTextYPosition = previousTextPosition.getY();
58+
return (Math.round(textPosition.getY()) < Math.round(previousTextYPosition));
59+
}
60+
61+
private boolean isFirstCharacterOfAWord(final TextPosition textPosition) {
62+
if (!this.firstCharacterOfLineFound) {
63+
return true;
64+
}
65+
double numberOfSpaces = this.numberOfSpacesBetweenTwoCharacters(this.previousTextPosition, textPosition);
66+
return (numberOfSpaces > 1) || this.isCharacterAtTheBeginningOfNewLine(textPosition);
67+
}
68+
69+
private boolean isCharacterCloseToPreviousWord(final TextPosition textPosition) {
70+
if (!this.firstCharacterOfLineFound) {
71+
return false;
72+
}
73+
double numberOfSpaces = this.numberOfSpacesBetweenTwoCharacters(this.previousTextPosition, textPosition);
74+
return (numberOfSpaces > 1 && numberOfSpaces <= ForkPDFLayoutTextStripper.OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT);
75+
}
76+
77+
private boolean isCharacterPartOfPreviousWord(final TextPosition textPosition) {
78+
TextPosition previousTextPosition = this.getPreviousTextPosition();
79+
if (previousTextPosition.getUnicode().equals(" ")) {
80+
return false;
81+
}
82+
double numberOfSpaces = this.numberOfSpacesBetweenTwoCharacters(previousTextPosition, textPosition);
83+
return (numberOfSpaces <= 1);
84+
}
85+
86+
private double numberOfSpacesBetweenTwoCharacters(final TextPosition textPosition1,
87+
final TextPosition textPosition2) {
88+
double previousTextXPosition = textPosition1.getX();
89+
double previousTextWidth = textPosition1.getWidth();
90+
double previousTextEndXPosition = (previousTextXPosition + previousTextWidth);
91+
double numberOfSpaces = Math.abs(Math.round(textPosition2.getX() - previousTextEndXPosition));
92+
return numberOfSpaces;
93+
}
94+
95+
private char getCharacterFromTextPosition(final TextPosition textPosition) {
96+
String string = textPosition.getUnicode();
97+
char character = string.charAt(0);
98+
return character;
99+
}
100+
101+
private TextPosition getPreviousTextPosition() {
102+
return this.previousTextPosition;
103+
}
104+
105+
private void setPreviousTextPosition(final TextPosition previousTextPosition) {
106+
this.previousTextPosition = previousTextPosition;
107+
}
108+
109+
}

0 commit comments

Comments
 (0)