Skip to content

Commit 4bd1e61

Browse files
committed
feat: Sonar improvements
1 parent 4a1c1bf commit 4bd1e61

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

chapter7/Monitor/src/main/java/file/TextSearcher.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class TextSearcher extends Thread {
6161

6262
/**
6363
* Constructor for text searcher thread.
64+
*
6465
* @param text search text.
6566
* @param storage instance of file storage for store already checked file.
6667
*/
@@ -72,6 +73,7 @@ public TextSearcher(final String text, final FileStorage storage) {
7273

7374
/**
7475
* Return true if something was found.
76+
*
7577
* @return true if something was found, otherwise false.
7678
*/
7779
public boolean getFounded() {
@@ -98,6 +100,7 @@ public void brake() {
98100

99101
/**
100102
* Return list of found files.
103+
*
101104
* @return list of found files.
102105
*/
103106
public List<String> getFileList() {
@@ -112,12 +115,13 @@ public List<String> getFileList() {
112115
*/
113116
private void searchFromDisk() {
114117
for (File disk : disks) {
115-
search(disk.getAbsolutePath());
118+
search(disk.getAbsolutePath());
116119
}
117120
}
118121

119122
/**
120123
* Recursive search from directory to file.
124+
*
121125
* @param disk start of search.
122126
* @return true if text is find, otherwise false.
123127
*/
@@ -128,7 +132,7 @@ private boolean search(String disk) {
128132
if (file.isDirectory()) {
129133
search(file.getAbsolutePath());
130134
} else if (isCorrectFile(file) && !this.isInterrupted()) {
131-
processingFile(file, this.searchText);
135+
processFile(file, this.searchText);
132136
}
133137
}
134138
}
@@ -137,23 +141,28 @@ private boolean search(String disk) {
137141

138142
/**
139143
* Read file and set founded flag.
144+
*
140145
* @param file for reading.
141146
* @param text for searching.
142147
*/
143-
private void processingFile(File file, String text) {
148+
private void processFile(File file, String text) {
144149
this.founded = readFile(file.getAbsolutePath(), text);
145-
log.info(String.format("SEARCH AT: %s", file.getAbsolutePath()));
146-
if (this.founded) {
147-
log.info(String.format("FOUND AT: %s", file.getAbsolutePath()));
148-
synchronized (this.resultFiles) {
149-
this.resultFiles.add(file.getAbsolutePath());
150-
}
150+
if (log.isInfoEnabled()) {
151+
log.info("SEARCH AT: {}", file.getAbsolutePath());
152+
}
153+
if (this.founded && log.isInfoEnabled()) {
154+
log.info("FOUND AT: {}", file.getAbsolutePath());
155+
}
156+
157+
synchronized (this.resultFiles) {
158+
this.resultFiles.add(file.getAbsolutePath());
151159
}
152160
this.fileStorage.addCheckedFile(file.getAbsolutePath());
153161
}
154162

155163
/**
156164
* Read file.
165+
*
157166
* @param file for reading.
158167
* @param text for searching.
159168
* @return true if some string in file contains text or
@@ -182,6 +191,7 @@ private boolean readFile(String file, String text) {
182191
/**
183192
* Checked that current file correct.
184193
* Correct means that file not read yet, not hidden and can read.
194+
*
185195
* @param file instance of file.
186196
* @return true if all expression is true, otherwise false.
187197
*/

chapter8/Parser/src/main/java/parser/Parser.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ private Vacancy parseVacancy(Element worksTopic) {
296296
try {
297297
Document worksPage = Jsoup.connect(url).get();
298298
String description = worksPage.getElementsByClass(MSG_BODY).select(TD_TAG).text();
299-
log.info("Found vacancy: {}", worksTopic.text());
299+
if (log.isInfoEnabled()) {
300+
log.info("Found vacancy: {}", worksTopic.text());
301+
log.info("Was published at: {}", this.getPublishDate(worksPage));
302+
}
300303
log.info("With next desc:\n{}", description);
301-
log.info("Was published at: {}", this.getPublishDate(worksPage));
302304
vacancy = new Vacancy(worksTopic.text(), description, this.dateParser.parseDate(getPublishDate(worksPage)), url);
303305
} catch (IOException | ParseException ioe) {
304306
log.warn(ioe.getMessage(), ioe);

chapter8/Parser/src/main/java/start/TextSimilarityChecker.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public boolean haveSimilarVacancy(String text) {
4848
String description = savedVacancies.getString("description");
4949
double percentage = StringUtils.getJaroWinklerDistance(text, description) * 100;
5050

51-
log.info(String.format("%.2f percentage between vacancies", percentage));
51+
if (log.isInfoEnabled()) {
52+
log.info(String.format("%.2f percentage between vacancies", percentage));
53+
}
5254
if (Double.compare(percentage, 45.0d) > 0) {
5355
haveSimilar = true;
5456
}

chapter9/Bank/src/main/java/model/Client.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public Client(long timeIn, long timeOut) {
3838
this.checkTime(timeIn, timeOut);
3939
this.timeIn = timeIn;
4040
this.timeOut = timeOut;
41-
log.info(this.toString());
41+
if (log.isInfoEnabled()) {
42+
log.info(this.toString());
43+
}
4244
}
4345

4446
/**

0 commit comments

Comments
 (0)