99using JCG = J2N . Collections . Generic ;
1010using Directory = Lucene . Net . Store . Directory ;
1111
12+ #nullable enable
13+
1214namespace Lucene . Net . Replicator
1315{
1416 /*
@@ -57,10 +59,10 @@ public class IndexReplicationHandler : IReplicationHandler
5759 public const string INFO_STREAM_COMPONENT = "IndexReplicationHandler" ;
5860
5961 private readonly Directory indexDirectory ;
60- private readonly Action callback ;
62+ private readonly Action ? callback ;
6163
62- private volatile IDictionary < string , IList < RevisionFile > > currentRevisionFiles ;
63- private volatile string currentVersion ;
64+ private volatile IDictionary < string , IList < RevisionFile > > ? currentRevisionFiles ;
65+ private volatile string ? currentVersion ;
6466 private volatile InfoStream infoStream ;
6567
6668 //Note: LUCENENET Specific Utility Method
@@ -78,7 +80,7 @@ private void WriteToInfoStream(params string[] messages)
7880 /// <c>null</c> if there are no commits.
7981 /// </summary>
8082 /// <exception cref="IOException"></exception>
81- public static IndexCommit GetLastCommit ( Directory directory )
83+ public static IndexCommit ? GetLastCommit ( Directory directory )
8284 {
8385 try
8486 {
@@ -106,7 +108,7 @@ public static IndexCommit GetLastCommit(Directory directory)
106108 /// The reason why the code fails instead of putting segments_N file last is
107109 /// that this indicates an error in the <see cref="IRevision"/> implementation.
108110 /// </summary>
109- public static string GetSegmentsFile ( IList < string > files , bool allowEmpty )
111+ public static string ? GetSegmentsFile ( IList < string > files , bool allowEmpty )
110112 {
111113 if ( files . Count == 0 )
112114 {
@@ -121,7 +123,7 @@ public static string GetSegmentsFile(IList<string> files, bool allowEmpty)
121123 if ( ! segmentsFile . StartsWith ( IndexFileNames . SEGMENTS , StringComparison . Ordinal ) || segmentsFile . Equals ( IndexFileNames . SEGMENTS_GEN , StringComparison . Ordinal ) )
122124 {
123125 throw IllegalStateException . Create (
124- string . Format ( "last file to copy+sync must be segments_N but got {0 }; check your Revision implementation!" , segmentsFile ) ) ;
126+ $ "last file to copy+sync must be segments_N but got { segmentsFile } ; check your Revision implementation!") ;
125127 }
126128 return segmentsFile ;
127129 }
@@ -157,11 +159,11 @@ public static void CleanupFilesOnFailure(Directory directory, IList<string> file
157159 /// directory. It suppresses any exceptions that occur, as this can be retried
158160 /// the next time.
159161 /// </remarks>
160- public static void CleanupOldIndexFiles ( Directory directory , string segmentsFile )
162+ public static void CleanupOldIndexFiles ( Directory directory , string ? segmentsFile )
161163 {
162164 try
163165 {
164- IndexCommit commit = GetLastCommit ( directory ) ;
166+ IndexCommit ? commit = GetLastCommit ( directory ) ;
165167 // commit is null means weird IO errors occurred, ignore them
166168 // if there were any IO errors reading the expected commit point (i.e.
167169 // segments files mismatch), then ignore that commit either.
@@ -218,7 +220,7 @@ public static void CopyFiles(Directory source, Directory target, IList<string> f
218220 /// the generation from the given <paramref name="segmentsFile"/>. If it is <c>null</c>,
219221 /// this method deletes segments.gen from the directory.
220222 /// </summary>
221- public static void WriteSegmentsGen ( string segmentsFile , Directory directory )
223+ public static void WriteSegmentsGen ( string ? segmentsFile , Directory directory )
222224 {
223225 if ( segmentsFile != null )
224226 {
@@ -240,9 +242,9 @@ public static void WriteSegmentsGen(string segmentsFile, Directory directory)
240242 /// Constructor with the given index directory and callback to notify when the
241243 /// indexes were updated.
242244 /// </summary>
243- public IndexReplicationHandler ( Directory indexDirectory , Action callback )
245+ public IndexReplicationHandler ( Directory indexDirectory , Action ? callback )
244246 {
245- this . InfoStream = InfoStream . Default ;
247+ infoStream = InfoStream . Default ;
246248 this . callback = callback ;
247249 this . indexDirectory = indexDirectory ;
248250
@@ -258,25 +260,26 @@ public IndexReplicationHandler(Directory indexDirectory, Action callback)
258260 currentRevisionFiles = IndexRevision . RevisionFiles ( commit ) ;
259261
260262 WriteToInfoStream (
261- string . Format ( "constructor(): currentVersion={0 } currentRevisionFiles={1}" , currentVersion , currentRevisionFiles ) ,
262- string . Format ( "constructor(): commit={0}" , commit ) ) ;
263+ $ "constructor(): currentVersion={ currentVersion } currentRevisionFiles={ currentRevisionFiles } " ,
264+ $ "constructor(): commit={ commit } " ) ;
263265 }
264266 }
265267
266- public virtual string CurrentVersion => currentVersion ;
268+ public virtual string ? CurrentVersion => currentVersion ;
267269
268- public virtual IDictionary < string , IList < RevisionFile > > CurrentRevisionFiles => currentRevisionFiles ;
270+ public virtual IDictionary < string , IList < RevisionFile > > ? CurrentRevisionFiles => currentRevisionFiles ;
269271
270272 public virtual void RevisionReady ( string version ,
271273 IDictionary < string , IList < RevisionFile > > revisionFiles ,
272274 IDictionary < string , IList < string > > copiedFiles ,
273275 IDictionary < string , Directory > sourceDirectory )
274276 {
275- if ( revisionFiles . Count > 1 ) throw new ArgumentException ( string . Format ( "this handler handles only a single source; got {0}" , revisionFiles . Keys ) ) ;
277+ if ( revisionFiles . Count > 1 )
278+ throw new ArgumentException ( $ "this handler handles only a single source; got { revisionFiles . Keys } ") ;
276279
277280 Directory clientDirectory = sourceDirectory . Values . First ( ) ;
278281 IList < string > files = copiedFiles . Values . First ( ) ;
279- string segmentsFile = GetSegmentsFile ( files , false ) ;
282+ string segmentsFile = GetSegmentsFile ( files , false ) ! ; // [!]: verified by GetSegmentsFile
280283
281284 bool success = false ;
282285 try
@@ -306,7 +309,7 @@ public virtual void RevisionReady(string version,
306309 currentRevisionFiles = revisionFiles ;
307310 currentVersion = version ;
308311
309- WriteToInfoStream ( string . Format ( "revisionReady(): currentVersion={0 } currentRevisionFiles={1}" , currentVersion , currentRevisionFiles ) ) ;
312+ WriteToInfoStream ( $ "revisionReady(): currentVersion={ currentVersion } currentRevisionFiles={ currentRevisionFiles } " ) ;
310313
311314 // update the segments.gen file
312315 WriteSegmentsGen ( segmentsFile , indexDirectory ) ;
@@ -339,6 +342,7 @@ public virtual void RevisionReady(string version,
339342 public virtual InfoStream InfoStream
340343 {
341344 get => infoStream ;
345+ // ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract
342346 set => infoStream = value ?? InfoStream . NO_OUTPUT ;
343347 }
344348 }
0 commit comments