lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [02/18] lucenenet git commit: Minor cleanups
Date Tue, 06 Jan 2015 03:46:18 GMT
Minor cleanups


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/7a5aa5cc
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/7a5aa5cc
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/7a5aa5cc

Branch: refs/heads/master
Commit: 7a5aa5cc2cfb67377668de649e85590bde99eae1
Parents: 6b0841c
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Mon Jan 5 15:14:33 2015 +0200
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Mon Jan 5 15:14:33 2015 +0200

----------------------------------------------------------------------
 .../Lucene3x/Lucene3xSegmentInfoReader.cs       |   4 +-
 src/Lucene.Net.Core/Index/IndexWriter.cs        |   4 +-
 src/Lucene.Net.Core/Index/LogMergePolicy.cs     |  18 +--
 src/Lucene.Net.Core/Index/SegmentInfos.cs       | 135 +++++++++----------
 .../Support/CollectionsHelper.cs                |   7 -
 .../Support/Compatibility/Collections.cs        |   6 +
 .../Index/BaseStoredFieldsFormatTestCase.cs     |   4 +-
 .../core/Search/TestSubScorerFreqs.cs           |   2 +-
 .../core/Store/TestDirectory.cs                 |   2 +-
 .../core/Store/TestFileSwitchDirectory.cs       |   4 +-
 .../core/Store/TestWindowsMMap.cs               |  43 +++---
 11 files changed, 113 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
