lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccurr...@apache.org
Subject [Lucene.Net] svn commit: r1294875 [19/45] - in /incubator/lucene.net/trunk: ./ build/ build/vs2010/contrib/ build/vs2010/test/ doc/ src/ src/contrib/Analyzers/ src/contrib/Analyzers/AR/ src/contrib/Analyzers/BR/ src/contrib/Analyzers/CJK/ src/contrib/Analyzers/Cn/ ...
Date Tue, 28 Feb 2012 22:43:28 GMT
Modified: incubator/lucene.net/trunk/src/core/Index/ReadOnlyDirectoryReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/ReadOnlyDirectoryReader.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/ReadOnlyDirectoryReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/ReadOnlyDirectoryReader.cs Tue Feb 28 22:43:08 2012
@@ -27,12 +27,13 @@ namespace Lucene.Net.Index
 		internal ReadOnlyDirectoryReader(Directory directory, SegmentInfos sis, IndexDeletionPolicy deletionPolicy, int termInfosIndexDivisor):base(directory, sis, deletionPolicy, true, termInfosIndexDivisor)
 		{
 		}
-		
-		internal ReadOnlyDirectoryReader(Directory directory, SegmentInfos infos, SegmentReader[] oldReaders, int[] oldStarts, System.Collections.IDictionary oldNormsCache, bool doClone, int termInfosIndexDivisor):base(directory, infos, oldReaders, oldStarts, oldNormsCache, true, doClone, termInfosIndexDivisor)
-		{
-		}
-		
-		internal ReadOnlyDirectoryReader(IndexWriter writer, SegmentInfos infos, int termInfosIndexDivisor):base(writer, infos, termInfosIndexDivisor)
+
+        internal ReadOnlyDirectoryReader(Directory directory, SegmentInfos infos, SegmentReader[] oldReaders, int[] oldStarts, System.Collections.Generic.IDictionary<string, byte[]> oldNormsCache, bool doClone, int termInfosIndexDivisor)
+            : base(directory, infos, oldReaders, oldStarts, oldNormsCache, true, doClone, termInfosIndexDivisor)
+        {
+        }
+
+	    internal ReadOnlyDirectoryReader(IndexWriter writer, SegmentInfos infos, int termInfosIndexDivisor):base(writer, infos, termInfosIndexDivisor)
 		{
 		}
 		

Modified: incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/ReusableStringReader.cs Tue Feb 28 22:43:08 2012
@@ -16,6 +16,7 @@
  */
 
 using System;
+using Lucene.Net.Support;
 
 namespace Lucene.Net.Index
 {
@@ -35,38 +36,43 @@ namespace Lucene.Net.Index
             left = s.Length;
             this.upto = 0;
         }
+
         public int Read(char[] c)
         {
             return Read(c, 0, c.Length);
         }
+
         public override int Read(System.Char[] c, int off, int len)
         {
             if (left > len)
             {
-                SupportClass.TextSupport.GetCharsFromString(s, upto, upto + len, c, off);
+                TextSupport.GetCharsFromString(s, upto, upto + len, c, off);
                 upto += len;
                 left -= len;
                 return len;
             }
             else if (0 == left)
             {
+                // don't keep a reference (s could have been very large)
                 s = null;
                 return 0;
             }
             else
             {
-                SupportClass.TextSupport.GetCharsFromString(s, upto, upto + left, c, off);
+                TextSupport.GetCharsFromString(s, upto, upto + left, c, off);
                 int r = left;
                 left = 0;
                 upto = s.Length;
                 return r;
             }
         }
+
+        [Obsolete("Use Dispose() instead")]
         public override void Close()
         {
+            Dispose();
         }
 
-
         public override int Read()
         {
             if (left > 0)

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentInfo.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentInfo.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentInfo.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,8 @@
  */
 
 using System;
-
+using System.Collections.Generic;
+using Lucene.Net.Support;
 using Directory = Lucene.Net.Store.Directory;
 using IndexInput = Lucene.Net.Store.IndexInput;
 using IndexOutput = Lucene.Net.Store.IndexOutput;
@@ -34,59 +35,59 @@ namespace Lucene.Net.Index
 	public sealed class SegmentInfo : System.ICloneable
 	{
 		
-		internal const int NO = - 1; // e.g. no norms; no deletes;
-		internal const int YES = 1; // e.g. have norms; have deletes;
-		internal const int CHECK_DIR = 0; // e.g. must check dir to see if there are norms/deletions
-		internal const int WITHOUT_GEN = 0; // a file name that has no GEN in it. 
-		
-		public System.String name; // unique name in dir
-		public int docCount; // number of docs in seg
-		public Directory dir; // where segment resides
-		
-		private bool preLockless; // true if this is a segments file written before
-		// lock-less commits (2.1)
-		
-		private long delGen; // current generation of del file; NO if there
-		// are no deletes; CHECK_DIR if it's a pre-2.1 segment
-		// (and we must check filesystem); YES or higher if
-		// there are deletes at generation N
-		
-		private long[] normGen; // current generation of each field's norm file.
-		// If this array is null, for lockLess this means no 
-		// separate norms.  For preLockLess this means we must 
-		// check filesystem. If this array is not null, its 
-		// values mean: NO says this field has no separate  
-		// norms; CHECK_DIR says it is a preLockLess segment and    
-		// filesystem must be checked; >= YES says this field  
-		// has separate norms with the specified generation
-		
-		private sbyte isCompoundFile; // NO if it is not; YES if it is; CHECK_DIR if it's
-		// pre-2.1 (ie, must check file system to see
-		// if <name>.cfs and <name>.nrm exist)         
-		
-		private bool hasSingleNormFile; // true if this segment maintains norms in a single file; 
-		// false otherwise
-		// this is currently false for segments populated by DocumentWriter
-		// and true for newly created merged segments (both
-		// compound and non compound).
-		
-		private System.Collections.Generic.IList<string> files; // cached list of files that this segment uses
-		// in the Directory
-		
-		internal long sizeInBytes = - 1; // total byte size of all of our files (computed on demand)
-		
-		private int docStoreOffset; // if this segment shares stored fields & vectors, this
-		// offset is where in that file this segment's docs begin
-		private System.String docStoreSegment; // name used to derive fields/vectors file we share with
-		// other segments
-		private bool docStoreIsCompoundFile; // whether doc store files are stored in compound file (*.cfx)
+		internal const int NO = - 1;            // e.g. no norms; no deletes;
+		internal const int YES = 1;             // e.g. have norms; have deletes;
+		internal const int CHECK_DIR = 0;       // e.g. must check dir to see if there are norms/deletions
+		internal const int WITHOUT_GEN = 0;     // a file name that has no GEN in it. 
+		
+		public System.String name;              // unique name in dir
+		public int docCount;                    // number of docs in seg
+		public Directory dir;                   // where segment resides
+		
+		private bool preLockless;               // true if this is a segments file written before
+		                                        // lock-less commits (2.1)
+		
+		private long delGen;                    // current generation of del file; NO if there
+		                                        // are no deletes; CHECK_DIR if it's a pre-2.1 segment
+		                                        // (and we must check filesystem); YES or higher if
+		                                        // there are deletes at generation N
+		
+		private long[] normGen;                 // current generation of each field's norm file.
+		                                        // If this array is null, for lockLess this means no 
+		                                        // separate norms.  For preLockLess this means we must 
+		                                        // check filesystem. If this array is not null, its 
+		                                        // values mean: NO says this field has no separate  
+		                                        // norms; CHECK_DIR says it is a preLockLess segment and    
+		                                        // filesystem must be checked; >= YES says this field  
+		                                        // has separate norms with the specified generation
+		
+		private sbyte isCompoundFile;           // NO if it is not; YES if it is; CHECK_DIR if it's
+		                                        // pre-2.1 (ie, must check file system to see
+		                                        // if <name>.cfs and <name>.nrm exist)         
+		
+		private bool hasSingleNormFile;         // true if this segment maintains norms in a single file; 
+		                                        // false otherwise
+		                                        // this is currently false for segments populated by DocumentWriter
+		                                        // and true for newly created merged segments (both
+		                                        // compound and non compound).
+		
+		private IList<string> files;            // cached list of files that this segment uses
+		                                        // in the Directory
+		
+		internal long sizeInBytes = - 1;        // total byte size of all of our files (computed on demand)
+		
+		private int docStoreOffset;             // if this segment shares stored fields & vectors, this
+		                                        // offset is where in that file this segment's docs begin
+		private System.String docStoreSegment;  // name used to derive fields/vectors file we share with
+		                                        // other segments
+		private bool docStoreIsCompoundFile;    // whether doc store files are stored in compound file (*.cfx)
 		
-		private int delCount; // How many deleted docs in this segment, or -1 if not yet known
-		// (if it's an older index)
+		private int delCount;                   // How many deleted docs in this segment, or -1 if not yet known
+		                                        // (if it's an older index)
 		
-		private bool hasProx; // True if this segment has any fields with omitTermFreqAndPositions==false
+		private bool hasProx;                   // True if this segment has any fields with omitTermFreqAndPositions==false
 
-        private System.Collections.Generic.IDictionary<string, string> diagnostics;
+        private IDictionary<string, string> diagnostics;
 		
 		public override System.String ToString()
 		{
@@ -151,14 +152,12 @@ namespace Lucene.Net.Index
 			delCount = src.delCount;
 		}
 		
-		// must be Map<String, String>
-        internal void SetDiagnostics(System.Collections.Generic.IDictionary<string, string> diagnostics)
+        internal void SetDiagnostics(IDictionary<string, string> diagnostics)
 		{
 			this.diagnostics = diagnostics;
 		}
 		
-		// returns Map<String, String>
-        public System.Collections.Generic.IDictionary<string, string> GetDiagnostics()
+        public IDictionary<string, string> GetDiagnostics()
 		{
 			return diagnostics;
 		}
@@ -242,7 +241,7 @@ namespace Lucene.Net.Index
 				}
 				else
 				{
-					diagnostics = new System.Collections.Generic.Dictionary<string,string>();
+					diagnostics = new Dictionary<string,string>();
 				}
 			}
 			else
@@ -257,7 +256,7 @@ namespace Lucene.Net.Index
 				docStoreSegment = null;
 				delCount = - 1;
 				hasProx = true;
-				diagnostics = new System.Collections.Generic.Dictionary<string,string>();
+				diagnostics = new Dictionary<string,string>();
 			}
 		}
 		
