From cd8e057e08b8eca454711687b4cf96a8c7476910 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Sun, 10 Mar 2024 10:49:39 -0600 Subject: [PATCH] Replace int.MinValue with MergeTrigger.NONE The original Java code uses null, but that causes problems if you make the enum nullable. This is a cleaner solution although it is an API mismatch from the Java semantics. --- .../Index/MockRandomMergePolicy.cs | 6 +++--- src/Lucene.Net.Tests/Index/TestNoMergePolicy.cs | 4 ++-- src/Lucene.Net/Index/MergeTrigger.cs | 7 ++++++- src/Lucene.Net/Index/UpgradeIndexMergePolicy.cs | 8 ++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Index/MockRandomMergePolicy.cs b/src/Lucene.Net.TestFramework/Index/MockRandomMergePolicy.cs index 03fc938ac8..ed20cb2a22 100644 --- a/src/Lucene.Net.TestFramework/Index/MockRandomMergePolicy.cs +++ b/src/Lucene.Net.TestFramework/Index/MockRandomMergePolicy.cs @@ -116,8 +116,8 @@ public override MergeSpecification FindForcedMerges(SegmentInfos segmentInfos, i public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentInfos) { - // LUCENENET specific - just use int.MinValue to indicate "null" - return FindMerges((MergeTrigger)int.MinValue, segmentInfos); + // LUCENENET specific - use NONE instead of null + return FindMerges(MergeTrigger.NONE, segmentInfos); } protected override void Dispose(bool disposing) @@ -130,4 +130,4 @@ public override bool UseCompoundFile(SegmentInfos infos, SegmentCommitInfo merge return random.Next(5) != 1; } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Index/TestNoMergePolicy.cs b/src/Lucene.Net.Tests/Index/TestNoMergePolicy.cs index 49b1b55b1d..417841d40e 100644 --- a/src/Lucene.Net.Tests/Index/TestNoMergePolicy.cs +++ b/src/Lucene.Net.Tests/Index/TestNoMergePolicy.cs @@ -32,7 +32,7 @@ public class TestNoMergePolicy : LuceneTestCase public virtual void TestNoMergePolicy_Mem() { MergePolicy mp = NoMergePolicy.NO_COMPOUND_FILES; - Assert.IsNull(mp.FindMerges(/*null*/ (MergeTrigger)int.MinValue, (SegmentInfos)null)); + Assert.IsNull(mp.FindMerges(/*null*/ MergeTrigger.NONE, (SegmentInfos)null)); Assert.IsNull(mp.FindForcedMerges(null, 0, null)); Assert.IsNull(mp.FindForcedDeletesMerges(null)); Assert.IsFalse(mp.UseCompoundFile(null, null)); @@ -82,4 +82,4 @@ public virtual void TestMethodsOverridden() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/MergeTrigger.cs b/src/Lucene.Net/Index/MergeTrigger.cs index ea8c80c16a..6516fe2606 100644 --- a/src/Lucene.Net/Index/MergeTrigger.cs +++ b/src/Lucene.Net/Index/MergeTrigger.cs @@ -24,6 +24,11 @@ namespace Lucene.Net.Index /// public enum MergeTrigger { + /// + /// LUCENENET-specific value to be used instead of null. + /// + NONE = -1, + /// /// Merge was triggered by a segment flush. /// @@ -50,4 +55,4 @@ public enum MergeTrigger /// CLOSING } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/UpgradeIndexMergePolicy.cs b/src/Lucene.Net/Index/UpgradeIndexMergePolicy.cs index 0214c46b8f..62a1e359c6 100644 --- a/src/Lucene.Net/Index/UpgradeIndexMergePolicy.cs +++ b/src/Lucene.Net/Index/UpgradeIndexMergePolicy.cs @@ -83,8 +83,8 @@ public override void SetIndexWriter(IndexWriter writer) public override MergeSpecification FindMerges(MergeTrigger mergeTrigger, SegmentInfos segmentInfos) { - // LUCENENET specific - just use min value to indicate "null" for merge trigger - return m_base.FindMerges((MergeTrigger)int.MinValue, segmentInfos); + // LUCENENET specific - use NONE instead of null + return m_base.FindMerges(MergeTrigger.NONE, segmentInfos); } public override MergeSpecification FindForcedMerges(SegmentInfos segmentInfos, int maxSegmentCount, IDictionary segmentsToMerge) @@ -163,7 +163,7 @@ public override bool UseCompoundFile(SegmentInfos segments, SegmentCommitInfo ne protected override void Dispose(bool disposing) { if (disposing) - { + { m_base.Dispose(); } } @@ -184,4 +184,4 @@ private void Message(string message) m_writer.Get().infoStream.Message("UPGMP", message); } } -} \ No newline at end of file +}