index 9519489..8501048 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
@@ -44,7 +44,7 @@ namespace Lucene.Net.Codecs.Lucene3x
     {
         public static void ReadLegacyInfos(SegmentInfos infos, Directory directory, IndexInput
input, int format)
         {
-            infos.Version_Renamed = input.ReadLong(); // read version
+            infos.Version = input.ReadLong(); // read version
             infos.Counter = input.ReadInt(); // read counter
             Lucene3xSegmentInfoReader reader = new Lucene3xSegmentInfoReader();
             for (int i = input.ReadInt(); i > 0; i--) // read segmentInfos
@@ -98,7 +98,7 @@ namespace Lucene.Net.Codecs.Lucene3x
                 infos.Add(siPerCommit);
             }
 
-            infos.UserData_Renamed = input.ReadStringStringMap();
+            infos.UserData = input.ReadStringStringMap();
         }
 
         public override SegmentInfo Read(Directory directory, string segmentName, IOContext
context)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Index/IndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexWriter.cs b/src/Lucene.Net.Core/Index/IndexWriter.cs
index a393fc5..2715a2b 100644
--- a/src/Lucene.Net.Core/Index/IndexWriter.cs
+++ b/src/Lucene.Net.Core/Index/IndexWriter.cs
@@ -5654,9 +5654,9 @@ namespace Lucene.Net.Index
                 EnsureOpen();
                 if (infoStream.IsEnabled("IW"))
                 {
-                    infoStream.Message("IW", "nrtIsCurrent: infoVersion matches: " + (infos.Version_Renamed
== segmentInfos.Version_Renamed) + "; DW changes: " + DocWriter.AnyChanges() + "; BD changes:
" + BufferedUpdatesStream.Any());
+                    infoStream.Message("IW", "nrtIsCurrent: infoVersion matches: " + (infos.Version
== segmentInfos.Version) + "; DW changes: " + DocWriter.AnyChanges() + "; BD changes: " +
BufferedUpdatesStream.Any());
                 }
-                return infos.Version_Renamed == segmentInfos.Version_Renamed && !DocWriter.AnyChanges()
&& !BufferedUpdatesStream.Any();
+                return infos.Version == segmentInfos.Version && !DocWriter.AnyChanges()
&& !BufferedUpdatesStream.Any();
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Index/LogMergePolicy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/LogMergePolicy.cs b/src/Lucene.Net.Core/Index/LogMergePolicy.cs
index 39cfad1..d661a25 100644
--- a/src/Lucene.Net.Core/Index/LogMergePolicy.cs
+++ b/src/Lucene.Net.Core/Index/LogMergePolicy.cs
@@ -252,7 +252,7 @@ namespace Lucene.Net.Index
         private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, int maxNumSegments,
int last)
         {
             MergeSpecification spec = new MergeSpecification();
-            List<SegmentCommitInfo> segments = infos.AsList();
+            IList<SegmentCommitInfo> segments = infos.AsList();
 
             int start = last - 1;
             while (start >= 0)
@@ -300,8 +300,8 @@ namespace Lucene.Net.Index
         /// </summary>
         private MergeSpecification FindForcedMergesMaxNumSegments(SegmentInfos infos, int
maxNumSegments, int last)
         {
-            MergeSpecification spec = new MergeSpecification();
-            List<SegmentCommitInfo> segments = infos.AsList();
+            var spec = new MergeSpecification();
+            var segments = infos.AsList();
 
             // First, enroll all "full" merges (size
             // mergeFactor) to potentially be run concurrently:
@@ -454,7 +454,7 @@ namespace Lucene.Net.Index
         /// </summary>
         public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentInfos)
         {
-            List<SegmentCommitInfo> segments = segmentInfos.AsList();
+            var segments = segmentInfos.AsList();
             int numSegments = segments.Count;
 
             if (Verbose())
@@ -462,7 +462,7 @@ namespace Lucene.Net.Index
                 Message("findForcedDeleteMerges: " + numSegments + " segments");
             }
 
-            MergeSpecification spec = new MergeSpecification();
+            var spec = new MergeSpecification();
             int firstSegmentWithDeletions = -1;
             IndexWriter w = Writer.Get();
             Debug.Assert(w != null);
@@ -520,9 +520,9 @@ namespace Lucene.Net.Index
 
         private class SegmentInfoAndLevel : IComparable<SegmentInfoAndLevel>
         {
-            internal SegmentCommitInfo Info;
-            internal float Level;
-            internal int Index;
+            internal readonly SegmentCommitInfo Info;
+            internal readonly float Level;
+            private int Index;
 
             public SegmentInfoAndLevel(SegmentCommitInfo info, float level, int index)
             {
@@ -558,7 +558,7 @@ namespace Lucene.Net.Index
             // Compute levels, which is just log (base mergeFactor)
             // of the size of each segment
             IList<SegmentInfoAndLevel> levels = new List<SegmentInfoAndLevel>();
-            float norm = (float)Math.Log(MergeFactor_Renamed);
+            var norm = (float)Math.Log(MergeFactor_Renamed);
 
             ICollection<SegmentCommitInfo> mergingSegments = Writer.Get().MergingSegments;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Index/SegmentInfos.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SegmentInfos.cs b/src/Lucene.Net.Core/Index/SegmentInfos.cs
index 0b0fcb6..72ac8ea 100644
--- a/src/Lucene.Net.Core/Index/SegmentInfos.cs
+++ b/src/Lucene.Net.Core/Index/SegmentInfos.cs
@@ -4,6 +4,8 @@ using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading;
+using Lucene.Net.Codecs;
+using Lucene.Net.Store;
 
 namespace Lucene.Net.Index
 {
@@ -139,18 +141,14 @@ namespace Lucene.Net.Index
         /// Used to name new segments. </summary>
         public int Counter;
 
-        /// <summary>
-        /// Counts how often the index has been changed. </summary>
-        public long Version_Renamed;
-
-        private long Generation_Renamed; // generation of the "segments_N" for the next commit
-        private long LastGeneration_Renamed; // generation of the "segments_N" file we last
successfully read
+        private long _generation; // generation of the "segments_N" for the next commit
+        private long _lastGeneration; // generation of the "segments_N" file we last successfully
read
         // or wrote; this is normally the same as generation except if
         // there was an IOException that had interrupted a commit
 
         /// <summary>
         /// Opaque Map&lt;String, String&gt; that user can specify during IndexWriter.commit
</summary>
-        public IDictionary<string, string> UserData_Renamed = CollectionsHelper.EmptyMap<string,
string>();
+        private IDictionary<string, string> _userData = CollectionsHelper.EmptyMap<string,
string>();
 
         private List<SegmentCommitInfo> segments = new List<SegmentCommitInfo>();
 
@@ -191,7 +189,7 @@ namespace Lucene.Net.Index
                 return -1;
             }
             long max = -1;
-            foreach (string file in files)
+            foreach (var file in files)
             {
                 if (file.StartsWith(IndexFileNames.SEGMENTS) && !file.Equals(IndexFileNames.SEGMENTS_GEN))
                 {
@@ -216,7 +214,7 @@ namespace Lucene.Net.Index
             {
                 return GetLastCommitGeneration(directory.ListAll());
             }
-            catch (NoSuchDirectoryException nsde)
+            catch (NoSuchDirectoryException)
             {
                 return -1;
             }
@@ -250,7 +248,7 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "",
LastGeneration_Renamed);
+                return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "",
_lastGeneration);
             }
         }
 
@@ -300,10 +298,10 @@ namespace Lucene.Net.Index
                 finally
                 {
                     genOutput.Dispose();
-                    dir.Sync(/*CollectionsHelper.Singleton(*/ new[] { IndexFileNames.SEGMENTS_GEN
}/*)*/);
+                    dir.Sync(Collections.Singleton(IndexFileNames.SEGMENTS_GEN));
                 }
             }
