Skip to content

Commit 4439de8

Browse files
committed
SonarQube fixes.
- HTML DOCTYPE, lang, title - avoid shadowing field from superclass - avoid switch fallthrough - accidental use of & - SpanQuerySequence: fix accidental shortcircuiting optimizations - number type casts
1 parent 2a979a1 commit 4439de8

20 files changed

Lines changed: 64 additions & 58 deletions

File tree

core/src/test/java/nl/inl/blacklab/searches/TestSearchHitGroups.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.junit.runners.Parameterized;
1313

1414
import nl.inl.blacklab.exceptions.InvalidQuery;
15-
import nl.inl.blacklab.resultproperty.HitGroupProperty;
1615
import nl.inl.blacklab.resultproperty.HitGroupPropertyIdentity;
1716
import nl.inl.blacklab.resultproperty.HitProperty;
1817
import nl.inl.blacklab.resultproperty.HitPropertyHitText;
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<html>
2-
<head></head>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head><title>package info: blacklab.contentstore</title></head>
34
<body>
45
<p>Deals with storing the original content for highlighting whole documents
56
with hits.</p>
67
</body>
7-
</html>
8+
</html>

engine/src/main/java/nl/inl/blacklab/indexers/config/DocIndexerChat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class DocIndexerChat extends DocIndexerConfig {
5353
/** Fallback locale in case we can't parse the date */
5454
private final Locale usLocale = new Locale("en", "US");
5555

56-
private ConfigAnnotatedField currentAnnotatedField;
56+
private ConfigAnnotatedField currentAnnotatedFieldConfig;
5757

5858
@Override
5959
public void indexSpecificDocument(String documentExpr) {
@@ -125,7 +125,7 @@ public void index() throws IOException, PluginException {
125125

126126
// For the configured annotated field...
127127
for (ConfigAnnotatedField annotatedField : config.getAnnotatedFields().values()) {
128-
currentAnnotatedField = annotatedField;
128+
currentAnnotatedFieldConfig = annotatedField;
129129
setCurrentAnnotatedFieldName(annotatedField.getName());
130130

131131
log("processing " + documentName + "...");
@@ -455,7 +455,7 @@ private void addWords(String line) {
455455
String[] words = line.trim().split(StringUtil.REGEX_WHITESPACE);
456456
for (String word : words) {
457457
beginWord();
458-
for (ConfigAnnotation annot : currentAnnotatedField.getAnnotationsFlattened().values()) {
458+
for (ConfigAnnotation annot : currentAnnotatedFieldConfig.getAnnotationsFlattened().values()) {
459459
String processed = annot.getProcess().performSingle(word, this);
460460
annotationValueAppend(annot.getName(), processed, 1);
461461
}

engine/src/main/java/nl/inl/blacklab/indexers/config/DocIndexerExample.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class DocIndexerExample extends DocIndexerBase {
8383
private boolean inDoc = false;
8484

8585
/** Name of annotated field we're processing or null if not in annotated field part */
86-
private String currentAnnotatedField = null;
86+
private String currentAnnotatedFieldName = null;
8787

8888
/** Are we in an annotated field block and have we called beginWord()? Then make sure to call endWord(). */
8989
private boolean inWord = false;
@@ -233,7 +233,7 @@ private void processLine(String line) {
233233
}
234234

235235
private void executeCommand(String command, String[] parameters) {
236-
if (currentAnnotatedField != null) {
236+
if (currentAnnotatedFieldName != null) {
237237
// We're inside an annotated field value block (nested inside a document block).
238238
executeValueCommand(command, parameters);
239239
} else if (inDoc) {
@@ -311,7 +311,7 @@ private void executeValueCommand(String command, String[] parameters) {
311311
endWord();
312312
inWord = false;
313313
}
314-
currentAnnotatedField = null;
314+
currentAnnotatedFieldName = null;
315315
break;
316316

317317
default:
@@ -325,7 +325,7 @@ protected void endWord() {
325325

326326
// Make sure that all annotations are at the same token position.
327327
// (we don't want annotations to run out of synch)
328-
for (AnnotationWriter aw: getAnnotatedField(currentAnnotatedField).annotationWriters()) {
328+
for (AnnotationWriter aw: getAnnotatedField(currentAnnotatedFieldName).annotationWriters()) {
329329
while (aw.lastValuePosition() < currentTokenPosition) {
330330
aw.addValue("");
331331
}
@@ -349,10 +349,10 @@ private void executeDocumentCommand(String command, String[] parameters) {
349349

350350
case "FIELD_START":
351351
// Starts an annotated field block.
352-
currentAnnotatedField = parameters[0];
352+
currentAnnotatedFieldName = parameters[0];
353353
//posIncr = 1; // initialize at default value
354354
currentTokenPosition = 0;
355-
setCurrentAnnotatedFieldName(currentAnnotatedField);
355+
setCurrentAnnotatedFieldName(currentAnnotatedFieldName);
356356
break;
357357

358358
case "DOC_END":

engine/src/main/java/nl/inl/blacklab/indexers/config/InputFormatReader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ private void readAnnotatedFields(Entry<String, JsonNode> afsEntry, ConfigInputFo
381381
break;
382382
case "tokenPositionIdPath": // old name, DEPRECATED
383383
logger.warn("Encountered deprecated key 'tokenPositionIdPath' (rename to 'tokenIdPath') in annotated field " + fieldName + inFormat());
384+
af.setTokenIdPath(str(e));
385+
break;
384386
case "tokenIdPath":
385387
af.setTokenIdPath(str(e));
386388
break;
@@ -540,6 +542,8 @@ private void readStandoffAnnotations(Entry<String, JsonNode> sasEntry, ConfigAnn
540542
break;
541543
case "refTokenPositionIdPath": // old name, DEPRECATED
542544
logger.warn("Encountered deprecated key 'refTokenPositionIdPath' (rename to 'tokenRefPath')");
545+
s.setTokenRefPath(str(e));
546+
break;
543547
case "tokenRefPath":
544548
case "spanStartPath": // synonym, used for span annotation
545549
case "sourcePath": // synonym, used for relation annotation
@@ -554,6 +558,8 @@ private void readStandoffAnnotations(Entry<String, JsonNode> sasEntry, ConfigAnn
554558
break;
555559
case "spanNamePath": // DEPRECATED
556560
logger.warn("Encountered deprecated key 'spanNamePath' (rename to 'valuePath')");
561+
s.setValuePath(str(e));
562+
break;
557563
case "valuePath":
558564
s.setValuePath(str(e));
559565
break;
@@ -615,6 +621,7 @@ private void readInlineTags(Entry<String, JsonNode> itsEntry, ConfigAnnotatedFie
615621
throw new InvalidInputFormatConfig("extraAttributes not allowed in .blf.yaml version 2 (use 'attributes' instead)");
616622
logger.warn("Encountered deprecated key 'extraAttributes' (use 'attributes' instead)");
617623
t.setAttributes(readExtraAttributes(e));
624+
break;
618625
case "attributes":
619626
t.setAttributes(readExtraAttributes(e));
620627
break;

engine/src/main/java/nl/inl/blacklab/resultproperty/HitPropertyAlignments.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ static HitPropertyAlignments deserializeProp(BlackLabIndex index, AnnotatedField
2626
return new HitPropertyAlignments();
2727
}
2828

29-
private Hits hits;
30-
3129
HitPropertyAlignments(HitPropertyAlignments prop, Hits hits, boolean invert) {
32-
super();
33-
this.hits = hits;
34-
reverse = prop.reverse ? !invert : invert;
30+
super(prop, hits, invert);
3531
}
3632

3733
private synchronized List<Integer> getTargetHitGroupIndexes() {
@@ -111,12 +107,11 @@ public boolean equals(Object o) {
111107
if (!super.equals(o))
112108
return false;
113109
HitPropertyAlignments that = (HitPropertyAlignments) o;
114-
return Objects.equals(targetHitGroupIndexes, that.targetHitGroupIndexes) && Objects.equals(hits,
115-
that.hits);
110+
return Objects.equals(targetHitGroupIndexes, that.targetHitGroupIndexes);
116111
}
117112

118113
@Override
119114
public int hashCode() {
120-
return Objects.hash(super.hashCode(), targetHitGroupIndexes, hits);
115+
return Objects.hash(super.hashCode(), targetHitGroupIndexes);
121116
}
122117
}

engine/src/main/java/nl/inl/blacklab/resultproperty/HitPropertySpanAttribute.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,13 @@ static HitPropertySpanAttribute deserializeProp(BlackLabIndex index, AnnotatedFi
5858
/** The sensitivity of the match */
5959
private MatchSensitivity sensitivity;
6060

61-
private Hits hits;
62-
6361
HitPropertySpanAttribute(HitPropertySpanAttribute prop, Hits hits, boolean invert) {
64-
super();
62+
super(prop, hits, invert);
6563
groupName = prop.groupName;
6664
relNameInList = prop.relNameInList;
6765
relNameIsFullRelType = prop.relNameIsFullRelType;
6866
attributeName = prop.attributeName;
6967
sensitivity = prop.sensitivity;
70-
this.hits = hits;
71-
reverse = prop.reverse ? !invert : invert;
7268

7369
// Determine group index. We don't use the one from prop (if any), because
7470
// index might be different for different hits object.
@@ -179,12 +175,12 @@ public boolean equals(Object o) {
179175
HitPropertySpanAttribute that = (HitPropertySpanAttribute) o;
180176
return Objects.equals(groupName, that.groupName) && Objects.equals(relNameInList,
181177
that.relNameInList) && Objects.equals(attributeName, that.attributeName)
182-
&& sensitivity == that.sensitivity && Objects.equals(hits, that.hits);
178+
&& sensitivity == that.sensitivity;
183179
}
184180

185181
@Override
186182
public int hashCode() {
187183
return Objects.hash(super.hashCode(), groupName, relNameInList, attributeName,
188-
sensitivity, hits);
184+
sensitivity);
189185
}
190186
}

engine/src/main/java/nl/inl/blacklab/search/indexmetadata/Annotation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ default AnnotationSensitivities sensitivitySetting() {
141141

142142
if (s && i && ci && di)
143143
return AnnotationSensitivities.CASE_AND_DIACRITICS_SEPARATE;
144-
else if (s & i)
144+
else if (s && i)
145145
return AnnotationSensitivities.SENSITIVE_AND_INSENSITIVE;
146146
else if (i)
147147
return AnnotationSensitivities.ONLY_INSENSITIVE;

engine/src/main/java/nl/inl/blacklab/search/lucene/SpanQueryAndNot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public BLSpanQuery rewrite(IndexReader reader) throws IOException {
254254
// Rewrite clauses, and again flatten/invert if necessary.
255255
List<BLSpanQuery> rewrCl = new ArrayList<>();
256256
List<BLSpanQuery> rewrNotCl = new ArrayList<>();
257-
anyRewritten = anyRewritten | rewriteFlattenInvert(reader, flatCl, flatNotCl, rewrCl, rewrNotCl);
257+
anyRewritten |= rewriteFlattenInvert(reader, flatCl, flatNotCl, rewrCl, rewrNotCl);
258258

259259
if (rewrCl.isEmpty()) {
260260
// All-negative; node should be rewritten to OR.

engine/src/main/java/nl/inl/blacklab/search/lucene/SpanQuerySequence.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ protected boolean matchingTagsToPosFilter(List<BLSpanQuery> clauses) {
165165
for (int i = 0; i < clauses.size(); i++) {
166166
BLSpanQuery clause = clauses.get(i);
167167
if (clause instanceof SpanQueryEdge) {
168-
anyRewritten = anyRewritten || matchingTagsWithEdge(clauses, i);
168+
anyRewritten |= matchingTagsWithEdge(clauses, i);
169169
} else if (clause instanceof SpanQueryRelations) {
170-
anyRewritten = anyRewritten || matchingTagsWithRelations(clauses, i);
170+
anyRewritten |= matchingTagsWithRelations(clauses, i);
171171
}
172172
}
173173
return anyRewritten;

0 commit comments

Comments
 (0)