Skip to content

Commit

Permalink
Replace int.MinValue with MergeTrigger.NONE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paulirwin committed Mar 10, 2024
1 parent f029231 commit cd8e057
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Lucene.Net.TestFramework/Index/MockRandomMergePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -130,4 +130,4 @@ public override bool UseCompoundFile(SegmentInfos infos, SegmentCommitInfo merge
return random.Next(5) != 1;
}
}
}
}
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/Index/TestNoMergePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -82,4 +82,4 @@ public virtual void TestMethodsOverridden()
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/Lucene.Net/Index/MergeTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace Lucene.Net.Index
/// </summary>
public enum MergeTrigger
{
/// <summary>
/// LUCENENET-specific value to be used instead of null.
/// </summary>
NONE = -1,

/// <summary>
/// Merge was triggered by a segment flush.
/// </summary>
Expand All @@ -50,4 +55,4 @@ public enum MergeTrigger
/// </summary>
CLOSING
}
}
}
8 changes: 4 additions & 4 deletions src/Lucene.Net/Index/UpgradeIndexMergePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SegmentCommitInfo, bool> segmentsToMerge)
Expand Down Expand Up @@ -163,7 +163,7 @@ public override bool UseCompoundFile(SegmentInfos segments, SegmentCommitInfo ne
protected override void Dispose(bool disposing)
{
if (disposing)
{
{
m_base.Dispose();
}
}
Expand All @@ -184,4 +184,4 @@ private void Message(string message)
m_writer.Get().infoStream.Message("UPGMP", message);
}
}
}
}

0 comments on commit cd8e057

Please sign in to comment.