-            catch (Exception t)
+            catch (Exception)
             {
                 // It's OK if we fail to write this file since it's
                 // used only as one of the retry fallbacks.
@@ -311,7 +309,7 @@ namespace Lucene.Net.Index
                 {
                     dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
                 }
-                catch (Exception t2)
+                catch (Exception)
                 {
                     // Ignore; this file is only used in a retry
                     // fallback on init.
@@ -328,13 +326,13 @@ namespace Lucene.Net.Index
             {
                 long nextGeneration;
 
-                if (Generation_Renamed == -1)
+                if (_generation == -1)
                 {
                     nextGeneration = 1;
                 }
                 else
                 {
-                    nextGeneration = Generation_Renamed + 1;
+                    nextGeneration = _generation + 1;
                 }
                 return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "",
nextGeneration);
             }
@@ -355,9 +353,9 @@ namespace Lucene.Net.Index
             // Clear any previous segments:
             this.Clear();
 
-            Generation_Renamed = GenerationFromSegmentsFileName(segmentFileName);
+            _generation = GenerationFromSegmentsFileName(segmentFileName);
 
-            LastGeneration_Renamed = Generation_Renamed;
+            _lastGeneration = _generation;
 
             ChecksumIndexInput input = directory.OpenChecksumInput(segmentFileName, IOContext.READ);
             try
@@ -368,19 +366,19 @@ namespace Lucene.Net.Index
                 {
                     // 4.0+
                     actualFormat = CodecUtil.CheckHeaderNoMagic(input, "segments", VERSION_40,
VERSION_48);
-                    Version_Renamed = input.ReadLong();
+                    Version = input.ReadLong();
                     Counter = input.ReadInt();
                     int numSegments = input.ReadInt();
                     if (numSegments < 0)
                     {
                         throw new CorruptIndexException("invalid segment count: " + numSegments
+ " (resource: " + input + ")");
                     }
-                    for (int seg = 0; seg < numSegments; seg++)
+                    for (var seg = 0; seg < numSegments; seg++)
                     {
-                        string segName = input.ReadString();
-                        Codec codec = Codec.ForName(input.ReadString());
+                        var segName = input.ReadString();
+                        var codec = Codec.ForName(input.ReadString());
                         //System.out.println("SIS.read seg=" + seg + " codec=" + codec);
-                        SegmentInfo info = codec.SegmentInfoFormat().SegmentInfoReader.Read(directory,
segName, IOContext.READ);
+                        var info = codec.SegmentInfoFormat().SegmentInfoReader.Read(directory,
segName, IOContext.READ);
                         info.Codec = codec;
                         long delGen = input.ReadLong();
                         int delCount = input.ReadInt();
@@ -393,7 +391,7 @@ namespace Lucene.Net.Index
                         {
                             fieldInfosGen = input.ReadLong();
                         }
-                        SegmentCommitInfo siPerCommit = new SegmentCommitInfo(info, delCount,
delGen, fieldInfosGen);
+                        var siPerCommit = new SegmentCommitInfo(info, delCount, delGen, fieldInfosGen);
                         if (actualFormat >= VERSION_46)
                         {
                             int numGensUpdatesFiles = input.ReadInt();
@@ -414,7 +412,7 @@ namespace Lucene.Net.Index
                         }
                         Add(siPerCommit);
                     }
-                    UserData_Renamed = input.ReadStringStringMap();
+                    _userData = input.ReadStringStringMap();
                 }
                 else
                 {
@@ -466,7 +464,7 @@ namespace Lucene.Net.Index
         /// </summary>
         public void Read(Directory directory)
         {
-            Generation_Renamed = LastGeneration_Renamed = -1;
+            _generation = _lastGeneration = -1;
 
             new FindSegmentsFileAnonymousInnerClassHelper(this, directory).Run();
         }
@@ -475,7 +473,7 @@ namespace Lucene.Net.Index
         {
             private readonly SegmentInfos OuterInstance;
 
-            private new Directory Directory;
+            private new readonly Directory Directory;
 
             public FindSegmentsFileAnonymousInnerClassHelper(SegmentInfos outerInstance,
Directory directory)
                 : base(directory)
@@ -503,25 +501,25 @@ namespace Lucene.Net.Index
             string segmentsFileName = NextSegmentFileName;
 
             // Always advance the generation on write:
-            if (Generation_Renamed == -1)
+            if (_generation == -1)
             {
-                Generation_Renamed = 1;
+                _generation = 1;
             }
             else
             {
-                Generation_Renamed++;
+                _generation++;
             }
 
             IndexOutput segnOutput = null;
             bool success = false;
 
-            HashSet<string> upgradedSIFiles = new HashSet<string>();
+            var upgradedSIFiles = new HashSet<string>();
 
             try
             {
                 segnOutput = directory.CreateOutput(segmentsFileName, IOContext.DEFAULT);
                 CodecUtil.WriteHeader(segnOutput, "segments", VERSION_48);
-                segnOutput.WriteLong(Version_Renamed);
+                segnOutput.WriteLong(Version);
                 segnOutput.WriteInt(Counter); // write counter
                 segnOutput.WriteInt(Size()); // write infos
                 foreach (SegmentCommitInfo siPerCommit in segments)
@@ -575,11 +573,11 @@ namespace Lucene.Net.Index
                                 @out.Dispose();
                             }
                             upgradedSIFiles.Add(markerFileName);
-                            directory.Sync(/*Collections.singletonList(*/new[] { markerFileName
}/*)*/);
+                            directory.Sync(/*Collections.SingletonList(*/new[] { markerFileName
}/*)*/);
                         }
                     }
                 }
