Skip to content

Commit

Permalink
SWEEP: Make private/internal fields readonly where possible, #661
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Jan 19, 2025
1 parent 5374caa commit ec0d6d7
Show file tree
Hide file tree
Showing 105 changed files with 398 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ namespace Lucene.Net.Analysis.Br
*/

/// <summary>
/// <see cref="Analyzer"/> for Brazilian Portuguese language.
/// <see cref="Analyzer"/> for Brazilian Portuguese language.
/// <para>
/// Supports an external list of stopwords (words that
/// will not be indexed at all) and an external list of exclusions (words that will
/// not be stemmed, but indexed).
/// </para>
///
///
/// <para><b>NOTE</b>: This class uses the same <see cref="LuceneVersion"/>
/// dependent settings as <see cref="StandardAnalyzer"/>.</para>
/// </summary>
Expand Down Expand Up @@ -77,7 +77,7 @@ private static CharArraySet LoadDefaultStopSet() // LUCENENET: Avoid static cons
/// <summary>
/// Contains words that should be indexed but not stemmed.
/// </summary>
private CharArraySet excltable = CharArraySet.Empty;
private readonly CharArraySet excltable = CharArraySet.Empty; // LUCENENET: marked readonly

/// <summary>
/// Builds an analyzer with the default stop words (<see cref="DefaultStopSet"/>).
Expand Down Expand Up @@ -135,4 +135,4 @@ protected internal override TokenStreamComponents CreateComponents(string fieldN
return new TokenStreamComponents(source, new BrazilianStemFilter(result));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30792,19 +30792,19 @@ CharArrayDictionary<char> result
private static readonly char STYLE_REPLACEMENT = '\n';
private static readonly char REPLACEMENT_CHARACTER = '\uFFFD';

private CharArraySet escapedTags = null;
private readonly CharArraySet escapedTags = null; // LUCENENET: marked readonly
private int inputStart;
private int cumulativeDiff;
private bool escapeBR = false;
private bool escapeSCRIPT = false;
private bool escapeSTYLE = false;
private readonly bool escapeBR = false; // LUCENENET: marked readonly
private readonly bool escapeSCRIPT = false; // LUCENENET: marked readonly
private readonly bool escapeSTYLE = false; // LUCENENET: marked readonly
private int restoreState;
private int previousRestoreState;
private int outputCharCount;
private int eofReturnValue;
private TextSegment inputSegment = new TextSegment(INITIAL_INPUT_SEGMENT_SIZE);
private readonly TextSegment inputSegment = new TextSegment(INITIAL_INPUT_SEGMENT_SIZE); // LUCENENET: marked readonly
private TextSegment outputSegment;
private TextSegment entitySegment = new TextSegment(2);
private readonly TextSegment entitySegment = new TextSegment(2); // LUCENENET: marked readonly

/// <summary>
/// Creates a new HTMLStripCharFilter over the provided TextReader.
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net.Analysis.Common/Analysis/Cjk/CJKWidthFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ namespace Lucene.Net.Analysis.Cjk
/// </summary>
public sealed class CJKWidthFilter : TokenFilter
{
private ICharTermAttribute termAtt;
private readonly ICharTermAttribute termAtt; // LUCENENET: marked readonly

/// <summary>
/// halfwidth kana mappings: 0xFF65-0xFF9D
/// halfwidth kana mappings: 0xFF65-0xFF9D
/// <para/>
/// note: 0xFF9C and 0xFF9D are only mapped to 0x3099 and 0x309A
/// as a fallback when they cannot properly combine with a preceding
/// as a fallback when they cannot properly combine with a preceding
/// character into a composed form.
/// </summary>
private static readonly char[] KANA_NORM = new char[] {
Expand Down Expand Up @@ -124,4 +124,4 @@ private static bool Combine(char[] text, int pos, char ch)
return false;
}
}
}
}
10 changes: 5 additions & 5 deletions src/Lucene.Net.Analysis.Common/Analysis/Cn/ChineseFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Lucene.Net.Analysis.Cn
*/

