Skip to content

Commit 9a88d8a

Browse files
authored
Remove redundant field initializers (#13060)
Make protected fields in final classes private.
1 parent 39f6818 commit 9a88d8a

File tree

32 files changed

+48
-48
lines changed

32 files changed

+48
-48
lines changed

lucene/analysis/common/src/java/org/apache/lucene/analysis/minhash/MinHashFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public class MinHashFilter extends TokenFilter {
5959

6060
private final List<List<FixedSizeTreeSet<LongPair>>> minHashSets;
6161

62-
private int hashSetSize = DEFAULT_HASH_SET_SIZE;
62+
private final int hashSetSize;
6363

64-
private int bucketCount = DEFAULT_BUCKET_COUNT;
64+
private final int bucketCount;
6565

66-
private int hashCount = DEFAULT_HASH_COUNT;
66+
private final int hashCount;
6767

6868
private boolean requiresInitialisation = true;
6969

lucene/analysis/common/src/java/org/apache/lucene/analysis/minhash/MinHashFilterFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public class MinHashFilterFactory extends TokenFilterFactory {
3232
/** SPI name */
3333
public static final String NAME = "minHash";
3434

35-
private int hashCount = MinHashFilter.DEFAULT_HASH_COUNT;
35+
private final int hashCount;
3636

37-
private int bucketCount = MinHashFilter.DEFAULT_BUCKET_COUNT;
37+
private final int bucketCount;
3838

39-
private int hashSetSize = MinHashFilter.DEFAULT_HASH_SET_SIZE;
39+
private final int hashSetSize;
4040

41-
private boolean withRotation;
41+
private final boolean withRotation;
4242

4343
/** Create a {@link MinHashFilterFactory}. */
4444
public MinHashFilterFactory(Map<String, String> args) {

lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/WordDelimiterGraphFilterFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class WordDelimiterGraphFilterFactory extends TokenFilterFactory
6767
private final int flags;
6868
byte[] typeTable = null;
6969
private CharArraySet protectedWords = null;
70-
private boolean adjustOffsets = false;
70+
private final boolean adjustOffsets;
7171

7272
/** Creates a new WordDelimiterGraphFilterFactory */
7373
public WordDelimiterGraphFilterFactory(Map<String, String> args) {

lucene/analysis/common/src/java/org/apache/lucene/analysis/nl/DutchAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static class DefaultSetHolder {
8989
private final CharArraySet stoptable;
9090

9191
/** Contains words that should be indexed but not stemmed. */
92-
private CharArraySet excltable = CharArraySet.EMPTY_SET;
92+
private final CharArraySet excltable;
9393

9494
private final StemmerOverrideMap stemdict;
9595

lucene/analysis/common/src/java/org/apache/lucene/analysis/pattern/PatternCaptureGroupFilterFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public class PatternCaptureGroupFilterFactory extends TokenFilterFactory {
4141
/** SPI name */
4242
public static final String NAME = "patternCaptureGroup";
4343

44-
private Pattern pattern;
45-
private boolean preserveOriginal = true;
44+
private final Pattern pattern;
45+
private final boolean preserveOriginal;
4646

4747
public PatternCaptureGroupFilterFactory(Map<String, String> args) {
4848
super(args);

lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseTokenizerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class JapaneseTokenizerFactory extends TokenizerFactory implements Resour
114114
* /箱根山-箱根/成田空港-成田/ requests "箱根" and "成田" to be in the result in NBEST output.
115115
*/
116116
private final String nbestExamples;
117-
private int nbestCost = -1;
117+
private int nbestCost;
118118

119119
/** Creates a new JapaneseTokenizerFactory */
120120
public JapaneseTokenizerFactory(Map<String, String> args) {

lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/OpenNLPTokenizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class OpenNLPTokenizer extends SegmentingTokenizerBase {
4444
private int sentenceStart = 0;
4545
private int sentenceIndex = -1;
4646

47-
private NLPTokenizerOp tokenizerOp = null;
47+
private final NLPTokenizerOp tokenizerOp;
4848

4949
public OpenNLPTokenizer(
5050
AttributeFactory factory, NLPSentenceDetectorOp sentenceOp, NLPTokenizerOp tokenizerOp)

lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/tools/NLPChunkerOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/** Supply OpenNLP Chunking tool Requires binary models from OpenNLP project on SourceForge. */
2525
public class NLPChunkerOp {
26-
private ChunkerME chunker = null;
26+
private final ChunkerME chunker;
2727

2828
public NLPChunkerOp(ChunkerModel chunkerModel) throws IOException {
2929
chunker = new ChunkerME(chunkerModel);

lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/tools/NLPPOSTaggerOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* SourceForge.
2828
*/
2929
public class NLPPOSTaggerOp {
30-
private POSTagger tagger = null;
30+
private final POSTagger tagger;
3131

3232
public NLPPOSTaggerOp(POSModel model) throws IOException {
3333
tagger = new POSTaggerME(model);

lucene/analysis/phonetic/src/java/org/apache/lucene/analysis/phonetic/DaitchMokotoffSoundexFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
*/
3333
public final class DaitchMokotoffSoundexFilter extends TokenFilter {
3434
/** true if encoded tokens should be added as synonyms */
35-
protected boolean inject = true;
35+
private final boolean inject;
3636

3737
/** phonetic encoder */
38-
protected DaitchMokotoffSoundex encoder = new DaitchMokotoffSoundex();
38+
private final DaitchMokotoffSoundex encoder = new DaitchMokotoffSoundex();
3939

4040
// output is a string such as ab|ac|...
4141
private static final Pattern pattern = Pattern.compile("([^|]+)");

lucene/analysis/phonetic/src/java/org/apache/lucene/analysis/phonetic/PhoneticFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
*/
3333
public final class PhoneticFilter extends TokenFilter {
3434
/** true if encoded tokens should be added as synonyms */
35-
protected boolean inject = true;
35+
private final boolean inject;
3636

3737
/** phonetic encoder */
38-
protected Encoder encoder = null;
38+
private final Encoder encoder;
3939

4040
/** captured state, non-null when <code>inject=true</code> and a token is buffered */
41-
protected State save = null;
41+
private State save = null;
4242

4343
private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
4444
private final PositionIncrementAttribute posAtt = addAttribute(PositionIncrementAttribute.class);

lucene/analysis/stempel/src/java/org/egothor/stemmer/Trie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class Trie {
7373
List<CharSequence> cmds = new ArrayList<>();
7474
int root;
7575

76-
boolean forward = false;
76+
boolean forward;
7777

7878
/**
7979
* Constructor for the Trie object.

lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/TaskSequence.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class TaskSequence extends PerfTask {
4343
private boolean resetExhausted = false;
4444
private PerfTask[] tasksArray;
4545
private boolean anyExhaustibleTasks;
46-
private boolean collapsable = false; // to not collapse external sequence named in alg.
46+
private final boolean collapsable; // to not collapse external sequence named in alg.
4747

4848
private boolean fixedTime; // true if we run for fixed time
4949
private double runTimeSec; // how long to run for

lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestTrecContentSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TestTrecContentSource extends LuceneTestCase {
3636
/** A TrecDocMaker which works on a String and not files. */
3737
private static class StringableTrecSource extends TrecContentSource {
3838

39-
private String docs = null;
39+
private final String docs;
4040

4141
public StringableTrecSource(String docs, boolean forever) {
4242
this.docs = docs;

lucene/core/src/java/org/apache/lucene/index/FieldInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class FieldInfo {
3232
/** Internal field number */
3333
public final int number;
3434

35-
private DocValuesType docValuesType = DocValuesType.NONE;
35+
private DocValuesType docValuesType;
3636

3737
// True if any document indexed term vectors
3838
private boolean storeTermVector;

lucene/core/src/java/org/apache/lucene/index/LiveIndexWriterConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class LiveIndexWriterConfig {
8484
protected volatile int perThreadHardLimitMB;
8585

8686
/** True if segment flushes should use compound file format */
87-
protected volatile boolean useCompoundFile = IndexWriterConfig.DEFAULT_USE_COMPOUND_FILE_SYSTEM;
87+
protected volatile boolean useCompoundFile;
8888

8989
/** True if calls to {@link IndexWriter#close()} should first do a commit. */
9090
protected boolean commitOnClose = IndexWriterConfig.DEFAULT_COMMIT_ON_CLOSE;

lucene/core/src/java/org/apache/lucene/index/MergePolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,12 @@ public MergeAbortedException(String message) {
597597
* If the size of the merge segment exceeds this ratio of the total index size then it will remain
598598
* in non-compound format
599599
*/
600-
protected double noCFSRatio = DEFAULT_NO_CFS_RATIO;
600+
protected double noCFSRatio;
601601

602602
/**
603603
* If the size of the merged segment exceeds this value then it will not use compound file format.
604604
*/
605-
protected long maxCFSSegmentSize = DEFAULT_MAX_CFS_SEGMENT_SIZE;
605+
protected long maxCFSSegmentSize;
606606

607607
/** Creates a new merge policy instance. */
608608
protected MergePolicy() {

lucene/core/src/java/org/apache/lucene/search/WANDScorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static long scaleMinScore(float minScore, int scalingFactor) {
120120

121121
private final int scalingFactor;
122122
// scaled min competitive score
123-
private long minCompetitiveScore = 0;
123+
private long minCompetitiveScore;
124124

125125
private final Scorer[] allScorers;
126126

lucene/core/src/java/org/apache/lucene/search/comparators/TermOrdValComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class TermOrdValComparator extends FieldComparator<BytesRef> {
8989
private boolean singleSort;
9090

9191
/** Whether this comparator is allowed to skip documents. */
92-
private boolean canSkipDocuments = true;
92+
private boolean canSkipDocuments;
9393

9494
/** Whether the collector is done with counting hits so that we can start skipping documents. */
9595
private boolean hitsThresholdReached = false;

lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public DocIdSetIterator iterator() throws IOException {
253253
private class Iterator extends DocIdSetIterator {
254254

255255
int block;
256-
DocIdSetIterator sub = null;
256+
DocIdSetIterator sub;
257257
int doc;
258258

259259
Iterator() throws IOException {

lucene/core/src/java/org/apache/lucene/util/automaton/LimitedFiniteStringsIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class LimitedFiniteStringsIterator extends FiniteStringsIterator {
3333
/** Maximum number of finite strings to create. */
34-
private int limit = Integer.MAX_VALUE;
34+
private final int limit;
3535

3636
/** Number of generated finite strings. */
3737
private int count = 0;

lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/OffsetsEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static class OfPostings extends OffsetsEnum {
123123
private final PostingsEnum postingsEnum; // with offsets
124124
private final int freq;
125125

126-
private int posCounter = -1;
126+
private int posCounter;
127127

128128
public OfPostings(BytesRef term, int freq, PostingsEnum postingsEnum) throws IOException {
129129
this.term = Objects.requireNonNull(term);

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BoostQueryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public class BoostQueryNode extends QueryNodeImpl {
3232

33-
private float value = 0;
33+
private float value;
3434

3535
/**
3636
* Constructs a boost node

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ModifierQueryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public String toLargeString() {
8484
}
8585
}
8686

87-
private Modifier modifier = Modifier.MOD_NONE;
87+
private Modifier modifier;
8888

8989
/**
9090
* Used to store the modifier value on the original query string

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/OpaqueQueryNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
*/
2626
public class OpaqueQueryNode extends QueryNodeImpl {
2727

28-
private CharSequence schema = null;
28+
private CharSequence schema;
2929

30-
private CharSequence value = null;
30+
private CharSequence value;
3131

3232
/**
3333
* @param schema - schema identifier

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/PathQueryNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class PathQueryNode extends QueryNodeImpl {
4141

4242
/** Term text with a beginning and end position */
4343
public static class QueryText implements Cloneable {
44-
CharSequence value = null;
44+
CharSequence value;
4545

4646
/** != null The term's begin position. */
4747
int begin;
@@ -97,7 +97,7 @@ public String toString() {
9797
}
9898
}
9999

100-
private List<QueryText> values = null;
100+
private List<QueryText> values;
101101

102102
/**
103103
* @param pathElements - List of QueryText objects

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/PhraseSlopQueryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/** Query node for {@link PhraseQuery}'s slop factor. */
2626
public class PhraseSlopQueryNode extends QueryNodeImpl implements FieldableNode {
2727

28-
private int value = 0;
28+
private int value;
2929

3030
/**
3131
* @exception QueryNodeError throw in overridden method to disallow

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ProximityQueryNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ CharSequence toQueryString() {
5757

5858
/** utility class containing the distance condition and number */
5959
public static class ProximityType {
60-
int pDistance = 0;
60+
int pDistance;
6161

62-
Type pType = null;
62+
Type pType;
6363

6464
public ProximityType(Type type) {
6565
this(type, 0);
@@ -71,10 +71,10 @@ public ProximityType(Type type, int distance) {
7171
}
7272
}
7373

74-
private Type proximityType = Type.SENTENCE;
74+
private Type proximityType;
7575
private int distance = -1;
76-
private boolean inorder = false;
77-
private CharSequence field = null;
76+
private final boolean inorder;
77+
private CharSequence field;
7878

7979
/**
8080
* @param clauses - QueryNode children

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/SlopQueryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public class SlopQueryNode extends QueryNodeImpl implements FieldableNode {
3434

35-
private int value = 0;
35+
private int value;
3636

3737
/**
3838
* @param query - QueryNode Tree with the phrase

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/FieldBoostMapFCListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class FieldBoostMapFCListener implements FieldConfigListener {
3636

37-
private QueryConfigHandler config = null;
37+
private final QueryConfigHandler config;
3838

3939
public FieldBoostMapFCListener(QueryConfigHandler config) {
4040
this.config = config;

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/FieldDateResolutionFCListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
public class FieldDateResolutionFCListener implements FieldConfigListener {
3838

39-
private QueryConfigHandler config = null;
39+
private final QueryConfigHandler config;
4040

4141
public FieldDateResolutionFCListener(QueryConfigHandler config) {
4242
this.config = config;

lucene/test-framework/src/java/org/apache/lucene/tests/index/DocHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public class DocHelper {
175175
public static Field textUtfField2 =
176176
new Field(TEXT_FIELD_UTF2_KEY, FIELD_UTF2_TEXT, TEXT_TYPE_STORED_WITH_TVS);
177177

178-
public static Map<String, Object> nameValues = null;
178+
public static Map<String, Object> nameValues;
179179

180180
// ordered list of all the fields...
181181
// could use LinkedHashMap for this purpose if Java1.4 is OK

0 commit comments

Comments
 (0)