-                segnOutput.WriteStringStringMap(UserData_Renamed);
+                segnOutput.WriteStringStringMap(_userData);
                 PendingSegnOutput = segnOutput;
                 success = true;
             }
@@ -597,7 +595,7 @@ namespace Lucene.Net.Index
                         {
                             directory.DeleteFile(fileName);
                         }
-                        catch (Exception t)
+                        catch (Exception)
                         {
                             // Suppress so we keep throwing the original exception
                         }
@@ -609,7 +607,7 @@ namespace Lucene.Net.Index
                         // the index:
                         directory.DeleteFile(segmentsFileName);
                     }
-                    catch (Exception t)
+                    catch (Exception)
                     {
                         // Suppress so we keep throwing the original exception
                     }
@@ -630,7 +628,7 @@ namespace Lucene.Net.Index
                     return true;
                 }
             }
-            catch (IOException ioe)
+            catch (IOException)
             {
                 // Ignore: if something is wrong w/ the marker file,
                 // we will just upgrade again
@@ -705,7 +703,7 @@ namespace Lucene.Net.Index
 
         public object Clone()
         {
-            SegmentInfos sis = (SegmentInfos)base.MemberwiseClone();
+            var sis = (SegmentInfos)base.MemberwiseClone();
             // deep clone, first recreate all collections:
             sis.segments = new List<SegmentCommitInfo>(Size());
             foreach (SegmentCommitInfo info in segments)
@@ -714,7 +712,7 @@ namespace Lucene.Net.Index
                 // dont directly access segments, use add method!!!
                 sis.Add((SegmentCommitInfo)(info.Clone()));
             }
-            sis.UserData_Renamed = new Dictionary<string, string>(UserData_Renamed);
+            sis._userData = new Dictionary<string, string>(_userData);
             return sis;
         }
 
@@ -723,16 +721,11 @@ namespace Lucene.Net.Index
             get { return segments; }
         }
 
+
         /// <summary>
-        /// version number when this SegmentInfos was generated.
+        /// Counts how often the index has been changed.
         /// </summary>
