paulirwin commented on code in PR #1056:
URL: https://github.com/apache/lucenenet/pull/1056#discussion_r1882955002


##########
src/Lucene.Net.Benchmark/Quality/QualityQuery.cs:
##########
@@ -82,22 +82,59 @@ public virtual string GetValue(string name)
         /// For a nicer sort of input queries before running them.
         /// Try first as ints, fall back to string if not int.
         /// </summary>
-        /// <param name="other"></param>
-        /// <returns></returns>
-        public virtual int CompareTo(QualityQuery other)
+        /// <param name="other">The other <see cref="QualityQuery"/> to 
compare to.</param>
+        /// <returns>0 if equal, a negative value if smaller, a positive value 
if larger.</returns>
+        public virtual int CompareTo(QualityQuery? other)
         {
-            try
+            if (other is null)
             {
-                // compare as ints when ids ints
-                int n = int.Parse(queryID, CultureInfo.InvariantCulture);
-                int nOther = int.Parse(other.queryID, 
CultureInfo.InvariantCulture);
-                return n - nOther;
+                return 1;
             }
-            catch (Exception e) when (e.IsNumberFormatException())
+
+            if (int.TryParse(queryID, NumberStyles.Integer, 
CultureInfo.InvariantCulture, out int n)
+                && int.TryParse(other.queryID, NumberStyles.Integer, 
CultureInfo.InvariantCulture, out int nOther))
             {
-                // fall back to string comparison
-                return queryID.CompareToOrdinal(other.queryID);
+                return n - nOther;
             }
+
+            // fall back to string comparison
+            return queryID.CompareToOrdinal(other.queryID);
+        }
+
+        // LUCENENET specific - provide Equals and GetHashCode due to 
providing operator overrides
+        protected bool Equals(QualityQuery? other) => queryID == 
other?.queryID;

Review Comment:
   That is how Rider generates it, so that subclasses (or any other private 
callers) don't have to do all the ReferenceEquals/GetType/etc. dance in the 
`object` version, but I'll remove it for now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to