Apache Lucene open-source search software
Simplify SearchGroup#equals and SearchGroup.MergedGroup#equals (#15888)
gaobinlongf2b01e5ff573
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.javaindex 0d2528f05fc..863924d42c2 100644--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java@@ -25,6 +25,7 @@ import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.NavigableSet;+import java.util.Objects;import java.util.TreeSet;import org.apache.lucene.search.FieldComparator;import org.apache.lucene.search.Pruning;@@ -62,17 +63,7 @@ public class SearchGroup<T> {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;- SearchGroup<?> that = (SearchGroup<?>) o;-- if (groupValue == null) {- if (that.groupValue != null) {- return false;- }- } else if (!groupValue.equals(that.groupValue)) {- return false;- }-- return true;+ return Objects.equals(groupValue, ((SearchGroup<?>) o).groupValue);}@Override@@ -141,16 +132,7 @@ public class SearchGroup<T> {// same groupValueassert neverEquals(_other);- if (_other instanceof MergedGroup) {- MergedGroup<?> other = (MergedGroup<?>) _other;- if (groupValue == null) {- return other.groupValue == null;- } else {- return groupValue.equals(other.groupValue);- }- } else {- return false;- }+ return _other instanceof MergedGroup<?> other && Objects.equals(groupValue, other.groupValue);}@Override