lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1102109 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g: src/core/Index/DirectoryReader.cs src/core/Index/IndexReader.cs src/core/Index/SegmentInfos.cs test/core/Index/TestIndexWriterReader.cs
Date Wed, 11 May 2011 22:07:49 GMT
Author: digy
Date: Wed May 11 22:07:48 2011
New Revision: 1102109

URL: http://svn.apache.org/viewvc?rev=1102109&view=rev
Log:
[LUCENENET-412] Some code clean up.
The abstract method "segmentInfos.FindSegmentsFile.DoBody" is converted to "Func<string,
object>"  to remove those ugly "AnonymousXXXX:FindSegmentsFile"s which make it hard to
compare java & .NET source files.

Modified:
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/DirectoryReader.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexReader.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentInfos.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Index/TestIndexWriterReader.cs

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/DirectoryReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/DirectoryReader.cs?rev=1102109&r1=1102108&r2=1102109&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/DirectoryReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/DirectoryReader.cs Wed
May 11 22:07:48 2011
@@ -32,60 +32,6 @@ namespace Lucene.Net.Index
 	/// <summary> An IndexReader which reads indexes with multiple segments.</summary>
 	public class DirectoryReader:IndexReader, System.ICloneable
 	{
-		/*new*/ private class AnonymousClassFindSegmentsFile:SegmentInfos.FindSegmentsFile
-		{
-			private void  InitBlock(bool readOnly, Lucene.Net.Index.IndexDeletionPolicy deletionPolicy,
int termInfosIndexDivisor)
-			{
-				this.readOnly = readOnly;
-				this.deletionPolicy = deletionPolicy;
-				this.termInfosIndexDivisor = termInfosIndexDivisor;
-			}
-			private bool readOnly;
-			private Lucene.Net.Index.IndexDeletionPolicy deletionPolicy;
-			private int termInfosIndexDivisor;
-			internal AnonymousClassFindSegmentsFile(bool readOnly, Lucene.Net.Index.IndexDeletionPolicy
deletionPolicy, int termInfosIndexDivisor, Lucene.Net.Store.Directory Param1):base(Param1)
-			{
-				InitBlock(readOnly, deletionPolicy, termInfosIndexDivisor);
-			}
-			public /*protected internal*/ override System.Object DoBody(System.String segmentFileName)
-			{
-				SegmentInfos infos = new SegmentInfos();
-				infos.Read(directory, segmentFileName);
-				if (readOnly)
-					return new ReadOnlyDirectoryReader(directory, infos, deletionPolicy, termInfosIndexDivisor);
-				else
-					return new DirectoryReader(directory, infos, deletionPolicy, false, termInfosIndexDivisor);
-			}
-		}
-        //DIGY: not used anymore
-        //private class AnonymousClassFindSegmentsFile1:SegmentInfos.FindSegmentsFile
-        //{
-        //    private void  InitBlock(bool openReadOnly, DirectoryReader enclosingInstance)
-        //    {
-        //        this.openReadOnly = openReadOnly;
-        //        this.enclosingInstance = enclosingInstance;
-        //    }
-        //    private bool openReadOnly;
-        //    private DirectoryReader enclosingInstance;
-        //    public DirectoryReader Enclosing_Instance
-        //    {
-        //        get
-        //        {
-        //            return enclosingInstance;
-        //        }
-				
-        //    }
-        //    internal AnonymousClassFindSegmentsFile1(bool openReadOnly, DirectoryReader
enclosingInstance, Lucene.Net.Store.Directory Param1):base(Param1)
-        //    {
-        //        InitBlock(openReadOnly, enclosingInstance);
-        //    }
-        //    public /*protected internal*/ override System.Object DoBody(System.String segmentFileName)
-        //    {
-        //        SegmentInfos infos = new SegmentInfos();
-        //        infos.Read(directory, segmentFileName);
-        //        return Enclosing_Instance.DoReopen(infos, false, openReadOnly);
-        //    }
-        //}
 		protected internal Directory directory;
 		protected internal bool readOnly;
 		
@@ -112,12 +58,21 @@ namespace Lucene.Net.Index
         // > our current segmentInfos version in case we were
         // opened on a past IndexCommit:
         private long maxIndexVersion;
