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 2020/06/30 21:50:56 UTC

[lucenenet] 20/27: Lucene.Net.Util (BytesRef + CharsRef): Implemented IEquatable

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit f420576a2d578992885515fdb124fe8e69282971
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Mon Jun 29 13:35:53 2020 +0700

    Lucene.Net.Util (BytesRef + CharsRef): Implemented IEquatable<T>
---
 src/Lucene.Net/Util/BytesRef.cs | 15 ++++++++-------
 src/Lucene.Net/Util/CharsRef.cs |  5 ++++-
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/Lucene.Net/Util/BytesRef.cs b/src/Lucene.Net/Util/BytesRef.cs
index f44b8d4..7697ecd 100644
--- a/src/Lucene.Net/Util/BytesRef.cs
+++ b/src/Lucene.Net/Util/BytesRef.cs
@@ -40,7 +40,7 @@ namespace Lucene.Net.Util
 #if FEATURE_SERIALIZABLE
     [Serializable]
 #endif
-    public sealed class BytesRef : IComparable<BytesRef>, IComparable // LUCENENET specific - implemented IComparable for FieldComparator
+    public sealed class BytesRef : IComparable<BytesRef>, IComparable, IEquatable<BytesRef> // LUCENENET specific - implemented IComparable for FieldComparator, IEquatable<BytesRef>
 #if FEATURE_CLONEABLE
         , System.ICloneable
 #endif
@@ -210,16 +210,17 @@ namespace Lucene.Net.Util
         public override bool Equals(object other)
         {
             if (other == null)
-            {
                 return false;
-            }
-            if (other is BytesRef)
-            {
-                return this.BytesEquals((BytesRef)other);
-            }
+
+            if (other is BytesRef otherBytes)
+                return this.BytesEquals(otherBytes);
+
             return false;
         }
 
+        bool IEquatable<BytesRef>.Equals(BytesRef other) // LUCENENET specific - implemented IEquatable<BytesRef>
+            => BytesEquals(other);
+
         /// <summary>
         /// Interprets stored bytes as UTF8 bytes, returning the
         /// resulting <see cref="string"/>.
diff --git a/src/Lucene.Net/Util/CharsRef.cs b/src/Lucene.Net/Util/CharsRef.cs
index a5768ce..c84296c 100644
--- a/src/Lucene.Net/Util/CharsRef.cs
+++ b/src/Lucene.Net/Util/CharsRef.cs
@@ -34,7 +34,7 @@ namespace Lucene.Net.Util
 #if FEATURE_SERIALIZABLE
     [Serializable]
 #endif
-    public sealed class CharsRef : IComparable<CharsRef>, ICharSequence
+    public sealed class CharsRef : IComparable<CharsRef>, ICharSequence, IEquatable<CharsRef> // LUCENENET specific - implemented IEquatable<CharsRef>
 #if FEATURE_CLONEABLE
         , System.ICloneable
 #endif
@@ -149,6 +149,9 @@ namespace Lucene.Net.Util
             return false;
         }
 
+        bool IEquatable<CharsRef>.Equals(CharsRef other) // LUCENENET specific - implemented IEquatable<CharsRef>
+            => CharsEquals(other);
+
         public bool CharsEquals(CharsRef other)
         {
             if (Length == other.Length)