lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [02/14] lucenenet git commit: API: Lucene.Net.Facet.Taxonomy.TaxonomyReader: Implemented IDisposable and proper dispose pattern.
Date Thu, 06 Jul 2017 13:06:59 GMT
API: Lucene.Net.Facet.Taxonomy.TaxonomyReader: Implemented IDisposable and proper dispose pattern.


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

Branch: refs/heads/master
Commit: ccc273f23e50fd5b859057229c6b4a140f421ea1
Parents: 199eb10
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Jul 4 21:27:38 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Jul 4 21:27:38 2017 +0700

----------------------------------------------------------------------
 .../Taxonomy/Directory/DirectoryTaxonomyReader.cs     |  7 +------
 src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs       | 13 +++++++++++--
 .../Taxonomy/Directory/TestAddTaxonomy.cs             | 14 ++------------
 .../Taxonomy/Directory/TestDirectoryTaxonomyReader.cs |  4 ++--
 .../Taxonomy/TestTaxonomyCombined.cs                  |  4 ++--
 .../Taxonomy/TestTaxonomyFacetAssociations.cs         |  2 +-
 6 files changed, 19 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ccc273f2/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
index 9b0f8e7..994b644 100644
--- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs
@@ -45,7 +45,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
     /// 
     /// @lucene.experimental
     /// </summary>
-    public class DirectoryTaxonomyReader : TaxonomyReader, IDisposable
+    public class DirectoryTaxonomyReader : TaxonomyReader
     {
         /// <summary>
         /// LUCENENET specific class to make an <see cref="int"/> type into a reference
type.
@@ -436,10 +436,5 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
             }
             return sb.ToString();
         }
-
-        public void Dispose()
-        {
-            Dispose(true);
-        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ccc273f2/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs
index ca4d6db..bff2334 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyReader.cs
@@ -69,7 +69,7 @@ namespace Lucene.Net.Facet.Taxonomy
     /// 
     /// @lucene.experimental
     /// </summary>
-    public abstract class TaxonomyReader
+    public abstract class TaxonomyReader : IDisposable
     {
         /// <summary>
         /// An iterator over a category's children.
@@ -169,7 +169,14 @@ namespace Lucene.Net.Facet.Taxonomy
             }
         }
 
-        public virtual void Dispose(bool disposing)
+        // LUCENENET specific - implementing proper dispose pattern
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected virtual void Dispose(bool disposing)
         {
             if (disposing)
             {
@@ -315,5 +322,7 @@ namespace Lucene.Net.Facet.Taxonomy
             }
             return false;
         }
+
+        
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ccc273f2/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs
index fc8db8f..fb12194 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs
@@ -123,12 +123,10 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
 
         private void validate(Directory dest, Directory src, IOrdinalMap ordMap)
         {
-            var destTr = new DirectoryTaxonomyReader(dest);
-            try
+            using (var destTr = new DirectoryTaxonomyReader(dest))
             {
                 int destSize = destTr.Count;
-                var srcTR = new DirectoryTaxonomyReader(src);
-                try
+                using (var srcTR = new DirectoryTaxonomyReader(src))
                 {
                     var map = ordMap.GetMap();
 
@@ -146,14 +144,6 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
                         Assert.AreEqual(destOrdinal, map[j]);
                     }
                 }
-                finally
-                {
-                    ((TaxonomyReader)srcTR).Dispose(true);
-                }
-            }
-            finally
-            {
-                ((TaxonomyReader)destTr).Dispose(true);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ccc273f2/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs
b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs
index d4b8f90..b6efe82 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestDirectoryTaxonomyReader.cs
@@ -178,14 +178,14 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
                     tw.Dispose();
                     if (closeReader)
                     {
-                        tr.Dispose(true);
+                        tr.Dispose();
                         tr = new DirectoryTaxonomyReader(dir);
                     }
                     else
                     {
                         var newtr = TaxonomyReader.OpenIfChanged(tr);
                         Assert.NotNull(newtr);
-                        tr.Dispose(true);
+                        tr.Dispose();
                         tr = newtr;
                     }
                     Assert.AreEqual(baseNumCategories + 1 + k, tr.Count, "Wrong #categories
in taxonomy (i=" + i + ", k=" + k + ")");

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ccc273f2/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs
index b33ca50..c6419e8 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyCombined.cs
@@ -314,7 +314,7 @@ namespace Lucene.Net.Facet.Taxonomy
             Assert.AreEqual(0, tr.GetPath(0).Length);
             Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents[0]);
             Assert.AreEqual(0, tr.GetOrdinal(new FacetLabel()));
-            tr.Dispose(true);
+            tr.Dispose();
             indexDir.Dispose();
         }
 
@@ -336,7 +336,7 @@ namespace Lucene.Net.Facet.Taxonomy
             Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.ParallelTaxonomyArrays.Parents[0]);
             Assert.AreEqual(0, tr.GetOrdinal(new FacetLabel()));
             tw.Dispose();
-            tr.Dispose(true);
+            tr.Dispose();
             indexDir.Dispose();
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ccc273f2/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs
index 774377b..24e3478 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/TestTaxonomyFacetAssociations.cs
@@ -101,7 +101,7 @@ namespace Lucene.Net.Facet.Taxonomy
             reader = null;
             dir.Dispose();
             dir = null;
-            taxoReader.Dispose(true);
+            taxoReader.Dispose();
             taxoReader = null;
             taxoDir.Dispose();
             taxoDir = null;


Mime
View raw message