lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject lucene-solr:branch_6x: LUCENE-7359: Add equals() and hashCode() to Explanation
Date Wed, 29 Jun 2016 09:38:28 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x d33ad81d6 -> 976501f6f


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/976501f6
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/976501f6
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/976501f6

Branch: refs/heads/branch_6x
Commit: 976501f6f3fe602ada85a6f2392d1bb23438a319
Parents: d33ad81
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:38:00 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/976501f6/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 912e601..53e18a5 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -56,6 +56,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/976501f6/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 3e5951a..6af1019 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;
@@ -121,7 +120,6 @@ public final class Explanation {
     return buffer.toString();
   }
 
-
   /** Render an explanation as HTML. */
   @Deprecated
   public String toHtml() {
@@ -142,4 +140,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/976501f6/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