You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/01/31 17:56:08 UTC

[35/50] [abbrv] lucenenet git commit: Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter: Changed Map (array property) > GetMap()

Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter: Changed Map (array property) > GetMap()


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

Branch: refs/heads/api-work
Commit: 810f47cf2ce749bfe44f0596508d27ebd8ecf396
Parents: c68378f
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Jan 31 16:53:27 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Tue Jan 31 16:53:27 2017 +0700

----------------------------------------------------------------------
 .../Directory/DirectoryTaxonomyWriter.cs        | 62 +++++++++-----------
 .../Taxonomy/Directory/TestAddTaxonomy.cs       |  2 +-
 2 files changed, 30 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/810f47cf/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs
index 1c8e21d..b34a190 100644
--- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyWriter.cs
@@ -5,6 +5,7 @@ using Lucene.Net.Util;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Linq;
 using System.IO;
 
 namespace Lucene.Net.Facet.Taxonomy.Directory
@@ -979,7 +980,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
             /// needed. Calling it will also free all resources that the map might
             /// be holding (such as temporary disk space), other than the returned int[].
             /// </summary>
-            int[] Map { get; }
+            int[] GetMap();
         }
 
         /// <summary>
@@ -1018,12 +1019,10 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
             public void AddDone() // nothing to do
             {
             }
-            public int[] Map
+
+            public int[] GetMap()
             {
-                get
-                {
-                    return map;
-                }
+                return map.ToArray(); // LUCENENET specific: Since this is clearly not meant to be written to, we are cloning the array
             }
         }
 
@@ -1067,37 +1066,34 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
 
             int[] map = null;
 
-            public int[] Map
+            public int[] GetMap()
             {
-                get
+                if (map != null)
                 {
-                    if (map != null)
-                    {
-                        return map;
-                    }
-                    AddDone(); // in case this wasn't previously called
-
-                    var ifs = new FileStream(tmpfile, FileMode.OpenOrCreate, FileAccess.Read);
-                    var @in = new InputStreamDataInput(ifs);
-                    map = new int[@in.ReadInt()];
-                    // NOTE: The current code assumes here that the map is complete,
-                    // i.e., every ordinal gets one and exactly one value. Otherwise,
-                    // we may run into an EOF here, or vice versa, not read everything.
-                    for (int i = 0; i < map.Length; i++)
-                    {
-                        int origordinal = @in.ReadInt();
-                        int newordinal = @in.ReadInt();
-                        map[origordinal] = newordinal;
-                    }
-                    @in.Dispose();
-
-                    // Delete the temporary file, which is no longer needed.
-                    if (File.Exists(tmpfile))
-                    {
-                        File.Delete(tmpfile);
-                    }
                     return map;
                 }
+                AddDone(); // in case this wasn't previously called
+
+                var ifs = new FileStream(tmpfile, FileMode.OpenOrCreate, FileAccess.Read);
+                var @in = new InputStreamDataInput(ifs);
+                map = new int[@in.ReadInt()];
+                // NOTE: The current code assumes here that the map is complete,
+                // i.e., every ordinal gets one and exactly one value. Otherwise,
+                // we may run into an EOF here, or vice versa, not read everything.
+                for (int i = 0; i < map.Length; i++)
+                {
+                    int origordinal = @in.ReadInt();
+                    int newordinal = @in.ReadInt();
+                    map[origordinal] = newordinal;
+                }
+                @in.Dispose();
+
+                // Delete the temporary file, which is no longer needed.
+                if (File.Exists(tmpfile))
+                {
+                    File.Delete(tmpfile);
+                }
+                return map;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/810f47cf/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 0ed2bb4..b896c94 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/Directory/TestAddTaxonomy.cs
@@ -129,7 +129,7 @@ namespace Lucene.Net.Facet.Taxonomy.Directory
                 var srcTR = new DirectoryTaxonomyReader(src);
                 try
                 {
-                    var map = ordMap.Map;
+                    var map = ordMap.GetMap();
 
                     // validate taxo sizes
                     int srcSize = srcTR.Count;