lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [02/50] [abbrv] lucenenet git commit: Lucene.Net.Core.Support: Consolidated ReverseComparer functionality into the Support.Compaitiblity.Collections class.
Date Tue, 31 Jan 2017 17:55:35 GMT
Lucene.Net.Core.Support: Consolidated ReverseComparer functionality into the Support.Compaitiblity.Collections
class.


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

Branch: refs/heads/api-work
Commit: 15b94d2ad02f5a0aefc30de4d304df5ac91f45d1
Parents: 2391561
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Jan 31 10:54:16 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Jan 31 11:19:00 2017 +0700

----------------------------------------------------------------------
 .../Support/Compatibility/Collections.cs        | 28 +++++++++++++++-----
 src/Lucene.Net.Tests/core/Util/TestArrayUtil.cs | 14 +++++-----
 .../core/Util/TestCollectionUtil.cs             | 22 +++++++--------
 3 files changed, 37 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/15b94d2a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
index 9412424..d0ba71d 100644
--- a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
+++ b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
@@ -38,7 +38,7 @@ namespace Lucene.Net
 
         public static IComparer<T> ReverseOrder<T>()
         {
-            return (IComparer<T>)ReverseComparer.REVERSE_ORDER;
+            return (IComparer<T>)ReverseComparer<T>.REVERSE_ORDER;
         }
 
         public static IComparer<T> ReverseOrder<T>(IComparer<T> cmp)
@@ -306,14 +306,28 @@ namespace Lucene.Net
 
         #region ReverseComparer
 
