lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [04/10] lucenenet git commit: Fixed bug in the Analysis.Compound.Hyphenation.TernaryTree.Iterator that was causing it to populate one the 'k' array incorrectly. Refactored the Iterator to act more like a .NET IEnumerator (that is, to have an initial poin
Date Sun, 02 Oct 2016 15:02:30 GMT
Fixed bug in the Analysis.Compound.Hyphenation.TernaryTree.Iterator that was causing it to
populate one the 'k' array incorrectly. Refactored the Iterator to act more like a .NET IEnumerator
(that is, to have an initial pointer state that is before the sequence it is enumerating).


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

Branch: refs/heads/master
Commit: 01fb360225bf0a3cd69dcbe4847313e5b99a1cce
Parents: d85d19b
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Sep 27 18:23:11 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Oct 2 21:44:03 2016 +0700

----------------------------------------------------------------------
 .../Compound/hyphenation/TernaryTree.cs         | 46 +++++++++++---------
 1 file changed, 26 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/01fb3602/src/Lucene.Net.Analysis.Common/Analysis/Compound/hyphenation/TernaryTree.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Compound/hyphenation/TernaryTree.cs b/src/Lucene.Net.Analysis.Common/Analysis/Compound/hyphenation/TernaryTree.cs
index 98f1e47..dc983b4 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Compound/hyphenation/TernaryTree.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Compound/hyphenation/TernaryTree.cs
@@ -451,10 +451,9 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
             string[] k = new string[n];
             char[] v = new char[n];
             Iterator iter = new Iterator(this);
-            while (iter.HasMoreElements())
+            while (iter.MoveNext())
             {
                 v[i] = iter.Value;
-                iter.MoveNext();
                 k[i++] = iter.Current;
             }
             Init();
@@ -527,6 +526,16 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
             return new Iterator(this);
         }
 
+        /// <summary>
+        /// Enumerator for TernaryTree
+        /// 
+        /// LUCENENET NOTE: This differs a bit from its Java counterpart to adhere to
+        /// .NET IEnumerator semantics. In Java, when the <see cref="Iterator"/> is
+        /// instantiated, it is already positioned at the first element. However,
+        /// to act like a .NET IEnumerator, the initial state is undefined and considered
+        /// to be before the first element until <see cref="MoveNext"/> is called,
and
+        /// if a move took place it will return <c>true</c>;
+        /// </summary>
         public class Iterator : IEnumerator<string>
         {
             private readonly TernaryTree outerInstance;
@@ -576,13 +585,15 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
             /// </summary>
             internal StringBuilder ks;
 
+            private bool isInitialized = false;
+
             public Iterator(TernaryTree outerInstance)
             {
                 this.outerInstance = outerInstance;
                 cur = -1;
                 ns = new Stack<Item>();
                 ks = new StringBuilder();
-                Rewind();
+                isInitialized = false;
             }
 
             public virtual void Rewind()
@@ -593,14 +604,6 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
                 Run();
             }
 
-            //public override string NextElement()
-            //{
-            //  string res = curkey;
-            //  cur = up();
-            //  run();
-            //  return res;
-            //}
-
             public virtual char Value
             {
                 get
@@ -613,13 +616,6 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
                 }
             }
 
-
-
-            public bool HasMoreElements()
-            {
-                return (cur != -1);
-            }
-
             /// <summary>
             /// traverse upwards
             /// </summary>
@@ -752,7 +748,7 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
             {
                 get
                 {
-                    return curkey;
+                    return Current;
                 }
             }
 
@@ -763,6 +759,16 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
 
             public bool MoveNext()
             {
+                if (!isInitialized)
+                {
+                    Rewind();
+                    isInitialized = true;
+                    return cur != -1;
+                }
+                if (cur == -1)
+                {
+                    return false;
+                }
                 cur = Up();
                 Run();
                 return cur != -1;
@@ -770,7 +776,7 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
 
             public void Reset()
             {
-                throw new NotImplementedException();
+                throw new NotSupportedException();
             }
 
             #endregion


Mime
View raw message