-		
-		internal static IndexReader Open(Directory directory, IndexDeletionPolicy deletionPolicy,
IndexCommit commit, bool readOnly, int termInfosIndexDivisor)
-		{
-			return (IndexReader) new AnonymousClassFindSegmentsFile(readOnly, deletionPolicy, termInfosIndexDivisor,
directory).Run(commit);
-		}
-		
+
+        internal static IndexReader Open(Directory directory, IndexDeletionPolicy deletionPolicy,
IndexCommit commit, bool readOnly, int termInfosIndexDivisor)
+        {
+            return (IndexReader)new SegmentInfos.FindSegmentsFile(directory,
+                (segmentFileName) =>
+                {
+                    SegmentInfos infos = new SegmentInfos();
+                    infos.Read(directory, segmentFileName);
+                    if (readOnly)
+                        return new ReadOnlyDirectoryReader(directory, infos, deletionPolicy,
termInfosIndexDivisor);
+                    else
+                        return new DirectoryReader(directory, infos, deletionPolicy, false,
termInfosIndexDivisor);
+                }).Run(commit);
+        }
+        		
 		/// <summary>Construct reading the named set of readers. </summary>
 		internal DirectoryReader(Directory directory, SegmentInfos sis, IndexDeletionPolicy deletionPolicy,
bool readOnly, int termInfosIndexDivisor)
 		{
@@ -567,27 +522,13 @@ namespace Lucene.Net.Index
                     }
                 }
 
-                return (IndexReader)new AnonymousFindSegmentsFile(directory, openReadOnly,
this).Run(commit);
-            }
-        }
-
-        class AnonymousFindSegmentsFile : SegmentInfos.FindSegmentsFile
-        {
-            DirectoryReader enclosingInstance;
-            bool openReadOnly;
-            Directory dir;
-            public AnonymousFindSegmentsFile(Directory directory, bool openReadOnly, DirectoryReader
dirReader) : base(directory)
-            {
-                this.dir = directory;
-                this.openReadOnly = openReadOnly;
-                enclosingInstance = dirReader;
-            }
-
-            public override object DoBody(string segmentFileName)
-            {
-                SegmentInfos infos = new SegmentInfos();
-                infos.Read(this.dir, segmentFileName);
-                return enclosingInstance.DoReopen(infos, false, openReadOnly);
+                return (IndexReader)new SegmentInfos.FindSegmentsFile(directory, 
+                    (segmentFileName) =>
+                    {
+                        SegmentInfos infos = new SegmentInfos();
+                        infos.Read(directory, segmentFileName);
+                        return DoReopen(infos, false, openReadOnly);
+                    }).Run(commit);
             }
         }
 

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexReader.cs?rev=1102109&r1=1102108&r2=1102109&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/IndexReader.cs Wed May
11 22:07:48 2011
@@ -69,23 +69,6 @@ namespace Lucene.Net.Index
 	/// </version>
 	public abstract class IndexReader : System.ICloneable, System.IDisposable
 	{
-		private class AnonymousClassFindSegmentsFile:SegmentInfos.FindSegmentsFile
-		{
-			private void  InitBlock(Lucene.Net.Store.Directory directory2)
-			{
-				this.directory2 = directory2;
-			}
-			private Lucene.Net.Store.Directory directory2;
-			internal AnonymousClassFindSegmentsFile(Lucene.Net.Store.Directory directory2, Lucene.Net.Store.Directory
Param1):base(Param1)
-			{
-				InitBlock(directory2);
-			}
-			public override System.Object DoBody(System.String segmentFileName)
-			{
-				return (long) directory2.FileModified(segmentFileName);
-			}
-		}
-		
 		/// <summary> Constants describing field properties, for example used for
 		/// {@link IndexReader#GetFieldNames(FieldOption)}.
 		/// </summary>
@@ -763,7 +746,11 @@ namespace Lucene.Net.Index
 		/// <throws>  IOException if there is a low-level IO error </throws>
 		public static long LastModified(Directory directory2)
 		{
-			return (long) ((System.Int64) new AnonymousClassFindSegmentsFile(directory2, directory2).Run());
+            return (long)new SegmentInfos.FindSegmentsFile(directory2, 
+                (segmentFileName) =>
+                {
+                    return directory2.FileModified(segmentFileName);
+                }).Run();
 		}
 		
 		/// <summary> Reads version number from segments files. The version number is

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentInfos.cs?rev=1102109&r1=1102108&r2=1102109&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentInfos.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentInfos.cs Wed May
11 22:07:48 2011
@@ -37,32 +37,6 @@ namespace Lucene.Net.Index
 	[Serializable]
 	public sealed class SegmentInfos: List<SegmentInfo> 
 	{
-		private class AnonymousClassFindSegmentsFile:FindSegmentsFile
-		{
-			private void  InitBlock(SegmentInfos enclosingInstance)
-			{
-				this.enclosingInstance = enclosingInstance;
-			}
-			private SegmentInfos enclosingInstance;
-			public SegmentInfos Enclosing_Instance
-			{
-				get
-				{
-					return enclosingInstance;
-				}
-				
-			}
-			internal AnonymousClassFindSegmentsFile(SegmentInfos enclosingInstance, Lucene.Net.Store.Directory
Param1):base(Param1)
-			{
-				InitBlock(enclosingInstance);
-			}
-			
-			public /*protected internal*/ override System.Object DoBody(System.String segmentFileName)
-			{
-				Enclosing_Instance.Read(directory, segmentFileName);
-				return null;
-			}
-		}
 		/// <summary>The file format version, a negative number. </summary>
 		/* Works since counter, the old 1st entry, is always >= 0 */
 		public const int FORMAT = - 1;
@@ -358,8 +332,13 @@ namespace Lucene.Net.Index
 		{
 			
 			generation = lastGeneration = - 1;
-			
-			new AnonymousClassFindSegmentsFile(this, directory).Run();
+
+            new SegmentInfos.FindSegmentsFile(directory, 
+                (segmentFileName) =>
+                {
+                    Read(directory, segmentFileName);
+                    return null;
+                }).Run();
 		}
 		
 		// Only non-null after prepareCommit has been called and
@@ -476,8 +455,6 @@ namespace Lucene.Net.Index
             SegmentInfos sis = new SegmentInfos();
             sis.Read(directory);
             return sis.version;
-			//return (long) ((System.Int64) new AnonymousClassFindSegmentsFile1(directory).Run());
-            //DIGY: AnonymousClassFindSegmentsFile1 can safely be deleted
 		}
 		
 		/// <summary> Returns userData from latest segments file</summary>
@@ -576,14 +553,14 @@ namespace Lucene.Net.Index
 		/// time, etc., it could have been deleted due to a writer
 		/// commit finishing.
 		/// </summary>
-		public abstract class FindSegmentsFile
+		internal class FindSegmentsFile
 		{
-			
 			internal Directory directory;
-			
-			public FindSegmentsFile(Directory directory)
+            
+			public FindSegmentsFile(Directory directory,Func<string,object> doBody)
 			{
 				this.directory = directory;
+                this.DoBody = doBody;
 			}
 			
 			public System.Object Run()
@@ -834,13 +811,15 @@ namespace Lucene.Net.Index
 					}
 				}
 			}
