lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject lucene-solr:master: LUCENE-7359: Add equals() and hashCode() to Explanation
Date Wed, 29 Jun 2016 09:40:53 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 4ea95bf8f -> 6a703bebf


LUCENE-7359: Add equals() and hashCode() to Explanation


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6a703beb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6a703beb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6a703beb

Branch: refs/heads/master
Commit: 6a703bebf751e882be30061121cfd7f0e9e8eb8b
Parents: 4ea95bf
Author: Alan Woodward <romseygeek@apache.org>
Authored: Wed Jun 29 10:36:28 2016 +0100
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Wed Jun 29 10:40:27 2016 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  2 ++
 .../org/apache/lucene/search/Explanation.java   | 19 +++++++++++--
 .../lucene/search/TestSimpleExplanations.java   | 29 ++++++++++++++++++++
 3 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6a703beb/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 22f86b2..2760474 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -68,6 +68,8 @@ Improvements
   and empty boolean queries now rewrite to MatchNoDocsQuery instead of
   vice/versa (Jim Ferenczi via Mike McCandless)
 
+* LUCENE-7359: Add equals() and hashCode() to Explanation (Alan Woodward)
+
 Optimizations
 
 * LUCENE-7330, LUCENE-7339: Speed up conjunction queries. (Adrien Grand)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6a703beb/lucene/core/src/java/org/apache/lucene/search/Explanation.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/Explanation.java b/lucene/core/src/java/org/apache/lucene/search/Explanation.java
index 818f83f..42e3ce7 100644
--- a/lucene/core/src/java/org/apache/lucene/search/Explanation.java
+++ b/lucene/core/src/java/org/apache/lucene/search/Explanation.java
@@ -16,7 +16,6 @@
  */
 package org.apache.lucene.search;
 
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -120,5 +119,21 @@ public final class Explanation {
 
     return buffer.toString();
   }
-  
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+    Explanation that = (Explanation) o;
+    return match == that.match &&
+        Float.compare(that.value, value) == 0 &&
+        Objects.equals(description, that.description) &&
+        Objects.equals(details, that.details);
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(match, value, description, details);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6a703beb/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java b/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java
index 422245a..9f8c589 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java
@@ -20,6 +20,7 @@ package org.apache.lucene.search;
 import java.util.Arrays;
 
 import org.apache.lucene.index.Term;
+import org.junit.Test;
 
 /**
  * TestExplanations subclass focusing on basic query types
@@ -715,4 +716,32 @@ public class TestSimpleExplanations extends BaseExplanationTestCase {
     qtest(query, new int[] { 0,1,2,3 });
   }
 
+  @Test
+  public void testEquality() {
+
+    Explanation e1 = Explanation.match(1f, "an explanation");
+    Explanation e2 = Explanation.match(1f, "an explanation", Explanation.match(1f, "a subexplanation"));
+    Explanation e25 = Explanation.match(1f, "an explanation",
+        Explanation.match(1f, "a subexplanation", Explanation.match(1f, "a subsubexplanation")));
+    Explanation e3 = Explanation.match(1f, "an explanation");
+    Explanation e4 = Explanation.match(2f, "an explanation");
+    Explanation e5 = Explanation.noMatch("an explanation");
+    Explanation e6 = Explanation.noMatch("an explanation", Explanation.match(1f, "a subexplanation"));
+    Explanation e7 = Explanation.noMatch("an explanation");
+    Explanation e8 = Explanation.match(1f, "another explanation");
+
+    assertEquals(e1, e3);
+    assertFalse(e1.equals(e2));
+    assertFalse(e2.equals(e25));
+    assertFalse(e1.equals(e4));
+    assertFalse(e1.equals(e5));
+    assertEquals(e5, e7);
+    assertFalse(e5.equals(e6));
+    assertFalse(e1.equals(e8));
+
+    assertEquals(e1.hashCode(), e3.hashCode());
+    assertEquals(e5.hashCode(), e7.hashCode());
+
+  }
+
 }


Mime
View raw message