lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [38/50] lucenenet git commit: Lucene.Net.Analysis.Common.Analysis.Util.CharArraySet: Added Equals() and GetHashCode() methods (that in Java were inherited from AbstractSet<T>)
Date Thu, 30 Mar 2017 18:00:33 GMT
Lucene.Net.Analysis.Common.Analysis.Util.CharArraySet: Added Equals() and GetHashCode() methods
(that in Java were inherited from AbstractSet<T>)


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

Branch: refs/heads/api-work
Commit: 2fe688d2e7d1a3fbf0d9fa62bf5c3bb055ef65f0
Parents: 71318f0
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Mar 30 16:27:32 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Mar 30 16:27:32 2017 +0700

----------------------------------------------------------------------
 .../Analysis/Util/CharArraySet.cs               | 34 +++++++++++
 .../Analysis/Util/TestCharArraySet.cs           | 63 +++++++++++++++-----
 2 files changed, 82 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2fe688d2/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
index 97bab79..dab73b0 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
@@ -324,6 +324,40 @@ namespace Lucene.Net.Analysis.Util
         #region LUCENENET specific members
 
         /// <summary>
+        /// Compares the specified object with this set for equality. Returns <c>true</c>
if the 
+        /// given object is also a set, the two sets have the same size, and every member
of the 
+        /// given set is contained in this set. This ensures that the equals method works
properly 
+        /// across different implementations of the <see cref="T:ISet{string}"/> interface.
+        /// <para/>
+        /// This implementation first checks if the specified object is this set; if so it

+        /// returns <c>true</c>. Then, it checks if the specified object is a
set whose 
+        /// size is identical to the size of this set; if not, it returns <c>false</c>.
If so, 
+        /// it uses the enumerator of this set and the specified object to determine if all
of the
+        /// contained values are present (using <see cref="string.Equals(string)"/>).
+        /// </summary>
+        /// <param name="obj">object to be compared for equality with this set</param>
+        /// <returns><c>true</c> if the specified object is equal to this
set</returns>
+        public override bool Equals(object obj)
+        {
+            return Collections.Equals(this, obj as ISet<string>);
+        }
+
+        /// <summary>
+        /// Returns the hash code value for this set. The hash code of a set 
+        /// is defined to be the sum of the hash codes of the elements in the 
+        /// set, where the hash code of a <c>null</c> element is defined to be
zero. 
+        /// This ensures that <c>s1.Equals(s2)</c> implies that 
+        /// <c>s1.GetHashCode()==s2.GetHashCode()</c> for any two sets s1 and
s2.
+        /// This implementation iterates over the set, calling the GetHashCode() 
+        /// method on each element in the set, and adding up the results.
+        /// </summary>
+        /// <returns>the hash code value for this set</returns>
+        public override int GetHashCode()
+        {
+            return Collections.GetHashCode(this);
+        }
+
+        /// <summary>
         /// Copies the entire <see cref="CharArraySet"/> to a one-dimensional <see
cref="T:string[]"/> array, 
         /// starting at the specified index of the target array.
         /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2fe688d2/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArraySet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArraySet.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArraySet.cs
index 5e80536..df04154 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArraySet.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArraySet.cs
@@ -1,4 +1,4 @@
-´╗┐using Lucene.Net.Analysis.Util;
+´╗┐using Lucene.Net.Attributes;
 using Lucene.Net.Support;
 using Lucene.Net.Util;
 using NUnit.Framework;
@@ -643,7 +643,40 @@ namespace Lucene.Net.Analysis.Util
 
         #region LUCENENET specific tests
 