/// <summary>
/// A <see cref="TokenFilter"/> with a stop word table.
/// A <see cref="TokenFilter"/> with a stop word table.
/// <list type="bullet">
/// <item><description>Numeric tokens are removed.</description></item>
/// <item><description>English tokens must be larger than 1 character.</description></item>
Expand All @@ -39,7 +39,7 @@ namespace Lucene.Net.Analysis.Cn
/// </list>
/// </summary>
/// @deprecated (3.1) Use <see cref="Core.StopFilter"/> instead, which has the same functionality.
/// This filter will be removed in Lucene 5.0
/// This filter will be removed in Lucene 5.0
[Obsolete("(3.1) Use StopFilter instead, which has the same functionality.")]
public sealed class ChineseFilter : TokenFilter
{
Expand All @@ -52,9 +52,9 @@ public sealed class ChineseFilter : TokenFilter
"they", "this", "to", "was", "will", "with"
};

private CharArraySet stopTable;
private readonly CharArraySet stopTable; // LUCENENET: marked readonly

private ICharTermAttribute termAtt;
private readonly ICharTermAttribute termAtt; // LUCENENET: marked readonly

public ChineseFilter(TokenStream @in)
: base(@in)
Expand Down Expand Up @@ -97,4 +97,4 @@ public override bool IncrementToken()
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -24,7 +24,7 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
/// <summary>
/// This class implements a simple byte vector with access to the underlying
/// array.
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
/// </summary>
public class ByteVector
{
Expand All @@ -33,7 +33,7 @@ public class ByteVector
/// </summary>
private const int DEFAULT_BLOCK_SIZE = 2048;

private int blockSize;
private readonly int blockSize; // LUCENENET: marked readonly

/// <summary>
/// The encapsulated array
Expand All @@ -45,7 +45,7 @@ public class ByteVector
/// </summary>
private int n;

public ByteVector()
public ByteVector()
: this(DEFAULT_BLOCK_SIZE)
{
}
Expand Down Expand Up @@ -148,4 +148,4 @@ public virtual void TrimToSize()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,8 +25,8 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
/// <summary>
/// This class implements a simple char vector with access to the underlying
/// array.
///
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
///
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
/// </summary>
public class CharVector // LUCENENET specific: Not implementing ICloneable per Microsoft's recommendation
{
Expand All @@ -35,7 +35,7 @@ public class CharVector // LUCENENET specific: Not implementing ICloneable per M
/// </summary>
private const int DEFAULT_BLOCK_SIZE = 2048;

private int blockSize;
private readonly int blockSize; // LUCENENET: marked readonly

/// <summary>
/// The encapsulated array
Expand All @@ -47,7 +47,7 @@ public class CharVector // LUCENENET specific: Not implementing ICloneable per M
/// </summary>
private int n;

public CharVector()
public CharVector()
: this(DEFAULT_BLOCK_SIZE)
{
}
Expand Down Expand Up @@ -160,4 +160,4 @@ public virtual void TrimToSize()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PatternParser

internal IPatternConsumer consumer;

internal StringBuilder token;
internal readonly StringBuilder token; // LUCENENET: marked readonly

internal IList<object> exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -27,7 +27,7 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation

/// <summary>
/// <h2>Ternary Search Tree.</h2>
///
///
/// <para>
/// A ternary search tree is a hybrid between a binary tree and a digital search
/// tree (trie). Keys are limited to strings. A data value of type char is stored
Expand All @@ -42,7 +42,7 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
/// trie. Performance is comparable with a hash table, sometimes it outperforms a
/// hash function (most of the time can determine a miss faster than a hash).
/// </para>
///
///
/// <para>
/// The main purpose of this java port is to serve as a base for implementing
/// TeX's hyphenation algorithm (see The TeXBook, appendix H). Each language
Expand All @@ -56,15 +56,15 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
/// tests the english patterns took 7694 nodes and the german patterns 10055
/// nodes, so I think we are safe.
/// </para>
///
///
/// <para>
/// All said, this is a map with strings as keys and char as value. Pretty
/// limited!. It can be extended to a general map by using the string
/// representation of an object and using the char value as an index to an array
/// that contains the object values.
/// </para>
///
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
///
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
/// </summary>

public class TernaryTree // LUCENENET specific: Not implementing ICloneable per Microsoft's recommendation
Expand Down Expand Up @@ -475,7 +475,7 @@ public virtual void Balance()
/// tree is traversed to find the key substrings actually used. In addition,
/// duplicate substrings are removed using a map (implemented with a
/// TernaryTree!).
///
///
/// </summary>
public virtual void TrimToSize()
{
Expand Down Expand Up @@ -560,7 +560,7 @@ public class Enumerator : IEnumerator<string>

private class Item // LUCENENET specific: Not implementing ICloneable per Microsoft's recommendation
{
internal char parent;
internal readonly char parent; // LUCENENET: marked readonly
internal char child;

// LUCENENET: This constructor is unnecessary
Expand Down Expand Up @@ -814,4 +814,4 @@ public static void main(String[] args) {
*/

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Lucene.Net.Analysis.En
/// <para>You must specify the required <see cref="LuceneVersion"/>
/// compatibility when creating <see cref="EnglishPossessiveFilter"/>:
/// <list type="bullet">
/// <item><description> As of 3.6, U+2019 RIGHT SINGLE QUOTATION MARK and
/// <item><description> As of 3.6, U+2019 RIGHT SINGLE QUOTATION MARK and
/// U+FF07 FULLWIDTH APOSTROPHE are also treated as
/// quotation marks.</description></item>
/// </list>
Expand All @@ -36,16 +36,16 @@ namespace Lucene.Net.Analysis.En
public sealed class EnglishPossessiveFilter : TokenFilter
{
private readonly ICharTermAttribute termAtt;
private LuceneVersion matchVersion;
private readonly LuceneVersion matchVersion; // LUCENENET: marked readonly

/// @deprecated Use <see cref="EnglishPossessiveFilter(LuceneVersion, TokenStream)"/> instead.
/// @deprecated Use <see cref="EnglishPossessiveFilter(LuceneVersion, TokenStream)"/> instead.
[Obsolete(@"Use <see cref=""#EnglishPossessiveFilter(org.apache.lucene.util.Version, org.apache.lucene.analysis.TokenStream)""/> instead.")]
public EnglishPossessiveFilter(TokenStream input)
public EnglishPossessiveFilter(TokenStream input)
: this(LuceneVersion.LUCENE_35, input)
{
}

public EnglishPossessiveFilter(LuceneVersion version, TokenStream input)
public EnglishPossessiveFilter(LuceneVersion version, TokenStream input)
: base(input)
{
this.matchVersion = version;
Expand Down Expand Up @@ -73,4 +73,4 @@ public override bool IncrementToken()
return true;
}
}
}
}
18 changes: 9 additions & 9 deletions src/Lucene.Net.Analysis.Common/Analysis/En/KStemmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ public class KStemmer

internal class DictEntry
{
internal bool exception;
internal string root;
internal readonly bool exception; // LUCENENET: marked readonly
internal readonly string root; // LUCENENET: marked readonly

internal DictEntry(string root, bool isException)
{
Expand All @@ -341,8 +341,8 @@ internal DictEntry(string root, bool isException)

private static readonly CharArrayDictionary<DictEntry> dict_ht = InitializeDictHash();

// caching off
//
// caching off
//
// private int maxCacheSize; private CharArrayDictionary{String} cache =
// null; private static final String SAME = "SAME"; // use if stemmed form is
// the same
Expand Down Expand Up @@ -809,9 +809,9 @@ private void PastTense()
k = j + 1;

DictEntry entry = WordInDict();
if (entry != null)
if (entry != null)
{
if (!entry.exception)
if (!entry.exception)
{
// if it's in the dictionary and
// not an exception
Expand Down Expand Up @@ -1882,7 +1882,7 @@ internal virtual bool Stem(char[] term, int len)

//*
// caching off is normally faster if (cache is null) initializeStemHash();
//
//
// // now check the cache, before we copy chars to "word" if (cache != null)
// { String val = cache.get(term, 0, len); if (val != null) { if (val !=
// SAME) { result = val; return true; } return false; } }
Expand Down Expand Up @@ -2026,12 +2026,12 @@ internal virtual bool Stem(char[] term, int len)
// if (entry is null) { if (!word.toString().equals(new String(term,0,len), StringComparison.Ordinal))
// { System.out.println("CASE:" + word.toString() + "," + new
// String(term,0,len));
//
//
// } }
// **

// no entry matched means result is "word"
return true;
}
}
}
}
Loading

0 comments on commit ec0d6d7

Please sign in to comment.