@@ -294,12 +293,12 @@ namespace Lucene.Net.Index
 		{
 			if (sizeInBytes == - 1)
 			{
-				System.Collections.Generic.IList<string> files = Files();
+				IList<string> files = Files();
 				int size = files.Count;
 				sizeInBytes = 0;
 				for (int i = 0; i < size; i++)
 				{
-					System.String fileName = (System.String) files[i];
+					System.String fileName = files[i];
 					// We don't count bytes used by a shared doc store
 					// against this segment:
 					if (docStoreOffset == - 1 || !IndexFileNames.IsDocStoreFile(fileName))
@@ -368,6 +367,7 @@ namespace Lucene.Net.Index
 			si.hasProx = hasProx;
 			si.preLockless = preLockless;
 			si.hasSingleNormFile = hasSingleNormFile;
+		    si.diagnostics = new HashMap<string, string>(this.diagnostics);
             if (this.diagnostics != null)
             {
                 si.diagnostics = new System.Collections.Generic.Dictionary<string, string>();
@@ -450,18 +450,20 @@ namespace Lucene.Net.Index
 					// This means this segment was saved with pre-LOCKLESS
 					// code.  So we must fallback to the original
 					// directory list check:
-					System.String[] result = dir.List();
+					System.String[] result = dir.ListAll();
 					if (result == null)
 					{
-						throw new System.IO.IOException("cannot read directory " + dir + ": list() returned null");
+                        throw new System.IO.IOException("cannot read directory " + dir + ": ListAll() returned null");
 					}
-					
+
+				    IndexFileNameFilter filter = IndexFileNameFilter.GetFilter();
 					System.String pattern;
 					pattern = name + ".s";
 					int patternLength = pattern.Length;
 					for (int i = 0; i < result.Length; i++)
 					{
-						if (result[i].StartsWith(pattern) && System.Char.IsDigit(result[i][patternLength]))
+					    string fileName = result[i];
+						if (filter.Accept(null, fileName) && fileName.StartsWith(pattern) && char.IsDigit(fileName[patternLength]))
 							return true;
 					}
 					return false;
@@ -690,7 +692,7 @@ namespace Lucene.Net.Index
 			return hasProx;
 		}
 		
-		private void  AddIfExists(System.Collections.Generic.IList<string> files, System.String fileName)
+		private void  AddIfExists(IList<string> files, System.String fileName)
 		{
 			if (dir.FileExists(fileName))
 				files.Add(fileName);
@@ -702,7 +704,7 @@ namespace Lucene.Net.Index
 		* modify it.
 		*/
 		
-		public System.Collections.Generic.IList<string> Files()
+		public IList<string> Files()
 		{
 			
 			if (files != null)
@@ -711,7 +713,7 @@ namespace Lucene.Net.Index
 				return files;
 			}
 
-            System.Collections.Generic.List<string> fileList = new System.Collections.Generic.List<string>();
+            var fileList = new System.Collections.Generic.List<string>();
 			
 			bool useCompoundFile = GetUseCompoundFile();
 			
@@ -865,16 +867,14 @@ namespace Lucene.Net.Index
 		/// </summary>
 		public  override bool Equals(System.Object obj)
 		{
-			SegmentInfo other;
-			try
-			{
-				other = (SegmentInfo) obj;
-			}
-			catch (System.InvalidCastException cce)
-			{
-				return false;
-			}
-			return other.dir == dir && other.name.Equals(name);
+            if (this == obj) return true;
+
+            if (obj is SegmentInfo)
+            {
+                SegmentInfo other = (SegmentInfo) obj;
+                return other.dir == dir && other.name.Equals(name);
+            }
+		    return false;
 		}
 		
 		public override int GetHashCode()

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,8 @@
  */
 
 using System;
-
+using System.Collections.Generic;
+using Lucene.Net.Support;
 using ChecksumIndexInput = Lucene.Net.Store.ChecksumIndexInput;
 using ChecksumIndexOutput = Lucene.Net.Store.ChecksumIndexOutput;
 using Directory = Lucene.Net.Store.Directory;
@@ -34,7 +35,7 @@ namespace Lucene.Net.Index
 	/// (subject to change suddenly in the next release)<p/>
 	/// </summary>
 	[Serializable]
-	public sealed class SegmentInfos:System.Collections.ArrayList
+	public sealed class SegmentInfos : List<SegmentInfo>, ICloneable
 	{
 		private class AnonymousClassFindSegmentsFile:FindSegmentsFile
 		{
@@ -126,7 +127,7 @@ namespace Lucene.Net.Index
 		// or wrote; this is normally the same as generation except if
 		// there was an IOException that had interrupted a commit
 
-        private System.Collections.Generic.IDictionary<string, string> userData = new System.Collections.Generic.Dictionary<string, string>(); // Opaque Map<String, String> that user can specify during IndexWriter.commit
+        private IDictionary<string, string> userData = new HashMap<string, string>(); // Opaque Map<String, String> that user can specify during IndexWriter.commit
 		
 		/// <summary> If non-null, information about loading segments_N files</summary>
 		/// <seealso cref="SetInfoStream">
@@ -224,7 +225,7 @@ namespace Lucene.Net.Index
 			}
 			else if (fileName.StartsWith(IndexFileNames.SEGMENTS))
 			{
-				return SupportClass.Number.ToInt64(fileName.Substring(1 + IndexFileNames.SEGMENTS.Length));
+				return Number.ToInt64(fileName.Substring(1 + IndexFileNames.SEGMENTS.Length));
 			}
 			else
 			{
@@ -314,22 +315,25 @@ namespace Lucene.Net.Index
 					}
 					else if (0 != input.ReadByte())
 					{
-                        userData = new System.Collections.Generic.Dictionary<string,string>();
+                        // TODO: Should be read-only map
+                        userData = new HashMap<string,string>();
 						userData.Add("userData", input.ReadString());
 					}
 					else
 					{
-                        userData = new System.Collections.Generic.Dictionary<string, string>();
+                        // TODO: Should be empty read-only map
+                        userData = new HashMap<string, string>();
 					}
 				}
 				else
 				{
-                    userData = new System.Collections.Generic.Dictionary<string, string>();
+                    // TODO: Should be empty read-only map
+                    userData = new HashMap<string, string>();
 				}
 				
 				if (format <= FORMAT_CHECKSUM)
 				{
-					long checksumNow = input.GetChecksum();
+					long checksumNow = input.Checksum;
 					long checksumThen = input.ReadLong();
 					if (checksumNow != checksumThen)
 						throw new CorruptIndexException("checksum mismatch in segments file");
@@ -432,18 +436,18 @@ namespace Lucene.Net.Index
 		/// SegmentInfo.
 		/// </summary>
 		
-		public override System.Object Clone()
+		public System.Object Clone()
 		{
             SegmentInfos sis = new SegmentInfos();
             for (int i = 0; i < this.Count; i++)
             {
-                sis.Add(((SegmentInfo) this[i]).Clone());
+                sis.Add((SegmentInfo)this[i].Clone());
             }
             sis.counter = this.counter;
             sis.generation = this.generation;
             sis.lastGeneration = this.lastGeneration;
             // sis.pendingSegnOutput = this.pendingSegnOutput; // {{Aroush-2.9}} needed?
-            sis.userData = new System.Collections.Generic.Dictionary<string, string>(userData);
+            sis.userData = new HashMap<string, string>(userData);
             sis.version = this.version;
             return sis;
 		}
@@ -563,7 +567,7 @@ namespace Lucene.Net.Index
 		{
 			if (infoStream != null)
 			{
-				infoStream.WriteLine("SIS [" + SupportClass.ThreadClass.Current().Name + "]: " + message);
+				infoStream.WriteLine("SIS [" + ThreadClass.Current().Name + "]: " + message);
 			}
 		}
 		
@@ -579,8 +583,8 @@ namespace Lucene.Net.Index
 		{
 			
 			internal Directory directory;
-			
-			public FindSegmentsFile(Directory directory)
+
+		    protected FindSegmentsFile(Directory directory)
 			{
 				this.directory = directory;
 			}
@@ -701,10 +705,11 @@ namespace Lucene.Net.Index
 							}
 							catch (System.Threading.ThreadInterruptedException ie)
 							{
-								// In 3.0 we will change this to throw
-								// InterruptedException instead
-								SupportClass.ThreadClass.Current().Interrupt();
-								throw new System.SystemException(ie.Message, ie);
+                                //// In 3.0 we will change this to throw
+                                //// InterruptedException instead
+                                //SupportClass.ThreadClass.Current().Interrupt();
+                                //throw new System.SystemException(ie.Message, ie);
+							    throw;
 							}
 						}
 						
@@ -718,17 +723,7 @@ namespace Lucene.Net.Index
 						
 						if (gen == - 1)
 						{
-							// Neither approach found a generation
-							System.String s;
-							if (files != null)
-							{
-								s = "";
-								for (int i = 0; i < files.Length; i++)
-									s += (" " + files[i]);
-							}
-							else
-								s = " null";
-							throw new System.IO.FileNotFoundException("no segments* file found in " + directory + ": files:" + s);
+							throw new System.IO.FileNotFoundException("no segments* file found in " + directory + ": files:" + string.Join(" ", files));
 						}
 					}
 					
@@ -850,7 +845,7 @@ namespace Lucene.Net.Index
 		public SegmentInfos Range(int first, int last)
 		{
 			SegmentInfos infos = new SegmentInfos();
-			infos.AddRange((System.Collections.IList) ((System.Collections.ArrayList) this).GetRange(first, last - first));
+			infos.AddRange(this.GetRange(first, last - first));
 			return infos;
 		}
 		
@@ -913,11 +908,10 @@ namespace Lucene.Net.Index
 		/// </summary>
         public System.Collections.Generic.ICollection<string> Files(Directory dir, bool includeSegmentsFile)
 		{
-            System.Collections.Generic.Dictionary<string, string> files = new System.Collections.Generic.Dictionary<string, string>();
+            System.Collections.Generic.HashSet<string> files = new System.Collections.Generic.HashSet<string>();
 			if (includeSegmentsFile)
 			{
-                string tmp = GetCurrentSegmentFileName();
-                files.Add(tmp, tmp);
+                files.Add(GetCurrentSegmentFileName());
 			}
 			int size = Count;
 			for (int i = 0; i < size; i++)
@@ -925,10 +919,10 @@ namespace Lucene.Net.Index
 				SegmentInfo info = Info(i);
 				if (info.dir == dir)
 				{
-					SupportClass.CollectionsHelper.AddAllIfNotContains(files, Info(i).Files());
+                    files.UnionWith(Info(i).Files());
 				}
 			}
-			return files.Keys;
+			return files;
 		}
 		
 		internal void  FinishCommit(Directory dir)
@@ -1043,7 +1037,7 @@ namespace Lucene.Net.Index
 		{
 			if (data == null)
 			{
-				userData = new System.Collections.Generic.Dictionary<string,string>();
+			    userData = new HashMap<string, string>();
 			}
 			else
 			{

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentMergeInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentMergeInfo.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentMergeInfo.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentMergeInfo.cs Tue Feb 28 22:43:08 2012
@@ -20,7 +20,7 @@ using System;
 namespace Lucene.Net.Index
 {
 	
-	sealed class SegmentMergeInfo
+	sealed class SegmentMergeInfo : IDisposable
 	{
 		internal Term term;
 		internal int base_Renamed;
@@ -30,6 +30,8 @@ namespace Lucene.Net.Index
 		internal int delCount;
 		private TermPositions postings; // use getPositions()
 		private int[] docMap; // use getDocMap()
+
+	    private bool isDisposed;
 		
 		internal SegmentMergeInfo(int b, TermEnum te, IndexReader r)
 		{
@@ -88,14 +90,19 @@ namespace Lucene.Net.Index
 				return false;
 			}
 		}
-		
-		internal void  Close()
-		{
-			termEnum.Close();
-			if (postings != null)
-			{
-				postings.Close();
-			}
-		}
+
+        public void Dispose()
+        {
+            if (isDisposed) return;
+
+            // Move to protected method if class becomes unsealed
+            termEnum.Close();
+            if (postings != null)
+            {
+                postings.Close();
+            }
+
+            isDisposed = true;
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentMergeQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentMergeQueue.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentMergeQueue.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentMergeQueue.cs Tue Feb 28 22:43:08 2012
@@ -16,34 +16,32 @@
  */
 
 using System;
-
-using PriorityQueue = Lucene.Net.Util.PriorityQueue;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Index
 {
 	
-	sealed class SegmentMergeQueue:PriorityQueue
+	sealed class SegmentMergeQueue : PriorityQueue<SegmentMergeInfo>, IDisposable
 	{
 		internal SegmentMergeQueue(int size)
 		{
 			Initialize(size);
 		}
-		
-		public override bool LessThan(System.Object a, System.Object b)
+
+        public override bool LessThan(SegmentMergeInfo stiA, SegmentMergeInfo stiB)
 		{
-			SegmentMergeInfo stiA = (SegmentMergeInfo) a;
-			SegmentMergeInfo stiB = (SegmentMergeInfo) b;
 			int comparison = stiA.term.CompareTo(stiB.term);
 			if (comparison == 0)
 				return stiA.base_Renamed < stiB.base_Renamed;
 			else
 				return comparison < 0;
 		}
-		
-		internal void  Close()
-		{
-			while (Top() != null)
-				((SegmentMergeInfo) Pop()).Close();
-		}
+
+	    public void Dispose()
+	    {
+            // Move to protected method if class becomes unsealed
+            while (Top() != null)
+                Pop().Dispose();
+	    }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentMerger.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentMerger.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentMerger.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentMerger.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
  */
 
 using System;
-
+using System.Collections.Generic;
 using Document = Lucene.Net.Documents.Document;
 using FieldSelector = Lucene.Net.Documents.FieldSelector;
 using FieldSelectorResult = Lucene.Net.Documents.FieldSelectorResult;
@@ -91,31 +91,7 @@ namespace Lucene.Net.Index
 				// do nothing
 			}
 		}
-		[Serializable]
-		private class AnonymousClassFieldSelector : FieldSelector
-		{
-			public AnonymousClassFieldSelector(SegmentMerger enclosingInstance)
-			{
-				InitBlock(enclosingInstance);
-			}
-			private void  InitBlock(SegmentMerger enclosingInstance)
-			{
-				this.enclosingInstance = enclosingInstance;
-			}
-			private SegmentMerger enclosingInstance;
-			public SegmentMerger Enclosing_Instance
-			{
-				get
-				{
-					return enclosingInstance;
-				}
-				
-			}
-			public FieldSelectorResult Accept(System.String fieldName)
-			{
-				return FieldSelectorResult.LOAD_FOR_MERGE;
-			}
-		}
+
 		private void  InitBlock()
 		{
 			termIndexInterval = IndexWriter.DEFAULT_TERM_INDEX_INTERVAL;
@@ -128,7 +104,7 @@ namespace Lucene.Net.Index
 		private System.String segment;
 		private int termIndexInterval;
 		
-		private System.Collections.IList readers = new System.Collections.ArrayList();
+		private IList<IndexReader> readers = new List<IndexReader>();
 		private FieldInfos fieldInfos;
 		
 		private int mergedDocs;
@@ -197,7 +173,7 @@ namespace Lucene.Net.Index
 		/// </returns>
 		internal IndexReader SegmentReader(int i)
 		{
-			return (IndexReader) readers[i];
+			return readers[i];
 		}
 		
 		/// <summary> Merges the readers specified by the <see cref="Add" /> method into the directory passed to the constructor</summary>
@@ -246,17 +222,17 @@ namespace Lucene.Net.Index
 		/// Should not be called before merge().
 		/// </summary>
 		/// <throws>  IOException </throws>
-		public /*internal*/ void  CloseReaders()
+		internal void  CloseReaders()
 		{
-			for (System.Collections.IEnumerator iter = readers.GetEnumerator(); iter.MoveNext(); )
+			foreach(IndexReader reader in readers)
 			{
-				((IndexReader) iter.Current).Close();
+				reader.Dispose();
 			}
 		}
 
-        public /*internal*/ System.Collections.Generic.ICollection<string> GetMergedFiles()
+        public /*internal*/ ICollection<string> GetMergedFiles()
 		{
-            System.Collections.Generic.IDictionary<string,string> fileSet = new System.Collections.Generic.Dictionary<string,string>();
+            ISet<string> fileSet = new HashSet<string>();
 			
 			// Basic files
 			for (int i = 0; i < IndexFileNames.COMPOUND_EXTENSIONS.Length; i++)
@@ -267,7 +243,7 @@ namespace Lucene.Net.Index
 					continue;
 				
 				if (mergeDocStores || (!ext.Equals(IndexFileNames.FIELDS_EXTENSION) && !ext.Equals(IndexFileNames.FIELDS_INDEX_EXTENSION)))
-                    fileSet[segment + "." + ext] = segment + "." + ext;
+                    fileSet.Add(segment + "." + ext);
 			}
 			
 			// Fieldable norm files
@@ -276,7 +252,7 @@ namespace Lucene.Net.Index
 				FieldInfo fi = fieldInfos.FieldInfo(i);
 				if (fi.isIndexed && !fi.omitNorms)
 				{
-                    fileSet[segment + "." + IndexFileNames.NORMS_EXTENSION]=segment + "." + IndexFileNames.NORMS_EXTENSION;
+                    fileSet.Add(segment + "." + IndexFileNames.NORMS_EXTENSION);
 					break;
 				}
 			}
@@ -286,23 +262,22 @@ namespace Lucene.Net.Index
 			{
 				for (int i = 0; i < IndexFileNames.VECTOR_EXTENSIONS.Length; i++)
 				{
-                    fileSet[segment + "." + IndexFileNames.VECTOR_EXTENSIONS[i]] = segment + "." + IndexFileNames.VECTOR_EXTENSIONS[i];
+                    fileSet.Add(segment + "." + IndexFileNames.VECTOR_EXTENSIONS[i]);
 				}
 			}
 
-            return fileSet.Keys;
+            return fileSet;
         }
 
-        public /*internal*/ System.Collections.Generic.ICollection<string> CreateCompoundFile(System.String fileName)
+        public /*internal*/ ICollection<string> CreateCompoundFile(System.String fileName)
         {
-            System.Collections.Generic.ICollection<string> files = GetMergedFiles();
+            ICollection<string> files = GetMergedFiles();
             CompoundFileWriter cfsWriter = new CompoundFileWriter(directory, fileName, checkAbort);
 
 			// Now merge all added files
-			System.Collections.IEnumerator it = files.GetEnumerator();
-			while (it.MoveNext())
+			foreach(var file in files)
 			{
-				cfsWriter.AddFile((System.String) it.Current);
+				cfsWriter.AddFile(file);
 			}
 			
 			// Perform the merge
@@ -311,17 +286,16 @@ namespace Lucene.Net.Index
             return files;
 		}
 
-        private void AddIndexed(IndexReader reader, FieldInfos fInfos, System.Collections.Generic.ICollection<string> names, bool storeTermVectors, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool storePayloads, bool omitTFAndPositions)
-		{
-			System.Collections.Generic.IEnumerator<string> i = names.GetEnumerator();
-			while (i.MoveNext())
-			{
-                System.String field = i.Current;
-				fInfos.Add(field, true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector, !reader.HasNorms(field), storePayloads, omitTFAndPositions);
-			}
-		}
-		
-		private SegmentReader[] matchingSegmentReaders;
+        private void AddIndexed(IndexReader reader, FieldInfos fInfos, ICollection<string> names, bool storeTermVectors, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool storePayloads, bool omitTFAndPositions)
+        {
+            foreach (var field in names)
+            {
+                fInfos.Add(field, true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector,
+                           !reader.HasNorms(field), storePayloads, omitTFAndPositions);
+            }
+        }
+
+	    private SegmentReader[] matchingSegmentReaders;
 		private int[] rawDocLengths;
 		private int[] rawDocLengths2;
 		
@@ -339,7 +313,7 @@ namespace Lucene.Net.Index
 			// stored fields:
 			for (int i = 0; i < numReaders; i++)
 			{
-				IndexReader reader = (IndexReader) readers[i];
+				IndexReader reader = readers[i];
 				if (reader is SegmentReader)
 				{
 					SegmentReader segmentReader = (SegmentReader) reader;
@@ -372,9 +346,7 @@ namespace Lucene.Net.Index
 			
 			if (!mergeDocStores)
 			{
-				// When we are not merging by doc stores, that means
-				// all segments were written as part of a single
-				// autoCommit=false IndexWriter session, so their field
+				// When we are not merging by doc stores, their field
 				// name -> number mapping are the same.  So, we start
 				// with the fieldInfos of the last segment in this
 				// case, to keep that numbering.
@@ -386,9 +358,8 @@ namespace Lucene.Net.Index
 				fieldInfos = new FieldInfos(); // merge field names
 			}
 			
-			for (System.Collections.IEnumerator iter = readers.GetEnumerator(); iter.MoveNext(); )
+			foreach(IndexReader reader in readers)
 			{
-				IndexReader reader = (IndexReader) iter.Current;
 				if (reader is SegmentReader)
 				{
 					SegmentReader segmentReader = (SegmentReader) reader;
@@ -420,20 +391,14 @@ namespace Lucene.Net.Index
 			
 			if (mergeDocStores)
 			{
-				
-				// for merging we don't want to compress/uncompress the data, so to tell the FieldsReader that we're
-				// in  merge mode, we use this FieldSelector
-				FieldSelector fieldSelectorMerge = new AnonymousClassFieldSelector(this);
-				
 				// merge field values
 				FieldsWriter fieldsWriter = new FieldsWriter(directory, segment, fieldInfos);
 				
 				try
 				{
 					int idx = 0;
-					for (System.Collections.IEnumerator iter = readers.GetEnumerator(); iter.MoveNext(); )
+					foreach(IndexReader reader in readers)
 					{
-						IndexReader reader = (IndexReader) iter.Current;
 						SegmentReader matchingSegmentReader = matchingSegmentReaders[idx++];
 						FieldsReader matchingFieldsReader = null;
 						if (matchingSegmentReader != null)
@@ -446,17 +411,17 @@ namespace Lucene.Net.Index
 						}
 						if (reader.HasDeletions())
 						{
-							docCount += CopyFieldsWithDeletions(fieldSelectorMerge, fieldsWriter, reader, matchingFieldsReader);
+							docCount += CopyFieldsWithDeletions(fieldsWriter, reader, matchingFieldsReader);
 						}
 						else
 						{
-							docCount += CopyFieldsNoDeletions(fieldSelectorMerge, fieldsWriter, reader, matchingFieldsReader);
+							docCount += CopyFieldsNoDeletions(fieldsWriter, reader, matchingFieldsReader);
 						}
 					}
 				}
 				finally
 				{
-					fieldsWriter.Close();
+					fieldsWriter.Dispose();
 				}
 				
 				System.String fileName = segment + "." + IndexFileNames.FIELDS_INDEX_EXTENSION;
@@ -475,16 +440,16 @@ namespace Lucene.Net.Index
 			// just sum numDocs() of each segment to get total docCount
 			else
 			{
-				for (System.Collections.IEnumerator iter = readers.GetEnumerator(); iter.MoveNext(); )
+				foreach(IndexReader reader in readers)
 				{
-					docCount += ((IndexReader) iter.Current).NumDocs();
+					docCount += reader.NumDocs();
 				}
 			}
 			
 			return docCount;
 		}
 		
-		private int CopyFieldsWithDeletions(FieldSelector fieldSelectorMerge, FieldsWriter fieldsWriter, IndexReader reader, FieldsReader matchingFieldsReader)
+		private int CopyFieldsWithDeletions(FieldsWriter fieldsWriter, IndexReader reader, FieldsReader matchingFieldsReader)
 		{
 			int docCount = 0;
 			int maxDoc = reader.MaxDoc();
@@ -533,7 +498,7 @@ namespace Lucene.Net.Index
 					}
 					// NOTE: it's very important to first assign to doc then pass it to
 					// termVectorsWriter.addAllDocVectors; see LUCENE-1282
-					Document doc = reader.Document(j, fieldSelectorMerge);
+					Document doc = reader.Document(j);
 					fieldsWriter.AddDocument(doc);
 					docCount++;
 					checkAbort.Work(300);
@@ -542,7 +507,7 @@ namespace Lucene.Net.Index
 			return docCount;
 		}
 		
-		private int CopyFieldsNoDeletions(FieldSelector fieldSelectorMerge, FieldsWriter fieldsWriter, IndexReader reader, FieldsReader matchingFieldsReader)
+		private int CopyFieldsNoDeletions(FieldsWriter fieldsWriter, IndexReader reader, FieldsReader matchingFieldsReader)
 		{
 			int maxDoc = reader.MaxDoc();
 			int docCount = 0;
@@ -564,7 +529,7 @@ namespace Lucene.Net.Index
 				{
 					// NOTE: it's very important to first assign to doc then pass it to
 					// termVectorsWriter.addAllDocVectors; see LUCENE-1282
-					Document doc = reader.Document(docCount, fieldSelectorMerge);
+					Document doc = reader.Document(docCount);
 					fieldsWriter.AddDocument(doc);
 					checkAbort.Work(300);
 				}
@@ -581,7 +546,7 @@ namespace Lucene.Net.Index
 			try
 			{
 				int idx = 0;
-				for (System.Collections.IEnumerator iter = readers.GetEnumerator(); iter.MoveNext(); )
+				foreach(IndexReader reader in readers)
 				{
 					SegmentReader matchingSegmentReader = matchingSegmentReaders[idx++];
 					TermVectorsReader matchingVectorsReader = null;
@@ -595,7 +560,6 @@ namespace Lucene.Net.Index
 							matchingVectorsReader = vectorsReader;
 						}
 					}
-					IndexReader reader = (IndexReader) iter.Current;
 					if (reader.HasDeletions())
 					{
 						CopyVectorsWithDeletions(termVectorsWriter, matchingVectorsReader, reader);
@@ -608,7 +572,7 @@ namespace Lucene.Net.Index
 			}
 			finally
 			{
-				termVectorsWriter.Close();
+				termVectorsWriter.Dispose();
 			}
 			
 			System.String fileName = segment + "." + IndexFileNames.VECTORS_INDEX_EXTENSION;
@@ -726,7 +690,7 @@ namespace Lucene.Net.Index
 			{
 				consumer.Finish();
 				if (queue != null)
-					queue.Close();
+					queue.Dispose();
 			}
 		}
 		
@@ -738,7 +702,7 @@ namespace Lucene.Net.Index
 			int readerCount = readers.Count;
 			for (int i = 0; i < readerCount; i++)
 			{
-				IndexReader reader = (IndexReader) readers[i];
+				IndexReader reader = readers[i];
 				TermEnum termEnum = reader.Terms();
 				SegmentMergeInfo smi = new SegmentMergeInfo(base_Renamed, termEnum, reader);
 				int[] docMap = smi.GetDocMap();
@@ -761,7 +725,7 @@ namespace Lucene.Net.Index
 					queue.Add(smi);
 				// initialize queue
 				else
-					smi.Close();
+					smi.Dispose();
 			}
 			
 			SegmentMergeInfo[] match = new SegmentMergeInfo[readers.Count];
@@ -772,14 +736,14 @@ namespace Lucene.Net.Index
 			while (queue.Size() > 0)
 			{
 				int matchSize = 0; // pop matching terms
-				match[matchSize++] = (SegmentMergeInfo) queue.Pop();
+				match[matchSize++] = queue.Pop();
 				Term term = match[0].term;
-				SegmentMergeInfo top = (SegmentMergeInfo) queue.Top();
+				SegmentMergeInfo top = queue.Top();
 				
 				while (top != null && term.CompareTo(top.term) == 0)
 				{
-					match[matchSize++] = (SegmentMergeInfo) queue.Pop();
-					top = (SegmentMergeInfo) queue.Top();
+					match[matchSize++] = queue.Pop();
+					top = queue.Top();
 				}
 				
 				if ((System.Object) currentField != (System.Object) term.field)
@@ -803,7 +767,7 @@ namespace Lucene.Net.Index
 						queue.Add(smi);
 					// restore queue
 					else
-						smi.Close(); // done with a segment
+						smi.Dispose(); // done with a segment
 				}
 			}
 		}
@@ -898,9 +862,8 @@ namespace Lucene.Net.Index
 							output = directory.CreateOutput(segment + "." + IndexFileNames.NORMS_EXTENSION);
 							output.WriteBytes(NORMS_HEADER, NORMS_HEADER.Length);
 						}
-						for (System.Collections.IEnumerator iter = readers.GetEnumerator(); iter.MoveNext(); )
+						foreach(IndexReader reader in readers)
 						{
-							IndexReader reader = (IndexReader) iter.Current;
 							int maxDoc = reader.MaxDoc();
 							if (normBuffer == null || normBuffer.Length < maxDoc)
 							{

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentReader.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentReader.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,8 @@
  */
 
 using System;
-
+using Lucene.Net.Support;
+using Lucene.Net.Util;
 using Document = Lucene.Net.Documents.Document;
 using FieldSelector = Lucene.Net.Documents.FieldSelector;
 using BufferedIndexInput = Lucene.Net.Store.BufferedIndexInput;
@@ -24,7 +25,6 @@ using Directory = Lucene.Net.Store.Direc
 using IndexInput = Lucene.Net.Store.IndexInput;
 using IndexOutput = Lucene.Net.Store.IndexOutput;
 using BitVector = Lucene.Net.Util.BitVector;
-using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
 using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
 
 namespace Lucene.Net.Index
@@ -35,7 +35,7 @@ namespace Lucene.Net.Index
 	/// <summary> <p/><b>NOTE:</b> This API is new and still experimental
 	/// (subject to change suddenly in the next release)<p/>
 	/// </summary>
-	public class SegmentReader:IndexReader, System.ICloneable
+	public class SegmentReader : IndexReader, System.ICloneable
 	{
 		public SegmentReader()
 		{
@@ -50,8 +50,8 @@ namespace Lucene.Net.Index
 		private SegmentInfo si;
 		private int readBufferSize;
 		
-		internal CloseableThreadLocal fieldsReaderLocal;
-		internal CloseableThreadLocal termVectorsLocal = new CloseableThreadLocal();
+		internal CloseableThreadLocal<FieldsReader> fieldsReaderLocal;
+        internal CloseableThreadLocal<TermVectorsReader> termVectorsLocal = new CloseableThreadLocal<TermVectorsReader>();
 		
 		internal BitVector deletedDocs = null;
 		internal Ref deletedDocsRef = null;
@@ -265,14 +265,14 @@ namespace Lucene.Net.Index
 						// close everything, nothing is shared anymore with other readers
 						if (tis != null)
 						{
-							tis.Close();
+							tis.Dispose();
 							// null so if an app hangs on to us we still free most ram
 							tis = null;
 						}
 						
 						if (tisNoIndex != null)
 						{
-							tisNoIndex.Close();
+							tisNoIndex.Dispose();
 						}
 						
 						if (freqStream != null)
@@ -287,12 +287,12 @@ namespace Lucene.Net.Index
 						
 						if (termVectorsReaderOrig != null)
 						{
-							termVectorsReaderOrig.Close();
+							termVectorsReaderOrig.Dispose();
 						}
 						
 						if (fieldsReaderOrig != null)
 						{
-							fieldsReaderOrig.Close();
+                            fieldsReaderOrig.Dispose();
 						}
 						
 						if (cfsReader != null)
@@ -391,7 +391,7 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary> Sets the initial value </summary>
-		private class FieldsReaderLocal:CloseableThreadLocal
+		private class FieldsReaderLocal : CloseableThreadLocal<FieldsReader>
 		{
 			public FieldsReaderLocal(SegmentReader enclosingInstance)
 			{
@@ -410,9 +410,9 @@ namespace Lucene.Net.Index
 				}
 				
 			}
-			public /*protected internal*/ override System.Object InitialValue()
+			public /*protected internal*/ override FieldsReader InitialValue()
 			{
-				return Enclosing_Instance.core.GetFieldsReaderOrig().Clone();
+				return (FieldsReader) Enclosing_Instance.core.GetFieldsReaderOrig().Clone();
 			}
 		}
 		
@@ -517,7 +517,7 @@ namespace Lucene.Net.Index
 					if (in_Renamed != Enclosing_Instance.singleNormStream)
 					{
 						// It's private to us -- just close it
-						in_Renamed.Close();
+						in_Renamed.Dispose();
 					}
 					else
 					{
@@ -525,7 +525,7 @@ namespace Lucene.Net.Index
 						// maybe close the shared norm stream
 						if (Enclosing_Instance.singleNormRef.DecRef() == 0)
 						{
-							Enclosing_Instance.singleNormStream.Close();
+							Enclosing_Instance.singleNormStream.Dispose();
 							Enclosing_Instance.singleNormStream = null;
 						}
 					}
@@ -768,24 +768,7 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		internal System.Collections.IDictionary norms = new System.Collections.Hashtable();
-		
-		/// <summary>The class which implements SegmentReader. </summary>
-		// @deprecated (LUCENE-1677)
-		private static System.Type IMPL;
-		
-		// @deprecated (LUCENE-1677)
-		private static System.Type READONLY_IMPL;
-		
-		/// <throws>  CorruptIndexException if the index is corrupt </throws>
-		/// <throws>  IOException if there is a low-level IO error </throws>
-		/// <deprecated>
-		/// </deprecated>
-        [Obsolete]
-		public static SegmentReader Get(SegmentInfo si)
-		{
-			return Get(false, si.dir, si, BufferedIndexInput.BUFFER_SIZE, true, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR);
-		}
+		internal System.Collections.Generic.IDictionary<string, Norm> norms = new HashMap<string, Norm>();
 		
 		/// <throws>  CorruptIndexException if the index is corrupt </throws>
 		/// <throws>  IOException if there is a low-level IO error </throws>
@@ -796,30 +779,9 @@ namespace Lucene.Net.Index
 		
 		/// <throws>  CorruptIndexException if the index is corrupt </throws>
 		/// <throws>  IOException if there is a low-level IO error </throws>
-		/// <deprecated>
-		/// </deprecated>
-        [Obsolete]
-		internal static SegmentReader Get(SegmentInfo si, int readBufferSize, bool doOpenStores, int termInfosIndexDivisor)
-		{
-			return Get(false, si.dir, si, readBufferSize, doOpenStores, termInfosIndexDivisor);
-		}
-		
-		/// <throws>  CorruptIndexException if the index is corrupt </throws>
-		/// <throws>  IOException if there is a low-level IO error </throws>
 		public static SegmentReader Get(bool readOnly, Directory dir, SegmentInfo si, int readBufferSize, bool doOpenStores, int termInfosIndexDivisor)
 		{
-			SegmentReader instance;
-			try
-			{
-				if (readOnly)
-					instance = (SegmentReader) System.Activator.CreateInstance(READONLY_IMPL);
-				else
-					instance = (SegmentReader) System.Activator.CreateInstance(IMPL);
-			}
-			catch (System.Exception e)
-			{
-				throw new System.SystemException("cannot load SegmentReader class: " + e, e);
-			}
+			SegmentReader instance = readOnly ? new ReadOnlySegmentReader() : new SegmentReader();
 			instance.readOnly = readOnly;
 			instance.si = si;
 			instance.readBufferSize = readBufferSize;
@@ -962,18 +924,7 @@ namespace Lucene.Net.Index
 				System.Diagnostics.Debug.Assert(!doClone ||(normsUpToDate && deletionsUpToDate));
 				
 				// clone reader
-				SegmentReader clone;
-				try
-				{
-					if (openReadOnly)
-						clone = (SegmentReader) System.Activator.CreateInstance(READONLY_IMPL);
-					else
-						clone = (SegmentReader) System.Activator.CreateInstance(IMPL);
-				}
-				catch (System.Exception e)
-				{
-					throw new System.SystemException("cannot load SegmentReader class: " + e, e);
-				}
+				SegmentReader clone = openReadOnly ? new ReadOnlySegmentReader() : new SegmentReader();
 				
 				bool success = false;
 				try
@@ -1019,8 +970,7 @@ namespace Lucene.Net.Index
 						}
 					}
 					
-					clone.SetDisableFakeNorms(GetDisableFakeNorms());
-					clone.norms = new System.Collections.Hashtable();
+					clone.norms = new HashMap<string, Norm>();
 					
 					// Clone norms
 					for (int i = 0; i < fieldNormsChanged.Length; i++)
@@ -1030,9 +980,9 @@ namespace Lucene.Net.Index
 						if (doClone || !fieldNormsChanged[i])
 						{
 							System.String curField = core.fieldInfos.FieldInfo(i).name;
-							Norm norm = (Norm) this.norms[curField];
+							Norm norm = this.norms[curField];
 							if (norm != null)
-								clone.norms[curField] = norm.Clone();
+								clone.norms[curField] = (Norm)norm.Clone();
 						}
 					}
 					
@@ -1055,14 +1005,6 @@ namespace Lucene.Net.Index
 				return clone;
 			}
 		}
-		
-		/// <deprecated>  
-		/// </deprecated>
-        [Obsolete]
-		protected internal override void  DoCommit()
-		{
-			DoCommit(null);
-		}
 
         protected internal override void DoCommit(System.Collections.Generic.IDictionary<string, string> commitUserData)
         {
@@ -1129,17 +1071,14 @@ namespace Lucene.Net.Index
             if (normsDirty)
             {               // re-write norms
                 si.SetNumFields(core.fieldInfos.Size());
-                System.Collections.IEnumerator it = norms.Values.GetEnumerator();
-                while (it.MoveNext())
+                foreach (Norm norm in norms.Values)
                 {
-                    Norm norm = (Norm)it.Current;
                     if (norm.dirty)
                     {
                         norm.ReWrite(si);
                     }
                 }
             }
-
             deletedDocsDirty = false;
             normsDirty = false;
             hasChanges = false;
@@ -1147,7 +1086,7 @@ namespace Lucene.Net.Index
         
 		internal virtual FieldsReader GetFieldsReader()
 		{
-			return (FieldsReader) fieldsReaderLocal.Get();
+			return fieldsReaderLocal.Get();
 		}
 		
 		protected internal override void  DoClose()
@@ -1162,10 +1101,9 @@ namespace Lucene.Net.Index
 				deletedDocs = null;
 			}
 			
-			System.Collections.IEnumerator it = norms.Values.GetEnumerator();
-			while (it.MoveNext())
+			foreach(Norm norm in norms.Values)
 			{
-				((Norm) it.Current).DecRef();
+				norm.DecRef();
 			}
 			if (core != null)
 			{
@@ -1328,56 +1266,56 @@ namespace Lucene.Net.Index
 		{
 			EnsureOpen();
 
-            System.Collections.Generic.IDictionary<string, string> fieldSet = new System.Collections.Generic.Dictionary<string, string>();
+            System.Collections.Generic.ISet<string> fieldSet = new System.Collections.Generic.HashSet<string>();
 			for (int i = 0; i < core.fieldInfos.Size(); i++)
 			{
 				FieldInfo fi = core.fieldInfos.FieldInfo(i);
 				if (fieldOption == IndexReader.FieldOption.ALL)
 				{
-					fieldSet[fi.name] = fi.name;
+					fieldSet.Add(fi.name);
 				}
 				else if (!fi.isIndexed && fieldOption == IndexReader.FieldOption.UNINDEXED)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.omitTermFreqAndPositions && fieldOption == IndexReader.FieldOption.OMIT_TERM_FREQ_AND_POSITIONS)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.storePayloads && fieldOption == IndexReader.FieldOption.STORES_PAYLOADS)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.isIndexed && fieldOption == IndexReader.FieldOption.INDEXED)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.isIndexed && fi.storeTermVector == false && fieldOption == IndexReader.FieldOption.INDEXED_NO_TERMVECTOR)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.storeTermVector == true && fi.storePositionWithTermVector == false && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.isIndexed && fi.storeTermVector && fieldOption == IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.storePositionWithTermVector && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
 				else if (fi.storeOffsetWithTermVector && fi.storePositionWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET)
-				{
-					fieldSet[fi.name] = fi.name;
-				}
-				else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET)
-				{
-					fieldSet[fi.name] = fi.name;
+                {
+                    fieldSet.Add(fi.name);
 				}
+                else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET)
+                {
+                    fieldSet.Add(fi.name);
+                }
 			}