-        [Test]
+        [Test, LuceneNetSpecific]
+        public virtual void TestEquality()
+        {
+            var values = new List<string> { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
+            var charArraySet = new CharArraySet(TEST_VERSION_CURRENT, values, false);
+            var charArraySetCopy = new CharArraySet(TEST_VERSION_CURRENT, values, false);
+            values.Reverse();
+            var charArraySetReverse = new CharArraySet(TEST_VERSION_CURRENT, values, false);
+            var equatableSetReverse = new EquatableSet<string>(values);
+
+            assertTrue(charArraySet.GetHashCode().Equals(charArraySetCopy.GetHashCode()));
+            assertTrue(charArraySet.Equals(charArraySetCopy));
+            assertTrue(charArraySet.GetHashCode().Equals(charArraySetReverse.GetHashCode()));
+            assertTrue(charArraySet.Equals(charArraySetReverse));
+            assertTrue(charArraySet.GetHashCode().Equals(equatableSetReverse.GetHashCode()));
+            assertTrue(charArraySet.Equals(equatableSetReverse));
+
+            values = new List<string> { "sally", "seashells", "by", "the", "sea", "shore"
};
+            charArraySet.Clear();
+            charArraySet.AddAll(values);
+
+            assertFalse(charArraySet.GetHashCode().Equals(charArraySetCopy.GetHashCode()));
+            assertFalse(charArraySet.Equals(charArraySetCopy));
+            assertFalse(charArraySet.GetHashCode().Equals(charArraySetReverse.GetHashCode()));
+            assertFalse(charArraySet.Equals(charArraySetReverse));
+            assertFalse(charArraySet.GetHashCode().Equals(equatableSetReverse.GetHashCode()));
+            assertFalse(charArraySet.Equals(equatableSetReverse));
+
+            equatableSetReverse.Remove("sells");
+            assertTrue(charArraySet.GetHashCode().Equals(equatableSetReverse.GetHashCode()));
+            assertTrue(charArraySet.Equals(equatableSetReverse));
+        }
+
+        [Test, LuceneNetSpecific]
         public virtual void TestUnionWithObject()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -686,7 +719,7 @@ namespace Lucene.Net.Analysis.Util
             assertTrue(target.Contains(new StringCharSequenceWrapper("testing")));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestUnionWithCharArray()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -706,7 +739,7 @@ namespace Lucene.Net.Analysis.Util
                 "true", "set", "of", "unique", "values", "except"}, target);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestUnionWithString()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -728,7 +761,7 @@ namespace Lucene.Net.Analysis.Util
                 "true", "set", "of", "unique", "values", "except"}, target);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestUnionWithCharSequence()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -748,7 +781,7 @@ namespace Lucene.Net.Analysis.Util
                 "true", "set", "of", "unique", "values", "except"}, target);
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsSubsetOfString()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -761,7 +794,7 @@ namespace Lucene.Net.Analysis.Util
             assertTrue(target.IsSubsetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsSubsetOfObject()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -774,7 +807,7 @@ namespace Lucene.Net.Analysis.Util
             assertTrue(target.IsSubsetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsProperSubsetOfString()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -787,7 +820,7 @@ namespace Lucene.Net.Analysis.Util
             assertFalse(target.IsProperSubsetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsProperSubsetOfObject()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -800,7 +833,7 @@ namespace Lucene.Net.Analysis.Util
             assertFalse(target.IsProperSubsetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsSupersetOfString()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -813,7 +846,7 @@ namespace Lucene.Net.Analysis.Util
             assertTrue(target.IsSupersetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsSupersetOfObject()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -826,7 +859,7 @@ namespace Lucene.Net.Analysis.Util
             assertTrue(target.IsSupersetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsProperSupersetOfString()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -839,7 +872,7 @@ namespace Lucene.Net.Analysis.Util
             assertFalse(target.IsProperSupersetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestIsProperSupersetOfObject()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -852,7 +885,7 @@ namespace Lucene.Net.Analysis.Util
             assertFalse(target.IsProperSupersetOf(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestOverlapsString()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };
@@ -865,7 +898,7 @@ namespace Lucene.Net.Analysis.Util
             assertTrue(target.Overlaps(originalValues));
         }
 
-        [Test]
+        [Test, LuceneNetSpecific]
         public virtual void TestOverlapsObject()
         {
             var originalValues = new string[] { "sally", "sells", "seashells", "by", "the",
"sea", "shore" };


Mime
View raw message