Fix test and suppress checkstyle warnings

This commit is contained in:
Thierry Göckel 2020-08-10 19:04:29 +02:00
parent d97a7b629a
commit a6415363cd
4 changed files with 22 additions and 20 deletions

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.iqser.red.service.redaction.v1.server.parsing.model.TextPositionSequence;
import com.iqser.red.service.redaction.v1.server.redaction.utils.TextNormalizationUtilities;
@ -26,6 +25,7 @@ public class SearchableText {
}
@SuppressWarnings("checkstyle:ModifiedControlVariable")
public List<EntityPositionSequence> getSequences(String searchString, boolean caseInsensitive) {
String normalizedSearchString;
@ -64,9 +64,9 @@ public class SearchableText {
.charAt(j, caseInsensitive) == '-') {
if (counter != 0 || i == 0 && j == 0 || j != 0 && isSeparator(sequences.get(i)
.charAt(j - 1, caseInsensitive)) || j == 0 && isSeparator(sequences.get(i - 1)
.charAt(j - 1, caseInsensitive)) || j == 0 && i != 0 && isSeparator(sequences.get(i - 1)
.charAt(sequences.get(i - 1)
.length() - 1, caseInsensitive)) || j == 0 && sequences.get(i - 1)
.length() - 1, caseInsensitive)) || j == 0 && i != 0 && sequences.get(i - 1)
.charAt(sequences.get(i - 1).length() - 1, caseInsensitive) != ' ' && sequences.get(i)
.charAt(j, caseInsensitive) != ' ') {
partMatch.add(sequences.get(i).textPositionAt(j));
@ -187,10 +187,4 @@ public class SearchableText {
return sb.append("\n").toString();
}
public List<String> getAsTabularData() {
return sequences.stream().map(TextPositionSequence::toString).collect(Collectors.toList());
}
}

View File

@ -7,9 +7,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -52,7 +51,7 @@ public class EntityRedactionService {
SearchableText searchableRow = new SearchableText();
List<String> cellValues = new ArrayList<>();
for (Cell cell : row) {
if (cell == null || cell.getTextBlocks() == null) {
if (cell == null || CollectionUtils.isEmpty(cell.getTextBlocks())) {
cellValues.add(null);
continue;
}
@ -113,7 +112,16 @@ public class EntityRedactionService {
private Map<String, String> toMap(List<String> keys, List<String> values) {
return IntStream.range(0, keys.size()).boxed().collect(Collectors.toMap(keys::get, values::get));
if (keys.size() != values.size()) {
throw new RuntimeException("Cannot merge lists of unequal size.");
}
Map<String, String> result = new HashMap<>();
for (int i = 0; i < keys.size(); i++) {
result.put(keys.get(i), values.get(i));
}
return result;
}

View File

@ -41,13 +41,14 @@ public class SectionsBuilderService {
Paragraph chunkBlock = buildTextBlock(chunkWords, lastHeadline, previousTable);
chunkBlock.setHeadline(lastHeadline);
lastHeadline = current.getText();
if (CollectionUtils.isNotEmpty(chunkBlock.getTables())) {
previousTable = chunkBlock.getTables().get(0);
}
chunkBlockList.add(chunkBlock);
chunkWords = new ArrayList<>();
}
chunkWords.add(current);
prev = current;
}
}
@ -95,7 +96,6 @@ public class SectionsBuilderService {
alreadyAdded = true;
}
paragraph.getPageBlocks().add(table);
previousTable = table;
continue;
}

View File

@ -82,7 +82,7 @@ public class Table extends AbstractTextContainer {
boolean allBold = true;
List<Cell> rowCells = rows.get(0);
for (Cell cell : rowCells) {
if (CollectionUtils.isNotEmpty(cell.getTextBlocks()) &&
if (cell == null || CollectionUtils.isEmpty(cell.getTextBlocks()) ||
!cell.getTextBlocks().get(0).getMostPopularWordStyle().equals("bold")) {
allBold = false;
break;
@ -93,7 +93,7 @@ public class Table extends AbstractTextContainer {
List<Cell> firstColCells = new ArrayList<>();
for (List<Cell> row : rows) {
Cell firstInRow = row.get(0);
if (CollectionUtils.isNotEmpty(firstInRow.getTextBlocks()) &&
if (firstInRow == null || CollectionUtils.isEmpty(firstInRow.getTextBlocks()) ||
!firstInRow.getTextBlocks().get(0).getMostPopularWordStyle().equals("bold")) {
allBold = false;
break;
@ -113,7 +113,7 @@ public class Table extends AbstractTextContainer {
} else {
log.info("Headers are defaulted in first row.");
return rowCells.stream().map(cell -> {
if (CollectionUtils.isNotEmpty(cell.getTextBlocks())) {
if (cell != null && CollectionUtils.isNotEmpty(cell.getTextBlocks())) {
return cell.getTextBlocks().get(0).getText();
} else {
return null;
@ -171,7 +171,7 @@ public class Table extends AbstractTextContainer {
}
public void add(Cell chunk, int row, int col) {
private void add(Cell chunk, int row, int col) {
rowCount = Math.max(rowCount, row + 1);
colCount = Math.max(colCount, col + 1);