-			
-			/// <summary> Subclass must implement this.  The assumption is an
-			/// IOException will be thrown if something goes wrong
-			/// during the processing that could have been caused by
-			/// a writer committing.
-			/// </summary>
-			public /*internal*/ abstract System.Object DoBody(System.String segmentFileName);
+
+            /// <summary> Subclass must implement this.  The assumption is an
+            /// IOException will be thrown if something goes wrong
+            /// during the processing that could have been caused by
+            /// a writer committing.
+            /// DIGY:
+            /// .NET: "DoBody" is converted to delegate to remove these ugly "AnonymousXXXX:FindSegmentsFile"s

+            /// </summary>
+            Func<string, object> DoBody;
 		}
 		
 		/// <summary> Returns a new SegmentInfos containg the SegmentInfo

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Index/TestIndexWriterReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Index/TestIndexWriterReader.cs?rev=1102109&r1=1102108&r2=1102109&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Index/TestIndexWriterReader.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Index/TestIndexWriterReader.cs
Wed May 11 22:07:48 2011
@@ -927,7 +927,7 @@ namespace Lucene.Net.Index
                 //There isn't any pending files to be deleted after "writer.Close()". 
                 //But, since lucene.java's test case is designed that way
                 //and I might be wrong, I will add a warning
-                Assert.Inconclusive("", 0, dir1.GetOpenDeletedFiles().Count);
+                Assert.Inconclusive("Is this really a bug?", 0, dir1.GetOpenDeletedFiles().Count);
             }
 			writer.Close();
 			



Mime
View raw message