-        internal class ReverseComparer : IComparer<IComparable>
-        {
-            internal static readonly ReverseComparer REVERSE_ORDER = new ReverseComparer();
+        //private class ReverseComparer : IComparer<IComparable>
+        //{
+        //    internal static readonly ReverseComparer REVERSE_ORDER = new ReverseComparer();
+
 
+        //    public int Compare(IComparable c1, IComparable c2)
+        //    {
+        //        return c2.CompareTo(c1);
+        //    }
+        //}
+
+        // LUCENENET NOTE: When consolidating this, it turns out that only the 
+        // CaseInsensitiveComparer works correctly in .NET (not sure why).
+        // So, this hybrid was made from the original Java implementation and the
+        // original implemenation (above) that used CaseInsensitiveComparer.
+        public class ReverseComparer<T> : IComparer<T>
+        {
+            internal static readonly ReverseComparer<T> REVERSE_ORDER = new ReverseComparer<T>();
 
-            public int Compare(IComparable c1, IComparable c2)
+            public int Compare(T x, T y)
             {
-                return c2.CompareTo(c1);
+                return (new CaseInsensitiveComparer()).Compare(y, x);
             }
         }
 
@@ -321,7 +335,7 @@ namespace Lucene.Net
 
         #region ReverseComparer2
 
-        internal class ReverseComparer2<T> : IComparer<T>
+        private class ReverseComparer2<T> : IComparer<T>
 
         {
             /**

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/15b94d2a/src/Lucene.Net.Tests/core/Util/TestArrayUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestArrayUtil.cs b/src/Lucene.Net.Tests/core/Util/TestArrayUtil.cs
index 0b0c27c..58c2c21 100644
--- a/src/Lucene.Net.Tests/core/Util/TestArrayUtil.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestArrayUtil.cs
@@ -169,8 +169,6 @@ namespace Lucene.Net.Util
             return a;
         }
 
-        private CollectionsHelper.ReverseComparer<int> ReverseOrder = new CollectionsHelper.ReverseComparer<int>();
-
         [Test]
         public virtual void TestIntroSort()
         {
@@ -185,8 +183,8 @@ namespace Lucene.Net.Util
 
                 a1 = CreateRandomArray(2000);
                 a2 = (int[])a1.Clone();
-                ArrayUtil.IntroSort(a1, ReverseOrder);
-                Array.Sort(a2, ReverseOrder);
+                ArrayUtil.IntroSort(a1, Collections.ReverseOrder<int>());
+                Array.Sort(a2, Collections.ReverseOrder<int>());
                 Assert.AreEqual(a2, a1);
                 // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
                 ArrayUtil.IntroSort(a1);
@@ -234,8 +232,8 @@ namespace Lucene.Net.Util
 
                 a1 = CreateRandomArray(2000);
                 a2 = (int[])a1.Clone();
-                ArrayUtil.TimSort(a1, ReverseOrder);
-                Array.Sort(a2, ReverseOrder);
+                ArrayUtil.TimSort(a1, Collections.ReverseOrder<int>());
+                Array.Sort(a2, Collections.ReverseOrder<int>());
                 Assert.AreEqual(a2, a1);
                 // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
                 ArrayUtil.TimSort(a1);
@@ -352,8 +350,8 @@ namespace Lucene.Net.Util
             int[] a = new int[0];
             ArrayUtil.IntroSort(a);
             ArrayUtil.TimSort(a);
-            ArrayUtil.IntroSort(a, ReverseOrder);
-            ArrayUtil.TimSort(a, ReverseOrder);
+            ArrayUtil.IntroSort(a, Collections.ReverseOrder<int>());
+            ArrayUtil.TimSort(a, Collections.ReverseOrder<int>());
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/15b94d2a/src/Lucene.Net.Tests/core/Util/TestCollectionUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestCollectionUtil.cs b/src/Lucene.Net.Tests/core/Util/TestCollectionUtil.cs
index 0f3ed18..f89c837 100644
--- a/src/Lucene.Net.Tests/core/Util/TestCollectionUtil.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestCollectionUtil.cs
@@ -26,8 +26,6 @@ namespace Lucene.Net.Util
     [TestFixture]
     public class TestCollectionUtil : LuceneTestCase
     {
-        private CollectionsHelper.ReverseComparer<int> ReverseOrder = new CollectionsHelper.ReverseComparer<int>();
-
         private List<int> CreateRandomList(int maxSize)
         {
             Random rnd = Random();
@@ -51,8 +49,8 @@ namespace Lucene.Net.Util
 
                 list1 = CreateRandomList(2000);
                 list2 = new List<int>(list1);
-                CollectionUtil.IntroSort<int>(list1, ReverseOrder);
-                list2.Sort(ReverseOrder);
+                CollectionUtil.IntroSort(list1, Collections.ReverseOrder<int>());
+                list2.Sort(Collections.ReverseOrder<int>());
                 Assert.AreEqual(list2, list1);
                 // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
                 CollectionUtil.IntroSort(list1);
@@ -73,8 +71,8 @@ namespace Lucene.Net.Util
 
                 list1 = CreateRandomList(2000);
                 list2 = new List<int>(list1);
-                CollectionUtil.TimSort(list1, ReverseOrder);
-                list2.Sort(ReverseOrder);
+                CollectionUtil.TimSort(list1, Collections.ReverseOrder<int>());
+                list2.Sort(Collections.ReverseOrder<int>());
                 Assert.AreEqual(list2, list1);
                 // reverse back, so we can test that completely backwards sorted array (worst
case) is working:
                 CollectionUtil.TimSort(list1);
@@ -90,15 +88,15 @@ namespace Lucene.Net.Util
             IList<int> list = Arrays.AsList(new int[0]); // LUCENE-2989
             CollectionUtil.IntroSort(list);
             CollectionUtil.TimSort(list);
-            CollectionUtil.IntroSort(list, ReverseOrder);
-            CollectionUtil.TimSort(list, ReverseOrder);
+            CollectionUtil.IntroSort(list, Collections.ReverseOrder<int>());
+            CollectionUtil.TimSort(list, Collections.ReverseOrder<int>());
 
             // check that empty non-random access lists pass sorting without ex (as sorting
is not needed)
             list = new List<int>();
             CollectionUtil.IntroSort(list);
             CollectionUtil.TimSort(list);
-            CollectionUtil.IntroSort(list, ReverseOrder);
-            CollectionUtil.TimSort(list, ReverseOrder);
+            CollectionUtil.IntroSort(list, Collections.ReverseOrder<int>());
+            CollectionUtil.TimSort(list, Collections.ReverseOrder<int>());
         }
 
         [Test]
@@ -109,8 +107,8 @@ namespace Lucene.Net.Util
             list.Add(1);
             CollectionUtil.IntroSort(list);
             CollectionUtil.TimSort(list);
-            CollectionUtil.IntroSort(list, ReverseOrder);
-            CollectionUtil.TimSort(list, ReverseOrder);
+            CollectionUtil.IntroSort(list, Collections.ReverseOrder<int>());
+            CollectionUtil.TimSort(list, Collections.ReverseOrder<int>());
         }
     }
 }
\ No newline at end of file


Mime
View raw message