-        public long Version
-        {
-            get
-            {
-                return Version_Renamed;
-            }
-        }
+        public long Version { get; set; }
 
         /// <summary>
         /// Returns current generation. </summary>
@@ -740,7 +733,7 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return Generation_Renamed;
+                return _generation;
             }
         }
 
@@ -750,7 +743,7 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return LastGeneration_Renamed;
+                return _lastGeneration;
             }
         }
 
@@ -1116,8 +1109,8 @@ namespace Lucene.Net.Index
         // Carry over generation numbers from another SegmentInfos
         internal void UpdateGeneration(SegmentInfos other)
         {
-            LastGeneration_Renamed = other.LastGeneration_Renamed;
-            Generation_Renamed = other.Generation_Renamed;
+            _lastGeneration = other._lastGeneration;
+            _generation = other._generation;
         }
 
         internal void RollbackCommit(Directory dir)
@@ -1131,7 +1124,7 @@ namespace Lucene.Net.Index
 
                 // Must carefully compute fileName from "generation"
                 // since lastGeneration isn't incremented:
-                string segmentFileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS,
"", Generation_Renamed);
+                string segmentFileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS,
"", _generation);
                 // Suppress so we keep throwing the original exception
                 // in our caller
                 IOUtils.DeleteFilesIgnoringExceptions(dir, segmentFileName);
@@ -1168,7 +1161,7 @@ namespace Lucene.Net.Index
         /// </summary>
         public ICollection<string> Files(Directory dir, bool includeSegmentsFile)
         {
-            HashSet<string> files = new HashSet<string>();
+            var files = new HashSet<string>();
             if (includeSegmentsFile)
             {
                 string segmentFileName = SegmentsFileName;
@@ -1177,10 +1170,10 @@ namespace Lucene.Net.Index
                     files.Add(segmentFileName);
                 }
             }
-            int size = Size();
+            var size = Size();
             for (int i = 0; i < size; i++)
             {
-                SegmentCommitInfo info = Info(i);
+                var info = Info(i);
                 Debug.Assert(info.Info.Dir == dir);
                 if (info.Info.Dir == dir)
                 {
@@ -1243,11 +1236,11 @@ namespace Lucene.Net.Index
             // logic in SegmentInfos to kick in and load the last
             // good (previous) segments_N-1 file.
 
-            string fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS,
"", Generation_Renamed);
+            var fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS,
"", _generation);
             success = false;
             try
             {
-                dir.Sync(/*Collections.singleton(*/new[] { fileName }/*)*/);
+                dir.Sync(Collections.Singleton(fileName));
                 success = true;
             }
             finally
@@ -1258,15 +1251,15 @@ namespace Lucene.Net.Index
                     {
                         dir.DeleteFile(fileName);
                     }
-                    catch (Exception t)
+                    catch (Exception)
                     {
                         // Suppress so we keep throwing the original exception
                     }
                 }
             }
 
-            LastGeneration_Renamed = Generation_Renamed;
-            WriteSegmentsGen(dir, Generation_Renamed);
+            _lastGeneration = _generation;
+            WriteSegmentsGen(dir, _generation);
         }
 
         /// <summary>
@@ -1288,7 +1281,7 @@ namespace Lucene.Net.Index
         /// Returns readable description of this segment. </summary>
         public string ToString(Directory directory)
         {
-            StringBuilder buffer = new StringBuilder();
+            var buffer = new StringBuilder();
             buffer.Append(SegmentsFileName).Append(": ");
             int count = Size();
             for (int i = 0; i < count; i++)
@@ -1311,17 +1304,17 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return UserData_Renamed;
+                return _userData;
             }
             set
             {
                 if (value == null)
                 {
-                    UserData_Renamed = CollectionsHelper.EmptyMap<string, string>();
+                    _userData = CollectionsHelper.EmptyMap<string, string>();
                 }
                 else
                 {
-                    UserData_Renamed = value;
+                    _userData = value;
                 }
             }
         }
@@ -1334,7 +1327,7 @@ namespace Lucene.Net.Index
         internal void Replace(SegmentInfos other)
         {
             RollbackSegmentInfos(other.AsList());
-            LastGeneration_Renamed = other.LastGeneration_Renamed;
+            _lastGeneration = other._lastGeneration;
         }
 
         /// <summary>
