diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData1.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData1.cs index 2c38fc2a8b..ac69ca139f 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData1.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData1.cs @@ -48,8 +48,10 @@ internal class KStemData1 private KStemData1() { } + + // LUCENENET specific - made readonly // KStemData1 ... KStemData8 are created from "head_word_list.txt" - internal static string[] data = new string[] { + internal static readonly string[] data = { "aback","abacus","abandon","abandoned","abase", "abash","abate","abattoir","abbess","abbey", "abbot","abbreviate","abbreviation","abc","abdicate", @@ -752,4 +754,4 @@ private KStemData1() "cascara","case","casebook","casein","casework", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData2.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData2.cs index 5df4284a77..a840a41eca 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData2.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData2.cs @@ -47,7 +47,9 @@ internal class KStemData2 private KStemData2() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "cash","cashew","cashier","cashmere","casing", "casino","cask","casket","casque","cassava", "casserole","cassette","cassock","cassowary","cast", @@ -750,4 +752,4 @@ private KStemData2() "distal","distance","distant","distantly","distaste", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData3.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData3.cs index 4980fcb7d6..8f1ef58a29 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData3.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData3.cs @@ -47,7 +47,9 @@ internal class KStemData3 private KStemData3() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "distasteful","distemper","distempered","distend","distension", "distil","distill","distillation","distiller","distillery", "distinct","distinction","distinctive","distinguish","distinguishable", @@ -750,4 +752,4 @@ private KStemData3() "grange","granite","grannie","granny","grant", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData4.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData4.cs index 4752a6820b..123c379ad9 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData4.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData4.cs @@ -47,7 +47,9 @@ internal class KStemData4 private KStemData4() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "granular","granulate","granule","grape","grapefruit", "grapeshot","grapevine","graph","graphic","graphical", "graphically","graphite","graphology","grapnel","grapple", @@ -750,4 +752,4 @@ private KStemData4() "locate","located","location","loch","loci", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData5.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData5.cs index 0a09e777bf..815c8f2143 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData5.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData5.cs @@ -47,7 +47,9 @@ internal class KStemData5 private KStemData5() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "lock","locker","locket","lockjaw","locknut", "lockout","locks","locksmith","lockstitch","lockup", "loco","locomotion","locomotive","locum","locus", @@ -750,4 +752,4 @@ private KStemData5() "peculiarly","pecuniary","pedagogue","pedagogy","pedal", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData6.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData6.cs index afb064aaa6..c6fb58153d 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData6.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData6.cs @@ -47,7 +47,9 @@ internal class KStemData6 private KStemData6() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "pedant","pedantic","pedantry","peddle","peddler", "pederast","pederasty","pedestal","pedestrian","pediatrician", "pediatrics","pedicab","pedicel","pedicure","pedigree", @@ -750,4 +752,4 @@ private KStemData6() "running","runny","runs","runt","runway", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData7.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData7.cs index 1c0f004a8b..02b07a1e0d 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData7.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData7.cs @@ -47,7 +47,9 @@ internal class KStemData7 private KStemData7() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "rupee","rupture","rural","ruritanian","ruse", "rush","rushes","rushlight","rusk","russet", "rust","rustic","rusticate","rustication","rustle", @@ -750,4 +752,4 @@ private KStemData7() "tenement","tenet","tenner","tennis","tenon", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData8.cs b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData8.cs index ef491903b4..78630eac5c 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData8.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/En/KStemData8.cs @@ -47,7 +47,9 @@ internal class KStemData8 private KStemData8() { } - internal static string[] data = new string[] { + + // LUCENENET specific - made readonly + internal static readonly string[] data = { "tenor","tenpin","tense","tensile","tension", "tent","tentacle","tentative","tenterhooks","tenuity", "tenuous","tenure","tepee","tepid","tequila", @@ -649,4 +651,4 @@ private KStemData8() "zoom","zoophyte","zouave","zucchini","zulu", }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizer.cs b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizer.cs index 14e6a0dfb8..bd107c862d 100644 --- a/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizer.cs +++ b/src/Lucene.Net.Analysis.OpenNLP/OpenNLPTokenizer.cs @@ -32,7 +32,8 @@ namespace Lucene.Net.Analysis.OpenNlp /// public sealed class OpenNLPTokenizer : SegmentingTokenizerBase { - public static int EOS_FLAG_BIT = 1; + // LUCENENET specific - made const, since it is never modified. Removed in Lucene 9.5.0. + public const int EOS_FLAG_BIT = 1; private readonly ICharTermAttribute termAtt; private readonly IFlagsAttribute flagsAtt; diff --git a/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs b/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs index 70c85a4400..64532ea97d 100644 --- a/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs +++ b/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs @@ -34,7 +34,7 @@ namespace Lucene.Net.Analysis.Cn.Smart /// To place the files in an alternate location, set an environment variable named "smartcn.data.dir" /// with the name of the directory the "bigramdict.dct" and "coredict.dct" files can be located within. /// - /// The default "bigramdict.dct" and "coredict.dct" files can be found at: + /// The default "bigramdict.dct" and "coredict.dct" files can be found at: /// https://issues.apache.org/jira/browse/LUCENE-1629. /// /// @lucene.experimental @@ -44,14 +44,15 @@ public static class AnalyzerProfile // LUCENENET specific: CA1052 Static holder /// /// Global indicating the configured analysis data directory /// - public static string ANALYSIS_DATA_DIR = ""; + // LUCENENET specific - changed from a mutable static field to a property. + public static string ANALYSIS_DATA_DIR { get; set; } = ""; static AnalyzerProfile() { Init(); } - // LUCENENET specific - changed the logic here to leave the + // LUCENENET specific - changed the logic here to leave the // ANALYSIS_DATA_DIR an empty string if it is not found. This // allows us to skip loading files from disk if there are no files // to load (and fixes LUCENE-1817 that prevents the on-disk files @@ -79,7 +80,6 @@ private static void Init() ANALYSIS_DATA_DIR = candidatePath; return; } - try { diff --git a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie.cs b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie.cs index 56a5bd5c0e..6814fa2def 100644 --- a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie.cs +++ b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/MultiTrie.cs @@ -68,8 +68,9 @@ namespace Egothor.Stemmer /// public class MultiTrie : Trie { - internal static char EOM = '*'; - internal static string EOM_NODE = "" + EOM; + // LUCENENET specific - made const + internal const char EOM = '*'; + internal const string EOM_NODE = "*"; // was `= "" + EOM;` but that is not a compile-time constant protected IList m_tries = new JCG.List(); diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs index 698234c658..f24f7edb4b 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs @@ -33,7 +33,11 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks /// public class TaskSequence : PerfTask { - public static int REPEAT_EXHAUST = -2; + // LUCENENET specific - changed from a mutable static field to a constant. + // While the original Java code uses a mutable static field, it is only + // intended to be used as a sentinel value, so we are changing it to a + // constant to prevent accidental modification. + public const int REPEAT_EXHAUST = -2; private IList tasks; private int repetitions = 1; private readonly bool parallel; @@ -46,7 +50,7 @@ public class TaskSequence : PerfTask private bool resetExhausted = false; private PerfTask[] tasksArray; private bool anyExhaustibleTasks; - private readonly bool collapsable = false; // to not collapse external sequence named in alg. + private readonly bool collapsable = false; // to not collapse external sequence named in alg. private bool fixedTime; // true if we run for fixed time private double runTimeSec; // how long to run for @@ -299,7 +303,7 @@ private int DoSerialTasksWithRate() { break; } - nextStartTime += delayStep; // this aims at avarage rate. + nextStartTime += delayStep; // this aims at avarage rate. try { int inc = task.RunAndMaybeStats(letChildReport); @@ -494,7 +498,7 @@ private void StartlThreadsWithRate(ParallelTask[] t) { Thread.Sleep((int)waitMore); } - nextStartTime += delayStep; // this aims at average rate of starting threads. + nextStartTime += delayStep; // this aims at average rate of starting threads. t[i].Start(); } } @@ -573,7 +577,7 @@ public virtual int GetRate() } /// - /// + /// /// /// The rate to set. /// @@ -607,7 +611,7 @@ private void SetSequenceName() public override string GetName() { - return seqName; // override to include more info + return seqName; // override to include more info } /// diff --git a/src/Lucene.Net.Benchmark/Constants.cs b/src/Lucene.Net.Benchmark/Constants.cs index 0c3e860aad..984c516f29 100644 --- a/src/Lucene.Net.Benchmark/Constants.cs +++ b/src/Lucene.Net.Benchmark/Constants.cs @@ -26,7 +26,8 @@ public static class Constants // LUCENENET specific: CA1052 Static holder types public const int DEFAULT_SCALE_UP = 5; public const int DEFAULT_LOG_STEP = 1000; - public static bool[] BOOLEANS = new bool[] { false, true }; + // LUCENENET specific - made readonly + public static readonly bool[] BOOLEANS = new bool[] { false, true }; public const int DEFAULT_MAXIMUM_DOCUMENTS = int.MaxValue; } diff --git a/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs b/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs index 5504248a3d..0638df6524 100644 --- a/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs +++ b/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs @@ -34,7 +34,7 @@ public class ExtractWikipedia { private readonly DirectoryInfo outputDir; // LUCENENET: marked readonly - public static int count = 0; + public static int Count { get; set; } // LUCENENET: changed mutable static field into a property internal const int BASE = 10; protected DocMaker m_docMaker; @@ -73,7 +73,7 @@ public virtual DirectoryInfo Directory(int count, DirectoryInfo directory) public virtual void Create(string id, string title, string time, string body) { - DirectoryInfo d = Directory(count++, null); + DirectoryInfo d = Directory(Count++, null); d.Create(); FileInfo f = new FileInfo(System.IO.Path.Combine(d.FullName, id + ".txt")); diff --git a/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs b/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs index 51f3fc083b..f6794ff575 100644 --- a/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs +++ b/src/Lucene.Net.Highlighter/Highlight/WeightedSpanTermExtractor.cs @@ -31,7 +31,7 @@ namespace Lucene.Net.Search.Highlight */ /// - /// Class used to extract s from a based on whether + /// Class used to extract s from a based on whether /// s from the are contained in a supplied . /// public class WeightedSpanTermExtractor @@ -137,10 +137,10 @@ protected virtual void Extract(Query query, IDictionary - /// Fills a with s using the terms from + /// Fills a with s using the terms from /// the supplied . /// /// to place created s in @@ -395,7 +395,7 @@ protected virtual AtomicReaderContext GetLeafContext() /// internal sealed class DelegatingAtomicReader : FilterAtomicReader { - public static string FIELD_NAME = "shadowed_field"; + public const string FIELD_NAME = "shadowed_field"; internal DelegatingAtomicReader(AtomicReader reader) : base(reader) { } @@ -430,7 +430,7 @@ public override BinaryDocValues GetBinaryDocValues(string field) { return base.GetBinaryDocValues(FIELD_NAME); } - + public override SortedDocValues GetSortedDocValues(string field) { return base.GetSortedDocValues(FIELD_NAME); @@ -742,4 +742,4 @@ protected internal void SetMaxDocCharsToAnalyze(int maxDocCharsToAnalyze) this.maxDocCharsToAnalyze = maxDocCharsToAnalyze; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.QueryParser/Classic/ParseException.cs b/src/Lucene.Net.QueryParser/Classic/ParseException.cs index f637bbe68f..186eeab9fe 100644 --- a/src/Lucene.Net.QueryParser/Classic/ParseException.cs +++ b/src/Lucene.Net.QueryParser/Classic/ParseException.cs @@ -29,16 +29,16 @@ namespace Lucene.Net.QueryParsers.Classic * limitations under the License. */ - /// + /// /// This exception is thrown when parse errors are encountered. /// You can explicitly create objects of this exception type by /// calling the method GenerateParseException in the generated /// parser. - /// + /// /// You can modify this class to customize your error reporting /// mechanisms so long as you retain the public fields. /// - // LUCENENET: It is no longer good practice to use binary serialization. + // LUCENENET: It is no longer good practice to use binary serialization. // See: https://github.com/dotnet/corefx/issues/23584#issuecomment-325724568 #if FEATURE_SERIALIZABLE_EXCEPTIONS [Serializable] @@ -114,14 +114,14 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont } #endif - /// + /// /// This is the last token that has been consumed successfully. If /// this object has been created due to a parse error, the token /// following this token will (therefore) be the first error token. /// public Token CurrentToken { get; set; } - /// + /// /// Each entry in this array is an array of integers. Each array /// of integers represents a sequence of tokens (by their ordinal /// values) that is expected at this point of the parse. @@ -130,7 +130,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")] public int[][] ExpectedTokenSequences { get; set; } - /// + /// /// This is a reference to the "tokenImage" array of the generated /// parser within which the parse error occurred. This array is /// defined in the generated ...Constants interface. @@ -200,13 +200,15 @@ private static string Initialize(Token currentToken, retval += expected.ToString(); return retval; } - - /// + + /// /// The end of line string for this machine. /// - protected static string eol = Environment.NewLine; - - /// + // LUCENENET specific - changed from a mutable protected static field into a property. + // While it's not likely that someone will change the end of line string, it is possible. + protected static string eol { get; set; } = Environment.NewLine; + + /// /// Used to convert raw characters to their escaped version /// when these raw version cannot be used as part of an ASCII /// string literal. @@ -219,43 +221,43 @@ internal static string AddEscapes(string str) { switch (str[i]) { - - case (char) (0): + + case (char) (0): continue; - - case '\b': + + case '\b': retval.Append("\\b"); continue; - - case '\t': + + case '\t': retval.Append("\\t"); continue; - - case '\n': + + case '\n': retval.Append("\\n"); continue; - - case '\f': + + case '\f': retval.Append("\\f"); continue; - - case '\r': + + case '\r': retval.Append("\\r"); continue; - - case '\"': + + case '\"': retval.Append("\\\""); continue; - - case '\'': + + case '\'': retval.Append("\\\'"); continue; - - case '\\': + + case '\\': retval.Append("\\\\"); continue; - - default: + + default: if ((ch = str[i]) < 0x20 || ch > 0x7e) { string s = "0000" + Convert.ToString(ch, 16); @@ -266,7 +268,7 @@ internal static string AddEscapes(string str) retval.Append(ch); } continue; - + } } return retval.ToString(); diff --git a/src/Lucene.Net.QueryParser/Classic/QueryParserConstants.cs b/src/Lucene.Net.QueryParser/Classic/QueryParserConstants.cs index 9bcdcc36c2..21d75e0128 100644 --- a/src/Lucene.Net.QueryParser/Classic/QueryParserConstants.cs +++ b/src/Lucene.Net.QueryParser/Classic/QueryParserConstants.cs @@ -95,9 +95,9 @@ public static class LexicalToken public const int DEFAULT = 2; } - // LUCENENET NOTE: In Java, this was an interface. However, in + // LUCENENET NOTE: In Java, this was an interface. However, in // .NET we cannot define constants in an interface. - // So, instead we are making it a static class so it + // So, instead we are making it a static class so it // can be shared between classes with different base classes. // public interface QueryParserConstants @@ -108,43 +108,44 @@ public static class LexicalToken public static class QueryParserConstants { /// Literal token values. - public static string[] TokenImage = new string[] { - "", - "<_NUM_CHAR>", - "<_ESCAPED_CHAR>", - "<_TERM_START_CHAR>", - "<_TERM_CHAR>", - "<_WHITESPACE>", - "<_QUOTED_CHAR>", - "", - "", - "", - "", - "\"+\"", - "\"-\"", + // LUCENENET specific - made readonly + public readonly static string[] TokenImage = { + "", + "<_NUM_CHAR>", + "<_ESCAPED_CHAR>", + "<_TERM_START_CHAR>", + "<_TERM_CHAR>", + "<_WHITESPACE>", + "<_QUOTED_CHAR>", + "", + "", + "", + "", + "\"+\"", + "\"-\"", "", - "\"(\"", - "\")\"", - "\":\"", - "\"*\"", - "\"^\"", - "", - "", - "", - "", - "", + "\"(\"", + "\")\"", + "\":\"", + "\"*\"", + "\"^\"", + "", + "", + "", + "", + "", "", - "\"[\"", - "\"{\"", - "", - "\"TO\"", - "\"]\"", - "", - "", - "\"TO\"", - "\"}\"", + "\"[\"", + "\"{\"", + "", + "\"TO\"", + "\"]\"", + "", + "", + "\"TO\"", + "\"}\"", "", "" }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserConstants.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserConstants.cs index 7558aff934..6ddff733be 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserConstants.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParserConstants.cs @@ -103,7 +103,8 @@ public static class LexicalToken public static class StandardSyntaxParserConstants { /// Literal token values. - public static string[] TokenImage = new string[] { + // LUCENENET specific - made readonly + public readonly static string[] TokenImage = { "", "<_NUM_CHAR>", "<_ESCAPED_CHAR>", diff --git a/src/Lucene.Net.QueryParser/Surround/Parser/ParseException.cs b/src/Lucene.Net.QueryParser/Surround/Parser/ParseException.cs index cf09eb095e..c9e065972a 100644 --- a/src/Lucene.Net.QueryParser/Surround/Parser/ParseException.cs +++ b/src/Lucene.Net.QueryParser/Surround/Parser/ParseException.cs @@ -29,16 +29,16 @@ namespace Lucene.Net.QueryParsers.Surround.Parser * limitations under the License. */ - /// + /// /// This exception is thrown when parse errors are encountered. /// You can explicitly create objects of this exception type by /// calling the method GenerateParseException in the generated /// parser. - /// + /// /// You can modify this class to customize your error reporting /// mechanisms so long as you retain the public fields. /// - // LUCENENET: It is no longer good practice to use binary serialization. + // LUCENENET: It is no longer good practice to use binary serialization. // See: https://github.com/dotnet/corefx/issues/23584#issuecomment-325724568 #if FEATURE_SERIALIZABLE_EXCEPTIONS [Serializable] @@ -114,14 +114,14 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont } #endif - /// + /// /// This is the last token that has been consumed successfully. If /// this object has been created due to a parse error, the token /// following this token will (therefore) be the first error token. /// public Token CurrentToken { get; set; } - /// + /// /// Each entry in this array is an array of integers. Each array /// of integers represents a sequence of tokens (by their ordinal /// values) that is expected at this point of the parse. @@ -130,7 +130,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")] public int[][] ExpectedTokenSequences { get; set; } - /// + /// /// This is a reference to the "tokenImage" array of the generated /// parser within which the parse error occurred. This array is /// defined in the generated ...Constants interface. @@ -201,12 +201,14 @@ private static string Initialize(Token currentToken, return retval; } - /// + /// /// The end of line string for this machine. /// - protected static string eol = Environment.NewLine; + // LUCENENET specific - changed from a mutable protected static field into a property. + // While it's not likely that someone will change the end of line string, it is possible. + protected static string eol { get; set; } = Environment.NewLine; - /// + /// /// Used to convert raw characters to their escaped version /// when these raw version cannot be used as part of an ASCII /// string literal. diff --git a/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserConstants.cs b/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserConstants.cs index 3045974a9c..729f31b07f 100644 --- a/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserConstants.cs +++ b/src/Lucene.Net.QueryParser/Surround/Parser/QueryParserConstants.cs @@ -75,9 +75,9 @@ public static class LexicalToken public const int DEFAULT = 2; } - // NOTE: In Java, this was an interface. However, in + // NOTE: In Java, this was an interface. However, in // .NET we cannot define constants in an interface. - // So, instead we are making it a static class so it + // So, instead we are making it a static class so it // can be shared between classes with different base classes. // public interface QueryParserConstants @@ -88,7 +88,8 @@ public static class LexicalToken public static class QueryParserConstants { /// Literal token values. - public static string[] TokenImage = new string[] { + // LUCENENET specific - made readonly + public static readonly string[] TokenImage = { "", "<_NUM_CHAR>", "<_TERM_CHAR>", @@ -115,4 +116,4 @@ public static class QueryParserConstants "" }; } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.QueryParser/Xml/CoreParser.cs b/src/Lucene.Net.QueryParser/Xml/CoreParser.cs index c6fbb8523d..8901934994 100644 --- a/src/Lucene.Net.QueryParser/Xml/CoreParser.cs +++ b/src/Lucene.Net.QueryParser/Xml/CoreParser.cs @@ -34,8 +34,11 @@ public class CoreParser : IQueryBuilder protected QueryParser m_parser; protected QueryBuilderFactory m_queryFactory; protected FilterBuilderFactory m_filterFactory; - //Controls the max size of the LRU cache used for QueryFilter objects parsed. - public static int maxNumCachedFilters = 20; + + /// Controls the max size of the LRU cache used for QueryFilter objects parsed. + // LUCENENET specific - changed from a mutable static field into a property. + // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global + public static int MaxNumCachedFilters { get; set; } = 20; /// /// Construct an XML parser that uses a single instance for handling @@ -85,7 +88,7 @@ protected CoreParser(string defaultField, Analyzer analyzer, QueryParser parser) m_queryFactory.AddBuilder("ConstantScoreQuery", new ConstantScoreQueryBuilder(m_filterFactory)); m_filterFactory.AddBuilder("CachedFilter", new CachedFilterBuilder(m_queryFactory, - m_filterFactory, maxNumCachedFilters)); + m_filterFactory, MaxNumCachedFilters)); SpanQueryBuilderFactory sqof = new SpanQueryBuilderFactory(); diff --git a/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs b/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs index 9fd5d3ceac..91ba0022cc 100644 --- a/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs +++ b/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs @@ -49,7 +49,7 @@ public class FuzzyLikeThisQuery : Query // a better way might be to convert this into multitermquery rewrite methods. // the rewrite method can 'average' the TermContext's term statistics (docfreq,totalTermFreq) // provided to TermQuery, so that the general idea is agnostic to any scoring system... - internal static TFIDFSimilarity sim = new DefaultSimilarity(); + internal readonly static TFIDFSimilarity sim = new DefaultSimilarity(); // LUCENENET specific - made readonly private Query rewrittenQuery = null; private readonly IList fieldVals = new JCG.List(); private readonly Analyzer analyzer; diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/BlendedInfixSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/BlendedInfixSuggester.cs index ffc6d4a245..42ef733cb6 100644 --- a/src/Lucene.Net.Suggest/Suggest/Analyzing/BlendedInfixSuggester.cs +++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/BlendedInfixSuggester.cs @@ -43,16 +43,17 @@ namespace Lucene.Net.Search.Suggest.Analyzing /// public class BlendedInfixSuggester : AnalyzingInfixSuggester { - /// /// Coefficient used for linear blending /// - protected internal static double LINEAR_COEF = 0.10; + // LUCENENET specific - changed from a mutable static field into a property. + protected internal static double LINEAR_COEF { get; set; } = 0.10; /// /// Default factor /// - public static int DEFAULT_NUM_FACTOR = 10; + // LUCENENET specific - changed from a mutable static field into a property. + public static int DEFAULT_NUM_FACTOR { get; set; } = 10; /// /// Factor to multiply the number of searched elements diff --git a/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs b/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs index 32bcc29e53..67d4dfa90b 100644 --- a/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs +++ b/src/Lucene.Net/Codecs/Lucene40/Lucene40FieldInfosReader.cs @@ -200,7 +200,7 @@ public static LegacyDocValuesType ToLegacyDocValuesType(this string name) // Was } // mapping of 4.0 types -> 4.2 types - internal static IDictionary mapping = new Dictionary + internal static readonly IDictionary mapping = new Dictionary { { LegacyDocValuesType.NONE, DocValuesType.NONE }, { LegacyDocValuesType.VAR_INTS, DocValuesType.NUMERIC }, diff --git a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsFormat.cs b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsFormat.cs index e3e8f782f9..eb6fb80883 100644 --- a/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsFormat.cs +++ b/src/Lucene.Net/Codecs/Lucene41/Lucene41PostingsFormat.cs @@ -372,7 +372,7 @@ public sealed class Lucene41PostingsFormat : PostingsFormat /// a single packed block. /// // NOTE: must be multiple of 64 because of PackedInts long-aligned encoding/decoding - public static int BLOCK_SIZE = 128; + public const int BLOCK_SIZE = 128; /// /// Creates with default @@ -385,7 +385,7 @@ public Lucene41PostingsFormat() /// /// Creates with custom - /// values for and + /// values for and /// passed to block terms dictionary. /// public Lucene41PostingsFormat(int minTermBlockSize, int maxTermBlockSize) @@ -441,4 +441,4 @@ public override FieldsProducer FieldsProducer(SegmentReadState state) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/CheckIndex.cs b/src/Lucene.Net/Index/CheckIndex.cs index 38d93d423c..348b344fa6 100644 --- a/src/Lucene.Net/Index/CheckIndex.cs +++ b/src/Lucene.Net/Index/CheckIndex.cs @@ -663,7 +663,7 @@ public virtual Status DoCheckIndex(IList onlySegments) // LUCENENET: We created the segments names wrong in 4.8.0-beta00001 - 4.8.0-beta00015, // so we added a switch to be able to read these indexes in later versions. - int segmentRadix = SegmentInfos.useLegacySegmentNames ? 10 : J2N.Character.MaxRadix; + int segmentRadix = SegmentInfos.UseLegacySegmentNames ? 10 : J2N.Character.MaxRadix; for (int i = 0; i < numSegments; i++) { diff --git a/src/Lucene.Net/Index/IndexFileDeleter.cs b/src/Lucene.Net/Index/IndexFileDeleter.cs index 85b7a8eeea..37b4ea46d9 100644 --- a/src/Lucene.Net/Index/IndexFileDeleter.cs +++ b/src/Lucene.Net/Index/IndexFileDeleter.cs @@ -113,7 +113,8 @@ internal sealed class IndexFileDeleter : IDisposable /// Change to true to see details of reference counts when /// infoStream is enabled /// - public static bool VERBOSE_REF_COUNTS = false; + // LUCENENET specific - changed from a mutable static field to a property + public static bool VERBOSE_REF_COUNTS { get; set; } = false; // Used only for assert private readonly IndexWriter writer; diff --git a/src/Lucene.Net/Index/IndexWriterConfig.cs b/src/Lucene.Net/Index/IndexWriterConfig.cs index fd1fcc0adf..e7cf635610 100644 --- a/src/Lucene.Net/Index/IndexWriterConfig.cs +++ b/src/Lucene.Net/Index/IndexWriterConfig.cs @@ -93,7 +93,13 @@ public sealed class IndexWriterConfig : LiveIndexWriterConfig // LUCENENET speci /// Default value for the write lock timeout (1,000 ms). /// /// - public static long WRITE_LOCK_TIMEOUT = 1000; + /// + /// WARNING: Per Lucene 4.8 behavior, modifying this also changes the static value. + /// + // LUCENENET specific - changed from a mutable static field to a property. + // NOTE: this is also accessed and set by DefaultWriteLockTimeout. + // This field is removed in later versions of Lucene. + public static long WRITE_LOCK_TIMEOUT { get; set; } = 1000; /// /// Default setting for . @@ -133,6 +139,9 @@ public sealed class IndexWriterConfig : LiveIndexWriterConfig // LUCENENET speci /// Gets or sets the default (for any instance) maximum time to wait for a write lock /// (in milliseconds). /// + /// + /// WARNING: Per Lucene 4.8 behavior, modifying this also changes the static value. + /// public static long DefaultWriteLockTimeout { get => WRITE_LOCK_TIMEOUT; diff --git a/src/Lucene.Net/Index/SegmentInfos.cs b/src/Lucene.Net/Index/SegmentInfos.cs index 346ce6f5c3..71140af1f0 100644 --- a/src/Lucene.Net/Index/SegmentInfos.cs +++ b/src/Lucene.Net/Index/SegmentInfos.cs @@ -154,12 +154,7 @@ public sealed class SegmentInfos : IEnumerable // LUCENENET s /// System properties can also be injected by supplying a at application startup /// through . /// - public static bool UseLegacySegmentNames - { - get => useLegacySegmentNames; - set => useLegacySegmentNames = value; - } - internal static bool useLegacySegmentNames = Util.SystemProperties.GetPropertyAsBoolean("useLegacySegmentNames", defaultValue: false); + public static bool UseLegacySegmentNames { get; set; } = Util.SystemProperties.GetPropertyAsBoolean("useLegacySegmentNames", defaultValue: false); /// /// Optimized version of with a radix of 36, that @@ -184,7 +179,7 @@ internal static string SegmentNumberToString(long segment, bool allowLegacyNames case 9: return "9"; } - if (!allowLegacyNames || !useLegacySegmentNames) + if (!allowLegacyNames || !UseLegacySegmentNames) { return segment switch { diff --git a/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs b/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs index 083c9d3b60..f38e1cf0f8 100644 --- a/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs +++ b/src/Lucene.Net/Search/ConstantScoreAutoRewrite.cs @@ -51,13 +51,15 @@ public class ConstantScoreAutoRewrite : TermCollectingRewrite /// doc Wikipedia index. With more than 350 terms in the /// query, the filter method is fastest: /// - public static int DEFAULT_TERM_COUNT_CUTOFF = 350; + // LUCENENET specific - changed mutable static field into a property. + public static int DEFAULT_TERM_COUNT_CUTOFF { get; set; } = 350; /// /// If the query will hit more than 1 in 1000 of the docs /// in the index (0.1%), the filter method is fastest: /// - public static double DEFAULT_DOC_COUNT_PERCENT = 0.1; + // LUCENENET specific - changed mutable static field into a property. + public static double DEFAULT_DOC_COUNT_PERCENT { get; set; } = 0.1; private int termCountCutoff = DEFAULT_TERM_COUNT_CUTOFF; private double docCountPercent = DEFAULT_DOC_COUNT_PERCENT; diff --git a/src/Lucene.Net/Search/FieldCache.cs b/src/Lucene.Net/Search/FieldCache.cs index d93799a88f..f377fb7d1f 100644 --- a/src/Lucene.Net/Search/FieldCache.cs +++ b/src/Lucene.Net/Search/FieldCache.cs @@ -87,7 +87,7 @@ public interface IFieldCache /// Checks the internal cache for an appropriate entry, and if none is /// found, reads the terms in as s and returns an array /// of size reader.MaxDoc of the value each document - /// has in the given field. + /// has in the given field. /// /// NOTE: this was getShorts() in Lucene /// @@ -104,7 +104,7 @@ public interface IFieldCache /// Checks the internal cache for an appropriate entry, and if none is found, /// reads the terms in as shorts and returns an array of /// size reader.MaxDoc of the value each document has in the - /// given field. + /// given field. /// /// NOTE: this was getShorts() in Lucene /// @@ -293,7 +293,7 @@ public interface IFieldCache SortedDocValues GetTermsIndex(AtomicReader reader, string field); /// - /// Expert: just like + /// Expert: just like /// , but you can specify /// whether more RAM should be consumed in exchange for /// faster lookups (default is "true"). Note that the @@ -359,7 +359,7 @@ public interface IFieldCache TextWriter InfoStream { set; get; } } - public static class FieldCache + public static class FieldCache { /// /// Field values as 8-bit signed bytes @@ -702,7 +702,8 @@ public interface IDoubleParser : IParser /// /// Expert: The cache used internally by sorting and range query classes. /// - public static IFieldCache DEFAULT = new FieldCacheImpl(); + // LUCENENET specific - changed mutable static field into a property + public static IFieldCache DEFAULT { get; set; } = new FieldCacheImpl(); /// /// The default parser for byte values, which are encoded by @@ -1020,7 +1021,7 @@ public TermsEnum GetTermsEnum(Terms terms) // .NET Port: skipping down to about line 681 of java version. The actual interface methods of FieldCache are in IFieldCache below. /// - /// EXPERT: A unique Identifier/Description for each item in the . + /// EXPERT: A unique Identifier/Description for each item in the . /// Can be useful for logging/debugging. /// /// @lucene.experimental @@ -1074,7 +1075,7 @@ public void EstimateSize() } /// - /// The most recently estimated size of the value, null unless + /// The most recently estimated size of the value, null unless /// has been called. /// public string EstimatedSize => size; @@ -1130,4 +1131,4 @@ public override string ToString() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Search/Similarities/BasicModelP.cs b/src/Lucene.Net/Search/Similarities/BasicModelP.cs index 7bdb5ae8e7..00096a71d3 100644 --- a/src/Lucene.Net/Search/Similarities/BasicModelP.cs +++ b/src/Lucene.Net/Search/Similarities/BasicModelP.cs @@ -33,7 +33,8 @@ public class BasicModelP : BasicModel { /// /// log2(Math.E), precomputed. - protected internal static double LOG2_E = Log2(Math.E); + // LUCENENET specific - made readonly, not expected to change + protected internal static readonly double LOG2_E = Log2(Math.E); /// /// Sole constructor: parameter-free @@ -52,4 +53,4 @@ public override string ToString() return "P"; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Store/Lock.cs b/src/Lucene.Net/Store/Lock.cs index a994a07e83..c82e0d1eaa 100644 --- a/src/Lucene.Net/Store/Lock.cs +++ b/src/Lucene.Net/Store/Lock.cs @@ -25,11 +25,11 @@ namespace Lucene.Net.Store /// /// An interprocess mutex lock. /// Typical use might look like: - /// + /// /// /// var result = Lock.With.NewAnonymous<string>( - /// @lock: directory.MakeLock("my.lock"), - /// lockWaitTimeout: Lock.LOCK_OBTAIN_WAIT_FOREVER, + /// @lock: directory.MakeLock("my.lock"), + /// lockWaitTimeout: Lock.LOCK_OBTAIN_WAIT_FOREVER, /// doBody: () => /// { /// //... code to execute while locked ... @@ -44,7 +44,8 @@ public abstract class Lock : IDisposable /// How long waits, in milliseconds, /// in between attempts to acquire the lock. /// - public static long LOCK_POLL_INTERVAL = 1000; + // LUCENENET specific - changed mutable static field into a property + public static long LOCK_POLL_INTERVAL { get; set; } = 1000; /// /// Pass this value to to try @@ -59,8 +60,8 @@ public abstract class Lock : IDisposable /// Simple example: /// /// var result = Lock.With.NewAnonymous<string>( - /// @lock: directory.MakeLock("my.lock"), - /// lockWaitTimeout: Lock.LOCK_OBTAIN_WAIT_FOREVER, + /// @lock: directory.MakeLock("my.lock"), + /// lockWaitTimeout: Lock.LOCK_OBTAIN_WAIT_FOREVER, /// doBody: () => /// { /// //... code to execute while locked ... @@ -74,7 +75,7 @@ public abstract class Lock : IDisposable /// /// the instance to use /// length of time to wait in - /// milliseconds or + /// milliseconds or /// to retry forever /// a delegate method that /// The value that is returned from the delegate method (i.e. () => { return theObject; }) @@ -104,7 +105,7 @@ public static With NewAnonymous(Lock @lock, int lockWaitTimeout, Func d /// passed. /// /// length of time to wait in - /// milliseconds or + /// milliseconds or /// to retry forever /// true if lock was obtained /// if lock wait times out @@ -150,7 +151,7 @@ public bool Obtain(long lockWaitTimeout) } return locked; } - + /// /// Releases exclusive access. public void Dispose() @@ -182,7 +183,7 @@ public abstract class With // LUCENENET specific - made generic so we don't n /// Constructs an executor that will grab the named . /// the instance to use /// length of time to wait in - /// milliseconds or + /// milliseconds or /// to retry forever protected With(Lock @lock, long lockWaitTimeout) // LUCENENET: CA1012: Abstract types should not have constructors (marked protected) { @@ -239,4 +240,4 @@ protected override T DoBody() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Support/Util/Events/Resources.cs b/src/Lucene.Net/Support/Util/Events/Resources.cs index 04e9d28ec9..1b3594b45a 100644 --- a/src/Lucene.Net/Support/Util/Events/Resources.cs +++ b/src/Lucene.Net/Support/Util/Events/Resources.cs @@ -8,7 +8,7 @@ // All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software -// is furnished to do so, subject to the following conditions: +// is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. // @@ -24,9 +24,9 @@ namespace Lucene.Net.Util.Events { internal static class Resources { - public static string EventAggregatorNotConstructedOnUIThread = "To use the UIThread option for subscribing, the EventAggregator must be constructed on the UI thread."; - public static string InvalidDelegateRerefenceTypeException = "Invalid Delegate Reference Type Exception"; + public const string EventAggregatorNotConstructedOnUIThread = "To use the UIThread option for subscribing, the EventAggregator must be constructed on the UI thread."; + public const string InvalidDelegateRerefenceTypeException = "Invalid Delegate Reference Type Exception"; } } -#endif \ No newline at end of file +#endif diff --git a/src/Lucene.Net/Util/Automaton/Automaton.cs b/src/Lucene.Net/Util/Automaton/Automaton.cs index 2261ae996e..a2ef5774d5 100644 --- a/src/Lucene.Net/Util/Automaton/Automaton.cs +++ b/src/Lucene.Net/Util/Automaton/Automaton.cs @@ -74,16 +74,18 @@ namespace Lucene.Net.Util.Automaton /// public class Automaton // LUCENENET specific: Not implementing ICloneable per Microsoft's recommendation { - /// - /// Minimize using Hopcroft's O(n log n) algorithm. this is regarded as one of - /// the most generally efficient algorithms that exist. - /// - /// - public const int MINIMIZE_HOPCROFT = 2; + // LUCENENET specific - commented out; unused and removed in later Lucene versions + // /// + // /// Minimize using Hopcroft's O(n log n) algorithm. this is regarded as one of + // /// the most generally efficient algorithms that exist. + // /// + // /// + // public const int MINIMIZE_HOPCROFT = 2; - /// - /// Selects minimization algorithm (default: MINIMIZE_HOPCROFT). - internal static int minimization = MINIMIZE_HOPCROFT; + // LUCENENET specific - commented out; unused and removed in later Lucene versions + // /// + // /// Selects minimization algorithm (default: MINIMIZE_HOPCROFT). + // internal static int minimization = MINIMIZE_HOPCROFT; /// /// Initial state of this automaton. @@ -110,13 +112,15 @@ public class Automaton // LUCENENET specific: Not implementing ICloneable per Mi /// /// Minimize always flag. - internal static bool minimize_always = false; + // LUCENENET specific - made private + private static bool minimize_always = false; /// /// Selects whether operations may modify the input automata (default: /// false). /// - internal static bool allow_mutation = false; + // LUCENENET specific - made private + private static bool allow_mutation = false; /// /// Constructs a new automaton that accepts the empty language. Using this @@ -137,15 +141,16 @@ public Automaton() { } - /// - /// Selects minimization algorithm (default: MINIMIZE_HOPCROFT). - /// - /// minimization algorithm - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SetMinimization(int algorithm) - { - minimization = algorithm; - } + // LUCENENET specific - commented out; unused and removed in later Lucene versions + // /// + // /// Selects minimization algorithm (default: MINIMIZE_HOPCROFT). + // /// + // /// minimization algorithm + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static void SetMinimization(int algorithm) + // { + // minimization = algorithm; + // } /// /// Sets or resets minimize always flag. If this flag is set, then diff --git a/src/Lucene.Net/Util/Automaton/MinimizationOperations.cs b/src/Lucene.Net/Util/Automaton/MinimizationOperations.cs index 6cb382c3fe..69a26c2809 100644 --- a/src/Lucene.Net/Util/Automaton/MinimizationOperations.cs +++ b/src/Lucene.Net/Util/Automaton/MinimizationOperations.cs @@ -46,7 +46,7 @@ public static class MinimizationOperations // LUCENENET specific - made static s /// Minimizes (and determinizes if not already deterministic) the given /// automaton. /// - /// + // LUCENENET: unused reference; it always uses Hopcroft /// public static void Minimize(Automaton a) { if (!a.IsSingleton) diff --git a/src/Lucene.Net/Util/Automaton/State.cs b/src/Lucene.Net/Util/Automaton/State.cs index ccc5ca5aff..6ba20278f3 100644 --- a/src/Lucene.Net/Util/Automaton/State.cs +++ b/src/Lucene.Net/Util/Automaton/State.cs @@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; +using System.Threading; /* * dk.brics.automaton @@ -58,7 +59,7 @@ public class State : IComparable internal int number; internal int id; - internal static int next_id; + private static int next_id; // LUCENENET specific - made private /// /// Constructs a new state. Initially, the new state is a reject state. @@ -66,7 +67,7 @@ public class State : IComparable public State() { //ResetTransitions(); // LUCENENET: Let class initializer set these - id = next_id++; + id = Interlocked.Increment(ref next_id); // LUCENENET specific - made atomic } /// diff --git a/src/Lucene.Net/Util/Automaton/UTF32ToUTF8.cs b/src/Lucene.Net/Util/Automaton/UTF32ToUTF8.cs index c5c8c84bf1..5057227c48 100644 --- a/src/Lucene.Net/Util/Automaton/UTF32ToUTF8.cs +++ b/src/Lucene.Net/Util/Automaton/UTF32ToUTF8.cs @@ -41,7 +41,7 @@ public sealed class UTF32ToUTF8 private static readonly int[] endCodes = new int[] { 127, 2047, 65535, 1114111 }; - internal static int[] MASKS = LoadMasks(); + internal readonly static int[] MASKS = LoadMasks(); // LUCENENET specific - made readonly private static int[] LoadMasks() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { @@ -392,4 +392,4 @@ private State NewUTF8State() return s; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Util/BytesRef.cs b/src/Lucene.Net/Util/BytesRef.cs index 8012c77282..63cb8eb0b9 100644 --- a/src/Lucene.Net/Util/BytesRef.cs +++ b/src/Lucene.Net/Util/BytesRef.cs @@ -434,7 +434,7 @@ public bool IsValid() #endif internal class Utf8SortedAsUnicodeComparer : IComparer { - public static Utf8SortedAsUnicodeComparer Instance = new Utf8SortedAsUnicodeComparer(); + public static readonly Utf8SortedAsUnicodeComparer Instance = new Utf8SortedAsUnicodeComparer(); // Only singleton private Utf8SortedAsUnicodeComparer() diff --git a/src/Lucene.Net/Util/Constants.cs b/src/Lucene.Net/Util/Constants.cs index e236b47d84..72d1107e53 100644 --- a/src/Lucene.Net/Util/Constants.cs +++ b/src/Lucene.Net/Util/Constants.cs @@ -33,7 +33,7 @@ public static class Constants // LUCENENET specific - made static because all me /// /// The maximum stack allocation size before switching to making allocations on the heap. /// - internal static int MaxStackByteLimit = SystemProperties.GetPropertyAsInt32("maxStackByteLimit", defaultValue: 2048); // LUCENENET specific + internal static readonly int MaxStackByteLimit = SystemProperties.GetPropertyAsInt32("maxStackByteLimit", defaultValue: 2048); // LUCENENET specific // LUCENENET NOTE: IMPORTANT - this line must be placed before RUNTIME_VERSION so it can be parsed. private static readonly Regex VERSION = new Regex(@"(\d+\.\d+(?:\.\d+)?(?:\.\d+)?)", RegexOptions.Compiled); diff --git a/src/Lucene.Net/Util/Packed/PackedInts.cs b/src/Lucene.Net/Util/Packed/PackedInts.cs index cccc671b56..3aea2be02b 100644 --- a/src/Lucene.Net/Util/Packed/PackedInts.cs +++ b/src/Lucene.Net/Util/Packed/PackedInts.cs @@ -46,32 +46,32 @@ public static class PackedInt32s // LUCENENET specific: CA1052 Static holder typ /// /// At most 700% memory overhead, always select a direct implementation. /// - public static float FASTEST = 7f; + public const float FASTEST = 7f; /// /// At most 50% memory overhead, always select a reasonably fast implementation. /// - public static float FAST = 0.5f; + public const float FAST = 0.5f; /// /// At most 20% memory overhead. /// - public static float DEFAULT = 0.2f; + public const float DEFAULT = 0.2f; /// /// No memory overhead at all, but the returned implementation may be slow. /// - public static float COMPACT = 0f; + public const float COMPACT = 0f; /// /// Default amount of memory to use for bulk operations. /// - public static int DEFAULT_BUFFER_SIZE = 1024; // 1K + public const int DEFAULT_BUFFER_SIZE = 1024; // 1K - public static string CODEC_NAME = "PackedInts"; - public static int VERSION_START = 0; // PackedInts were long-aligned - public static int VERSION_BYTE_ALIGNED = 1; - public static int VERSION_CURRENT = VERSION_BYTE_ALIGNED; + public const string CODEC_NAME = "PackedInts"; + public static readonly int VERSION_START = 0; // PackedInts were long-aligned + public static readonly int VERSION_BYTE_ALIGNED = 1; + public static readonly int VERSION_CURRENT = VERSION_BYTE_ALIGNED; /// /// Check the validity of a version number.