-			return fieldSet.Keys;
+			return fieldSet;
 		}
 		
 		
@@ -1386,36 +1324,16 @@ namespace Lucene.Net.Index
 			lock (this)
 			{
 				EnsureOpen();
-				return norms.Contains(field);
+				return norms.ContainsKey(field);
 			}
 		}
 		
-		internal static byte[] CreateFakeNorms(int size)
-		{
-			byte[] ones = new byte[size];
-			byte val = (byte) DefaultSimilarity.EncodeNorm(1.0f);
-            for (int i = 0; i < ones.Length; i++)
-            {
-                ones[i] = val;
-            }
-			return ones;
-		}
-		
-		private byte[] ones;
-		private byte[] FakeNorms()
-		{
-			System.Diagnostics.Debug.Assert(!GetDisableFakeNorms());
-			if (ones == null)
-				ones = CreateFakeNorms(MaxDoc());
-			return ones;
-		}
-		
 		// can return null if norms aren't stored
 		protected internal virtual byte[] GetNorms(System.String field)
 		{
 			lock (this)
 			{
-				Norm norm = (Norm) norms[field];
+				Norm norm = norms[field];
 				if (norm == null)
 					return null; // not indexed, or norms not stored
 				return norm.Bytes();
@@ -1429,15 +1347,13 @@ namespace Lucene.Net.Index
 			{
 				EnsureOpen();
 				byte[] bytes = GetNorms(field);
-				if (bytes == null && !GetDisableFakeNorms())
-					bytes = FakeNorms();
 				return bytes;
 			}
 		}
 		
 		protected internal override void  DoSetNorm(int doc, System.String field, byte value_Renamed)
 		{
-			Norm norm = (Norm) norms[field];
+			Norm norm = norms[field];
 			if (norm == null)
 			// not an indexed field
 				return ;
@@ -1447,13 +1363,13 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary>Read norms into a pre-allocated array. </summary>
-		public override void  Norms(System.String field, byte[] bytes, int offset)
+		public override void Norms(System.String field, byte[] bytes, int offset)
 		{
 			lock (this)
 			{
 				
 				EnsureOpen();
-				Norm norm = (Norm) norms[field];
+				Norm norm = norms[field];
 				if (norm == null)
 				{
                     for (int i = offset; i < bytes.Length; i++)
@@ -1475,7 +1391,7 @@ namespace Lucene.Net.Index
 			for (int i = 0; i < core.fieldInfos.Size(); i++)
 			{
 				FieldInfo fi = core.fieldInfos.FieldInfo(i);
-				if (norms.Contains(fi.name))
+				if (norms.ContainsKey(fi.name))
 				{
 					// in case this SegmentReader is being re-opened, we might be able to
 					// reuse some norm instances and skip loading them here
@@ -1546,10 +1462,8 @@ namespace Lucene.Net.Index
 			{
 				return false;
 			}
-			System.Collections.IEnumerator it = norms.Values.GetEnumerator();
-			while (it.MoveNext())
+			foreach(Norm norm in norms.Values)
 			{
-				Norm norm = (Norm) it.Current;
 				if (norm.refCount > 0)
 				{
 					return false;
@@ -1561,8 +1475,7 @@ namespace Lucene.Net.Index
 		// for testing only
 		public /*internal*/ virtual bool NormsClosed(System.String field)
 		{
-			Norm norm = (Norm) norms[field];
-			return norm.refCount == 0;
+			return norms[field].refCount == 0;
 		}
 		
 		/// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
@@ -1570,7 +1483,7 @@ namespace Lucene.Net.Index
 		/// </returns>
 		internal virtual TermVectorsReader GetTermVectorsReader()
 		{
-			TermVectorsReader tvReader = (TermVectorsReader) termVectorsLocal.Get();
+			TermVectorsReader tvReader = termVectorsLocal.Get();
 			if (tvReader == null)
 			{
 				TermVectorsReader orig = core.GetTermVectorsReaderOrig();
@@ -1626,15 +1539,13 @@ namespace Lucene.Net.Index
 			EnsureOpen();
 			FieldInfo fi = core.fieldInfos.FieldInfo(field);
 			if (fi == null || !fi.storeTermVector)
-				return ;
+				return;
 			
 			TermVectorsReader termVectorsReader = GetTermVectorsReader();
 			if (termVectorsReader == null)
 			{
-				return ;
+				return;
 			}
-			
-			
 			termVectorsReader.Get(docNumber, field, mapper);
 		}
 		
@@ -1692,10 +1603,8 @@ namespace Lucene.Net.Index
 			rollbackDeletedDocsDirty = deletedDocsDirty;
 			rollbackNormsDirty = normsDirty;
 			rollbackPendingDeleteCount = pendingDeleteCount;
-			System.Collections.IEnumerator it = norms.Values.GetEnumerator();
-			while (it.MoveNext())
-			{
-				Norm norm = (Norm) it.Current;
+			foreach(Norm norm in norms.Values)
+            {
 				norm.rollbackDirty = norm.dirty;
 			}
 		}
@@ -1707,10 +1616,8 @@ namespace Lucene.Net.Index
 			deletedDocsDirty = rollbackDeletedDocsDirty;
 			normsDirty = rollbackNormsDirty;
 			pendingDeleteCount = rollbackPendingDeleteCount;
-			System.Collections.IEnumerator it = norms.Values.GetEnumerator();
-			while (it.MoveNext())
-			{
-				Norm norm = (Norm) it.Current;
+			foreach(Norm norm in norms.Values)
+            {
 				norm.dirty = norm.rollbackDirty;
 			}
 		}
@@ -1727,7 +1634,6 @@ namespace Lucene.Net.Index
 		// This is necessary so that cloned SegmentReaders (which
 		// share the underlying postings data) will map to the
 		// same entry in the FieldCache.  See LUCENE-1579.
-        [Obsolete("Lucene.Net-2.9.1. This method overrides obsolete member Lucene.Net.Index.IndexReader.GetFieldCacheKey()")]
 		public override System.Object GetFieldCacheKey()
 		{
 			return core.freqStream;
@@ -1747,10 +1653,12 @@ namespace Lucene.Net.Index
 		/// <summary> Lotsa tests did hacks like:<br/>
 		/// SegmentReader reader = (SegmentReader) IndexReader.open(dir);<br/>
 		/// They broke. This method serves as a hack to keep hacks working
+		/// We do it with R/W access for the tests (BW compatibility)
 		/// </summary>
+		[Obsolete("Remove this when tests are fixed!")]
 		public /*internal*/ static SegmentReader GetOnlySegmentReader(Directory dir)
 		{
-			return GetOnlySegmentReader(IndexReader.Open(dir));
+			return GetOnlySegmentReader(IndexReader.Open(dir,false));
 		}
 		
 		public /*internal*/ static SegmentReader GetOnlySegmentReader(IndexReader reader)
@@ -1776,55 +1684,8 @@ namespace Lucene.Net.Index
 		{
 			return core.termsIndexDivisor;
 		}
-		static SegmentReader()
-		{
-			{
-				try
-				{
-					System.String name = SupportClass.AppSettings.Get("Lucene.Net.SegmentReader.class", typeof(SegmentReader).FullName);
-					IMPL = System.Type.GetType(name);
-				}
-				catch (System.Security.SecurityException se)
-				{
-					try
-					{
-						IMPL = System.Type.GetType(typeof(SegmentReader).FullName);
-					}
-					catch (System.Exception e)
-					{
-						throw new System.SystemException("cannot load default SegmentReader class: " + e, e);
-					}
-				}
-				catch (System.Exception e)
-				{
-					throw new System.SystemException("cannot load SegmentReader class: " + e, e);
-				}
-			}
-			{
-				try
-				{
-					System.String name = SupportClass.AppSettings.Get("Lucene.Net.ReadOnlySegmentReader.class", typeof(ReadOnlySegmentReader).FullName);
-					READONLY_IMPL = System.Type.GetType(name);
-				}
-				catch (System.Security.SecurityException se)
-				{
-					try
-					{
-						READONLY_IMPL = System.Type.GetType(typeof(ReadOnlySegmentReader).FullName);
-					}
-					catch (System.Exception e)
-					{
-						throw new System.SystemException("cannot load default ReadOnlySegmentReader class: " + e, e);
-					}
-				}
-				catch (System.Exception e)
-				{
-					throw new System.SystemException("cannot load ReadOnlySegmentReader class: " + e, e);
-				}
-			}
-		}
-
-        public System.Collections.IDictionary norms_ForNUnit
+		
+        public System.Collections.Generic.IDictionary<string, Norm> norms_ForNUnit
         {
             get { return norms; }
         }

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs Tue Feb 28 22:43:08 2012
@@ -16,14 +16,14 @@
  */
 
 using System;
-
+using Lucene.Net.Support;
 using IndexInput = Lucene.Net.Store.IndexInput;
 using BitVector = Lucene.Net.Util.BitVector;
 
 namespace Lucene.Net.Index
 {
 	
-	public class SegmentTermDocs : TermDocs
+	internal class SegmentTermDocs : TermDocs
 	{
 		protected internal SegmentReader parent;
 		protected internal IndexInput freqStream;
@@ -45,6 +45,8 @@ namespace Lucene.Net.Index
 		
 		protected internal bool currentFieldStoresPayloads;
 		protected internal bool currentFieldOmitTermFreqAndPositions;
+
+	    private bool isDisposed;
 		
 		public /*protected internal*/ SegmentTermDocs(SegmentReader parent)
 		{
@@ -108,13 +110,28 @@ namespace Lucene.Net.Index
 				haveSkipped = false;
 			}
 		}
-		
-		public virtual void  Close()
-		{
-			freqStream.Close();
-			if (skipListReader != null)
-				skipListReader.Close();
-		}
+
+        public void Dispose()
+        {
+            Dispose(true);
+        }
+
+        [Obsolete("Use Dispose() instead")]
+        public void Close()
+        {
+            Dispose();
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (isDisposed) return;
+
+            freqStream.Dispose();
+            if (skipListReader != null)
+                skipListReader.Dispose();
+
+            isDisposed = true;
+        }
 		
 		public int Doc()
 		{
@@ -144,7 +161,7 @@ namespace Lucene.Net.Index
 				}
 				else
 				{
-					doc += SupportClass.Number.URShift(docCode, 1); // shift off low bit
+					doc += Number.URShift(docCode, 1); // shift off low bit
 					if ((docCode & 1) != 0)
 					// if low bit is set
 						freq = 1;
@@ -177,7 +194,7 @@ namespace Lucene.Net.Index
 				{
 					// manually inlined call to next() for speed
 					int docCode = freqStream.ReadVInt();
-					doc += SupportClass.Number.URShift(docCode, 1); // shift off low bit
+					doc += Number.URShift(docCode, 1); // shift off low bit
 					if ((docCode & 1) != 0)
 					// if low bit is set
 						freq = 1;
@@ -261,7 +278,7 @@ namespace Lucene.Net.Index
 			return true;
 		}
 
-        public IndexInput freqStream_ForNUnit
+	    public IndexInput freqStream_ForNUnit
         {
             get { return freqStream; }
             set { freqStream = value; }

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentTermEnum.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentTermEnum.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentTermEnum.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentTermEnum.cs Tue Feb 28 22:43:08 2012
@@ -21,8 +21,7 @@ using IndexInput = Lucene.Net.Store.Inde
 
 namespace Lucene.Net.Index
 {
-	
-	public sealed class SegmentTermEnum:TermEnum, System.ICloneable
+	internal sealed class SegmentTermEnum : TermEnum, System.ICloneable
 	{
 		private IndexInput input;
 		internal FieldInfos fieldInfos;
@@ -242,9 +241,9 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary>Closes the enumeration to further activity, freeing resources. </summary>
-		public override void  Close()
-		{
-			input.Close();
-		}
+        protected override void Dispose(bool disposing)
+        {
+            input.Dispose();
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentTermPositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentTermPositions.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentTermPositions.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentTermPositions.cs Tue Feb 28 22:43:08 2012
@@ -16,13 +16,12 @@
  */
 
 using System;
-
+using Lucene.Net.Support;
 using IndexInput = Lucene.Net.Store.IndexInput;
 
 namespace Lucene.Net.Index
 {
-	
-	public sealed class SegmentTermPositions:SegmentTermDocs, TermPositions
+	internal sealed class SegmentTermPositions : SegmentTermDocs, TermPositions
 	{
 		private IndexInput proxStream;
 		private int proxCount;
@@ -56,12 +55,12 @@ namespace Lucene.Net.Index
 			needToLoadPayload = false;
 		}
 		
-		public override void  Close()
-		{
-			base.Close();
-			if (proxStream != null)
-				proxStream.Close();
-		}
+        protected override void Dispose(bool disposing)
+        {
+            base.Dispose(disposing);
+            if (proxStream != null)
+                proxStream.Dispose();
+        }
 		
 		public int NextPosition()
 		{
@@ -87,7 +86,7 @@ namespace Lucene.Net.Index
 				{
 					payloadLength = proxStream.ReadVInt();
 				}
-				delta = SupportClass.Number.URShift(delta, 1);
+				delta = Number.URShift(delta, 1);
 				needToLoadPayload = true;
 			}
 			return delta;

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentWriteState.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentWriteState.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentWriteState.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentWriteState.cs Tue Feb 28 22:43:08 2012
@@ -31,7 +31,7 @@ namespace Lucene.Net.Index
 		internal int numDocs;
 		internal int termIndexInterval;
 		internal int numDocsInStore;
-		internal System.Collections.Hashtable flushedFiles;
+		internal System.Collections.Generic.ICollection<string> flushedFiles;
 		
 		public SegmentWriteState(DocumentsWriter docWriter, Directory directory, System.String segmentName, System.String docStoreSegmentName, int numDocs, int numDocsInStore, int termIndexInterval)
 		{
@@ -42,7 +42,7 @@ namespace Lucene.Net.Index
 			this.numDocs = numDocs;
 			this.numDocsInStore = numDocsInStore;
 			this.termIndexInterval = termIndexInterval;
-            flushedFiles = new System.Collections.Hashtable();
+            flushedFiles = new System.Collections.Generic.HashSet<string>();
 		}
 		
 		public virtual System.String SegmentFileName(System.String ext)

Modified: incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs Tue Feb 28 22:43:08 2012
@@ -34,7 +34,6 @@ namespace Lucene.Net.Index
 		{
 			lock (this)
 			{
-				
 				while (true)
 				{
 					MergePolicy.OneMerge merge = writer.GetNextMerge();
@@ -44,9 +43,9 @@ namespace Lucene.Net.Index
 				}
 			}
 		}
-		
-		public override void  Close()
-		{
-		}
+
+	    protected override void Dispose(bool disposing)
+	    {
+	    }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/SnapshotDeletionPolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SnapshotDeletionPolicy.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SnapshotDeletionPolicy.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SnapshotDeletionPolicy.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
  */
 
 using System;
-
+using System.Collections.Generic;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Index
@@ -53,21 +53,21 @@ namespace Lucene.Net.Index
 			this.primary = primary;
 		}
 		
-		public virtual void  OnInit(System.Collections.IList commits)
+		public virtual void  OnInit<T>(IList<T> commits) where T : IndexCommit
 		{
 			lock (this)
 			{
 				primary.OnInit(WrapCommits(commits));
-				lastCommit = (IndexCommit) commits[commits.Count - 1];
+				lastCommit = commits[commits.Count - 1];
 			}
 		}
 		
-		public virtual void  OnCommit(System.Collections.IList commits)
+		public virtual void  OnCommit<T>(IList<T> commits) where T : IndexCommit
 		{
 			lock (this)
 			{
 				primary.OnCommit(WrapCommits(commits));
-				lastCommit = (IndexCommit) commits[commits.Count - 1];
+				lastCommit = commits[commits.Count - 1];
 			}
 		}
 		
@@ -81,8 +81,7 @@ namespace Lucene.Net.Index
 		/// consume an extra 1X of your total index size, until
 		/// you release the snapshot. 
 		/// </summary>
-		// TODO 3.0: change this to return IndexCommit instead
-		public virtual IndexCommitPoint Snapshot()
+		public virtual IndexCommit Snapshot()
 		{
 			lock (this)
 			{
@@ -90,6 +89,7 @@ namespace Lucene.Net.Index
                 {
                     throw new System.SystemException("no index commits to snapshot !");
                 }
+
 				if (snapshot == null)
 					snapshot = lastCommit.GetSegmentsFileName();
 				else
@@ -110,7 +110,7 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		private class MyCommitPoint:IndexCommit
+		private class MyCommitPoint : IndexCommit
 		{
 			private void  InitBlock(SnapshotDeletionPolicy enclosingInstance)
 			{
@@ -141,7 +141,7 @@ namespace Lucene.Net.Index
 			{
 				return cp.GetSegmentsFileName();
 			}
-            public override System.Collections.Generic.ICollection<string> GetFileNames()
+            public override ICollection<string> GetFileNames()
 			{
 				return cp.GetFileNames();
 			}
@@ -171,7 +171,7 @@ namespace Lucene.Net.Index
 			{
 				return cp.GetGeneration();
 			}
-            public override System.Collections.Generic.IDictionary<string, string> GetUserData()
+            public override IDictionary<string, string> GetUserData()
 			{
 				return cp.GetUserData();
 			}
@@ -182,13 +182,15 @@ namespace Lucene.Net.Index
             }
 		}
 		
-		private System.Collections.IList WrapCommits(System.Collections.IList commits)
+		private IList<IndexCommit> WrapCommits<T>(IList<T> commits) where T : IndexCommit
 		{
 			int count = commits.Count;
-			System.Collections.IList myCommits = new System.Collections.ArrayList(count);
-			for (int i = 0; i < count; i++)
-				myCommits.Add(new MyCommitPoint(this, (IndexCommit) commits[i]));
-			return myCommits;
+			var myCommits = new List<IndexCommit>(count);
+            for (int i = 0; i < count; i++)
+            {
+                myCommits.Add(new MyCommitPoint(this, commits[i]));
+            }
+		    return myCommits;
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/SortedTermVectorMapper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SortedTermVectorMapper.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SortedTermVectorMapper.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SortedTermVectorMapper.cs Tue Feb 28 22:43:08 2012
@@ -16,6 +16,8 @@
  */
 
 using System;
+using System.Collections.Generic;
+using Lucene.Net.Support;
 
 namespace Lucene.Net.Index
 {
@@ -30,10 +32,8 @@ namespace Lucene.Net.Index
 	/// </summary>
 	public class SortedTermVectorMapper:TermVectorMapper
 	{
-
-
-        private System.Collections.Generic.SortedDictionary<System.Object, System.Object> currentSet;
-		private System.Collections.IDictionary termToTVE = new System.Collections.Hashtable();
+        private SortedSet<TermVectorEntry> currentSet;
+		private IDictionary<string, TermVectorEntry> termToTVE = new HashMap<string, TermVectorEntry>();
 		private bool storeOffsets;
 		private bool storePositions;
 		/// <summary> Stand-in name for the field in <see cref="TermVectorEntry" />.</summary>
@@ -42,14 +42,16 @@ namespace Lucene.Net.Index
 		/// <summary> </summary>
 		/// <param name="comparator">A Comparator for sorting <see cref="TermVectorEntry" />s
 		/// </param>
-		public SortedTermVectorMapper(System.Collections.Generic.IComparer<System.Object> comparator):this(false, false, comparator)
+        public SortedTermVectorMapper(IComparer<TermVectorEntry> comparator)
+            : this(false, false, comparator)
 		{
 		}
-		
-		
-		public SortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, System.Collections.Generic.IComparer<System.Object> comparator):base(ignoringPositions, ignoringOffsets)
+
+
+        public SortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, IComparer<TermVectorEntry> comparator)
+            : base(ignoringPositions, ignoringOffsets)
 		{
-            currentSet = new System.Collections.Generic.SortedDictionary<System.Object, System.Object>(comparator);
+            currentSet = new SortedSet<TermVectorEntry>(comparator);
 		}
 		
 		/// <summary> </summary>
@@ -64,12 +66,12 @@ namespace Lucene.Net.Index
 		//We need to combine any previous mentions of the term
 		public override void  Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
 		{
-			TermVectorEntry entry = (TermVectorEntry) termToTVE[term];
+			TermVectorEntry entry = termToTVE[term];
 			if (entry == null)
 			{
 				entry = new TermVectorEntry(ALL, term, frequency, storeOffsets == true?offsets:null, storePositions == true?positions:null);
 				termToTVE[term] = entry;
-				currentSet.Add(entry, entry);
+				currentSet.Add(entry);
 			}
 			else
 			{
@@ -124,7 +126,7 @@ namespace Lucene.Net.Index
 		/// </summary>
 		/// <returns> The SortedSet of <see cref="TermVectorEntry" />.
 		/// </returns>
-        public virtual System.Collections.Generic.SortedDictionary<Object, Object> GetTermVectorEntrySet()
+        public virtual SortedSet<TermVectorEntry> GetTermVectorEntrySet()
 		{
 			return currentSet;
 		}

Modified: incubator/lucene.net/trunk/src/core/Index/StoredFieldsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/StoredFieldsWriter.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/StoredFieldsWriter.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/StoredFieldsWriter.cs Tue Feb 28 22:43:08 2012
@@ -102,12 +102,12 @@ namespace Lucene.Net.Index
 				
 				if (fieldsWriter != null)
 				{
-					fieldsWriter.Close();
+					fieldsWriter.Dispose();
 					fieldsWriter = null;
 					lastDocID = 0;
 					System.Diagnostics.Debug.Assert(state.docStoreSegmentName != null);
-                    SupportClass.CollectionsHelper.AddIfNotContains(state.flushedFiles, state.docStoreSegmentName + "." + IndexFileNames.FIELDS_EXTENSION);
-                    SupportClass.CollectionsHelper.AddIfNotContains(state.flushedFiles, state.docStoreSegmentName + "." + IndexFileNames.FIELDS_INDEX_EXTENSION);
+                    state.flushedFiles.Add(state.docStoreSegmentName + "." + IndexFileNames.FIELDS_EXTENSION);
+                    state.flushedFiles.Add(state.docStoreSegmentName + "." + IndexFileNames.FIELDS_INDEX_EXTENSION);
 					
 					state.docWriter.RemoveOpenFile(state.docStoreSegmentName + "." + IndexFileNames.FIELDS_EXTENSION);
 					state.docWriter.RemoveOpenFile(state.docStoreSegmentName + "." + IndexFileNames.FIELDS_INDEX_EXTENSION);
@@ -152,7 +152,7 @@ namespace Lucene.Net.Index
 				{
 					try
 					{
-						fieldsWriter.Close();
+						fieldsWriter.Dispose();
 					}
 					catch (System.Exception t)
 					{

Modified: incubator/lucene.net/trunk/src/core/Index/Term.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/Term.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/Term.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/Term.cs Tue Feb 28 22:43:08 2012
@@ -30,7 +30,7 @@ namespace Lucene.Net.Index
 	/// </summary>
 	
 	[Serializable]
-    public sealed class Term : System.IComparable
+    public sealed class Term : System.IComparable<Term>
 	{
 		internal System.String field;
 		internal System.String text;
@@ -128,11 +128,6 @@ namespace Lucene.Net.Index
 			return result;
 		}
 		
-		public int CompareTo(System.Object other)
-		{
-			return CompareTo((Term) other);
-		}
-		
 		/// <summary>Compares two terms, returning a negative integer if this
 		/// term belongs before the argument, zero if this term is equal to the
 		/// argument, and a positive integer if this term belongs after the argument.

Modified: incubator/lucene.net/trunk/src/core/Index/TermBuffer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/TermBuffer.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/TermBuffer.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/TermBuffer.cs Tue Feb 28 22:43:08 2012
@@ -16,7 +16,7 @@
  */
 
 using System;
-
+using Lucene.Net.Support;
 using IndexInput = Lucene.Net.Store.IndexInput;
 using UnicodeUtil = Lucene.Net.Util.UnicodeUtil;
 
@@ -111,7 +111,7 @@ namespace Lucene.Net.Index
 			System.String termText = term.Text();
 			int termLen = termText.Length;
 			text.SetLength(termLen);
-			SupportClass.TextSupport.GetCharsFromString(termText, 0, termLen, text.result, 0);
+			TextSupport.GetCharsFromString(termText, 0, termLen, text.result, 0);
 			dirty = true;
 			field = term.Field();
 			this.term = term;

Modified: incubator/lucene.net/trunk/src/core/Index/TermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/TermDocs.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/TermDocs.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/TermDocs.cs Tue Feb 28 22:43:08 2012
@@ -19,17 +19,14 @@ using System;
 
 namespace Lucene.Net.Index
 {
-	
 	/// <summary>TermDocs provides an interface for enumerating &lt;document, frequency&gt;
 	/// pairs for a term.  <p/> The document portion names each document containing
 	/// the term.  Documents are indicated by number.  The frequency portion gives
 	/// the number of times the term occurred in each document.  <p/> The pairs are
 	/// ordered by document number.
 	/// </summary>
-	/// <seealso cref="IndexReader.TermDocs()">
-	/// </seealso>
-	
-	public interface TermDocs
+	/// <seealso cref="IndexReader.TermDocs()" />
+	public interface TermDocs : IDisposable
 	{
 		/// <summary>Sets this to the data for a term.
 		/// The enumeration is reset to the start of the data for this term.
@@ -81,7 +78,9 @@ namespace Lucene.Net.Index
 		/// </summary>
 		bool SkipTo(int target);
 		
+        // TODO: Determine which release this will be removed from
 		/// <summary>Frees associated resources. </summary>
+		[Obsolete("Use Dispose() instead")]
 		void  Close();
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/TermEnum.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/TermEnum.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/TermEnum.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/TermEnum.cs Tue Feb 28 22:43:08 2012
@@ -24,8 +24,7 @@ namespace Lucene.Net.Index
 	/// <p/>Term enumerations are always ordered by Term.compareTo().  Each term in
 	/// the enumeration is greater than all that precede it.  
 	/// </summary>
-	
-	public abstract class TermEnum
+	public abstract class TermEnum : IDisposable
 	{
 		/// <summary>Increments the enumeration to the next element.  True if one exists.</summary>
 		public abstract bool Next();
@@ -35,38 +34,20 @@ namespace Lucene.Net.Index
 		
 		/// <summary>Returns the docFreq of the current Term in the enumeration.</summary>
 		public abstract int DocFreq();
-		
-		/// <summary>Closes the enumeration to further activity, freeing resources. </summary>
-		public abstract void  Close();
-		
-		/// <summary>Skips terms to the first beyond the current whose value is
-		/// greater or equal to <i>target</i>. <p/>Returns true iff there is such
-        /// an entry.  <p/>Behaves as if written: <code>
-		/// public boolean skipTo(Term target) {
-		///     do {
-		///         if (!next())
-		///             return false;
-		///     } while (target > term());
-		///         return true;
-		/// }
-        /// </code>
-		/// Some implementations *could* be considerably more efficient than a linear scan.
-		/// Check the implementation to be sure.
-		/// </summary>
-		/// <deprecated> This method is not performant and will be removed in Lucene 3.0.
-		/// Use <see cref="IndexReader.Terms(Term)" /> to create a new TermEnum positioned at a
-		/// given term.
-		/// </deprecated>
-        [Obsolete("This method is not performant and will be removed in Lucene 3.0.Use IndexReader.Terms(Term) to create a new TermEnum positioned at a given term.")]
-		public virtual bool SkipTo(Term target)
-		{
-			do 
-			{
-				if (!Next())
-					return false;
-			}
-			while (target.CompareTo(Term()) > 0);
-			return true;
-		}
+
+        /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
+        [Obsolete("Use Dispose() instead")]
+        public void Close()
+        {
+            Dispose();
+        }
+
+	    /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
+	    public void Dispose()
+	    {
+	        Dispose(true);
+	    }
+
+	    protected abstract void Dispose(bool disposing);
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/core/Index/TermInfosReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/TermInfosReader.cs?rev=1294875&r1=1294874&r2=1294875&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/TermInfosReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/TermInfosReader.cs Tue Feb 28 22:43:08 2012
@@ -16,10 +16,10 @@
  */
 
 using System;
-
+using Lucene.Net.Support;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Cache;
 using Directory = Lucene.Net.Store.Directory;
-using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
-using SimpleLRUCache = Lucene.Net.Util.Cache.SimpleLRUCache;
 
 namespace Lucene.Net.Index
 {
@@ -29,13 +29,15 @@ namespace Lucene.Net.Index
 	/// set.  
 	/// </summary>
 	
-	sealed class TermInfosReader
+	sealed class TermInfosReader : IDisposable
 	{
 		private Directory directory;
 		private System.String segment;
 		private FieldInfos fieldInfos;
-		
-		private CloseableThreadLocal threadResources = new CloseableThreadLocal();
+
+        private bool isDisposed;
+
+		private CloseableThreadLocal<ThreadResources> threadResources = new CloseableThreadLocal<ThreadResources>();
 		private SegmentTermEnum origEnum;
 		private long size;
 		
@@ -53,7 +55,7 @@ namespace Lucene.Net.Index
 			internal SegmentTermEnum termEnum;
 			
 			// Used for caching the least recently looked-up Terms
-			internal Lucene.Net.Util.Cache.Cache termInfoCache;
+			internal Lucene.Net.Util.Cache.Cache<Term, TermInfo> termInfoCache;
 		}
 		
 		internal TermInfosReader(Directory dir, System.String seg, FieldInfos fis, int readBufferSize, int indexDivisor)
@@ -124,7 +126,7 @@ namespace Lucene.Net.Index
 				// wait for a GC to do so.
 				if (!success)
 				{
-					Close();
+					Dispose();
 				}
 			}
 		}
@@ -138,13 +140,18 @@ namespace Lucene.Net.Index
 		{
 			return origEnum.maxSkipLevels;
 		}
-		
-		internal void  Close()
-		{
-			if (origEnum != null)
-				origEnum.Close();
-			threadResources.Close();
-		}
+
+        public void Dispose()
+        {
+            if (isDisposed) return;
+
+            // Move to protected method if class becomes unsealed
+            if (origEnum != null)
+                origEnum.Dispose();
+            threadResources.Dispose();
+
+            isDisposed = true;
+        }
 		
 		/// <summary>Returns the number of term/value pairs in the set. </summary>
 		internal long Size()
@@ -154,13 +161,13 @@ namespace Lucene.Net.Index
 		
 		private ThreadResources GetThreadResources()
 		{
-			ThreadResources resources = (ThreadResources) threadResources.Get();
+			ThreadResources resources = threadResources.Get();
 			if (resources == null)
 			{
 				resources = new ThreadResources();
 				resources.termEnum = Terms();
 				// Cache does not have to be thread-safe, it is only used by one thread at the same time
-				resources.termInfoCache = new SimpleLRUCache(DEFAULT_CACHE_SIZE);
+				resources.termInfoCache = new SimpleLRUCache<Term,TermInfo>(DEFAULT_CACHE_SIZE);
 				threadResources.Set(resources);
 			}
 			return resources;
@@ -175,7 +182,7 @@ namespace Lucene.Net.Index
 			
 			while (hi >= lo)
 			{
-				int mid = SupportClass.Number.URShift((lo + hi), 1);
+				int mid = Number.URShift((lo + hi), 1);
 				int delta = term.CompareTo(indexTerms[mid]);
 				if (delta < 0)
 					hi = mid - 1;
@@ -208,13 +215,13 @@ namespace Lucene.Net.Index
 			
 			TermInfo ti;
 			ThreadResources resources = GetThreadResources();
-			Lucene.Net.Util.Cache.Cache cache = null;
+			Lucene.Net.Util.Cache.Cache<Term, TermInfo> cache = null;
 			
 			if (useCache)
 			{
 				cache = resources.termInfoCache;
 				// check the cache first if the term was recently looked up
-				ti = (TermInfo) cache.Get(term);
+				ti = cache.Get(term);
 				if (ti != null)
 				{
 					return ti;



Mime
View raw message