@@ -1352,14 +1345,14 @@ namespace Lucene.Net.Index
         /// </summary>
         public void Changed()
         {
-            Version_Renamed++;
+            Version++;
         }
 
         /// <summary>
         /// applies all changes caused by committing a merge to this SegmentInfos </summary>
         internal void ApplyMergeChanges(MergePolicy.OneMerge merge, bool dropSegment)
         {
-            HashSet<SegmentCommitInfo> mergedAway = new HashSet<SegmentCommitInfo>(merge.Segments);
+            var mergedAway = new HashSet<SegmentCommitInfo>(merge.Segments);
             bool inserted = false;
             int newSegIdx = 0;
             for (int segIdx = 0, cnt = segments.Count; segIdx < cnt; segIdx++)
@@ -1398,8 +1391,8 @@ namespace Lucene.Net.Index
 
         internal IList<SegmentCommitInfo> CreateBackupSegmentInfos()
         {
-            IList<SegmentCommitInfo> list = new List<SegmentCommitInfo>(Size());
-            foreach (SegmentCommitInfo info in segments)
+            var list = new List<SegmentCommitInfo>(Size());
+            foreach (var info in segments)
             {
                 Debug.Assert(info.Info.Codec != null);
                 list.Add((SegmentCommitInfo)(info.Clone()));
@@ -1415,9 +1408,9 @@ namespace Lucene.Net.Index
 
         /// <summary>
         /// Returns all contained segments as an <b>unmodifiable</b> <seealso
cref="List"/> view. </summary>
-        public List<SegmentCommitInfo> AsList()
+        public IList<SegmentCommitInfo> AsList()
         {
-            return /*Collections.unmodifiableList*/(segments);
+            return Collections.UnmodifiableList<SegmentCommitInfo>(segments.ToArray());
         }
 
         /// <summary>
@@ -1438,7 +1431,7 @@ namespace Lucene.Net.Index
         /// Appends the provided <seealso cref="SegmentCommitInfo"/>s. </summary>
         public void AddAll(IEnumerable<SegmentCommitInfo> sis)
         {
-            foreach (SegmentCommitInfo si in sis)
+            foreach (var si in sis)
             {
                 this.Add(si);
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Support/CollectionsHelper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/CollectionsHelper.cs b/src/Lucene.Net.Core/Support/CollectionsHelper.cs
index ae79001..1a230d3 100644
--- a/src/Lucene.Net.Core/Support/CollectionsHelper.cs
+++ b/src/Lucene.Net.Core/Support/CollectionsHelper.cs
@@ -217,13 +217,6 @@ namespace Lucene.Net.Support
             return true;
         }
 
-        public static ISet<T> Singleton<T>(T single)
-        {
-            T[] singletonArr = new T[] { single };
-            HashSet<T> singleton = new HashSet<T>(singletonArr);
-            return singleton;
-        }
-
         /// <summary>
         /// Fills the array with an specific value from an specific index to an specific
index.
         /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
index 8c8a53e..5a54f49 100644
--- a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
+++ b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
@@ -1,5 +1,6 @@
 ´╗┐using System.Collections.Generic;
 using System.Collections.Immutable;
+using System.Linq;
 
 namespace Lucene.Net
 {
@@ -14,5 +15,10 @@ namespace Lucene.Net
         {
             return ImmutableList<T>.Empty;
         }
+
+        public static IList<T> UnmodifiableList<T>(IEnumerable<T> items)
+        {
+            return ImmutableList.Create<T>(items.ToArray());
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
index 7062269..ac3613f 100644
--- a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
@@ -401,9 +401,9 @@ namespace Lucene.Net.Index
             foreach (Field fld in fields)
             {
                 string fldName = fld.Name();
-                Document sDoc = reader.Document(docID, CollectionsHelper.Singleton(fldName));
+                Document sDoc = reader.Document(docID, Collections.Singleton(fldName));
                 IndexableField sField = sDoc.GetField(fldName);
-                if (typeof(Field).Equals(fld.GetType()))
+                if (typeof(Field) == fld.GetType())
                 {
                     Assert.AreEqual(fld.BinaryValue(), sField.BinaryValue());
                     Assert.AreEqual(fld.StringValue, sField.StringValue);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs b/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
index ce857e3..451108c 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
@@ -180,7 +180,7 @@ namespace Lucene.Net.Search
 
             // Only needed in Java6; Java7+ has a @SafeVarargs annotated Arrays#asList()!
             // see http://docs.oracle.com/javase/7/docs/api/java/lang/SafeVarargs.html
-            IEnumerable<ISet<string>> occurList = Arrays.AsList(CollectionsHelper.Singleton("MUST"),
new HashSet<string>(Arrays.AsList("MUST", "SHOULD")));
+            IEnumerable<ISet<string>> occurList = Arrays.AsList(Collections.Singleton("MUST"),
new HashSet<string>(Arrays.AsList("MUST", "SHOULD")));
 
             foreach (HashSet<string> occur in occurList)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
index 862d3d1..ecc0b31 100644
--- a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
@@ -385,7 +385,7 @@ namespace Lucene.Net.Store
                 // fsync it
                 try
                 {
-                    fsdir.Sync(CollectionsHelper.Singleton("afile"));
+                    fsdir.Sync(Collections.Singleton("afile"));
                     Assert.Fail("didn't get expected exception, instead fsync created new
files: " +
                                 Arrays.AsList(fsdir.ListAll()));
                 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
index fb71235..4f3b773 100644
--- a/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
@@ -147,8 +147,8 @@ namespace Lucene.Net.Store
         [Test]
         public virtual void TestCompoundFileAppendTwice()
         {
-            Directory newDir = NewFSSwitchDirectory(CollectionsHelper.Singleton("cfs"));
-            CompoundFileDirectory csw = new CompoundFileDirectory(newDir, "d.cfs", NewIOContext(Random()),
true);
+            Directory newDir = NewFSSwitchDirectory(Collections.Singleton("cfs"));
+            var csw = new CompoundFileDirectory(newDir, "d.cfs", NewIOContext(Random()),
true);
             CreateSequenceFile(newDir, "d1", (sbyte)0, 15);
             IndexOutput @out = csw.CreateOutput("d.xyz", NewIOContext(Random()));
             @out.WriteInt(0);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
index 7425024..217c851 100644
--- a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
@@ -74,31 +74,36 @@ namespace Lucene.Net.Store
             // sometimes the directory is not cleaned by rmDir, because on Windows it
             // may take some time until the files are finally dereferenced. So clean the
             // directory up front, or otherwise new IndexWriter will fail.
-            DirectoryInfo dirPath = CreateTempDir("testLuceneMmap");
+            var dirPath = CreateTempDir("testLuceneMmap");
             RmDir(dirPath);
-            MMapDirectory dir = new MMapDirectory(dirPath, null);
+            var dir = new MMapDirectory(dirPath, null);
 
             // plan to add a set of useful stopwords, consider changing some of the
             // interior filters.
-            MockAnalyzer analyzer = new MockAnalyzer(Random());
-            // TODO: something about lock timeouts and leftover locks.
-            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
analyzer).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE));
-            writer.Commit();
-            IndexReader reader = DirectoryReader.Open(dir);
-            IndexSearcher searcher = NewSearcher(reader);
-
-            int num = AtLeast(1000);
-            for (int dx = 0; dx < num; dx++)
+            using (var analyzer = new MockAnalyzer(Random()))
             {
-                string f = RandomField();
-                Document doc = new Document();
-                doc.Add(NewTextField("data", f, Field.Store.YES));
-                writer.AddDocument(doc);
-            }
+                // TODO: something about lock timeouts and leftover locks.
+                using (var writer = new IndexWriter(dir,
+                    new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(
+                        IndexWriterConfig.OpenMode_e.CREATE)))
+                {
+                    writer.Commit();
+                    using (IndexReader reader = DirectoryReader.Open(dir))
+                    {
+                        var searcher = NewSearcher(reader);
+                        var num = AtLeast(1000);
+                        for (int dx = 0; dx < num; dx++)
+                        {
+                            var f = RandomField();
+                            var doc = new Document();
+                            doc.Add(NewTextField("data", f, Field.Store.YES));
+                            writer.AddDocument(doc);
+                        }
+                    }
+                }
 
-            reader.Dispose();
-            writer.Dispose();
-            RmDir(dirPath);
+                RmDir(dirPath);
+            }
         }
 
         private static void RmDir(DirectoryInfo dir)


Mime
View raw message