You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/03/05 17:56:23 UTC

svn commit: r1664412 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/search/ lucene/core/src/test/org/apache/lucene/search/ lucene/queries/ lucene/queries/src/java/org/apache/lucene/queries/ lucene/qu...

Author: jpountz
Date: Thu Mar  5 16:56:21 2015
New Revision: 1664412

URL: http://svn.apache.org/r1664412
Log:
LUCENE-6333: Clean up overridden .equals and .hashCode methods in Query subclasses.

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesTermsQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
    lucene/dev/branches/branch_5x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
    lucene/dev/branches/branch_5x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java
    lucene/dev/branches/branch_5x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Thu Mar  5 16:56:21 2015
@@ -186,6 +186,9 @@ Other
 
 * LUCENE-6292: Seed StringHelper better. (Robert Muir)
 
+* LUCENE-6333: Refactored queries to delegate their equals and hashcode
+  impls to the super class. (Lee Hinman via Adrien Grand)
+
 Changes in Runtime Behavior
 
 * LUCENE-6255: PhraseQuery now ignores leading holes and requires that

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java Thu Mar  5 16:56:21 2015
@@ -304,7 +304,7 @@ public class BooleanQuery extends Query
       return false;
     }
     BooleanQuery other = (BooleanQuery)o;
-    return this.getBoost() == other.getBoost()
+    return super.equals(o)
         && this.clauses.equals(other.clauses)
         && this.getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch()
         && this.disableCoord == other.disableCoord;
@@ -313,7 +313,7 @@ public class BooleanQuery extends Query
   /** Returns a hash code value for this object.*/
   @Override
   public int hashCode() {
-    return Float.floatToIntBits(getBoost()) ^ clauses.hashCode()
+    return super.hashCode() ^ clauses.hashCode()
       + getMinimumNumberShouldMatch() + (disableCoord ? 17:0);
   }
   

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java Thu Mar  5 16:56:21 2015
@@ -284,7 +284,7 @@ public class DisjunctionMaxQuery extends
   public boolean equals(Object o) {
     if (! (o instanceof DisjunctionMaxQuery) ) return false;
     DisjunctionMaxQuery other = (DisjunctionMaxQuery)o;
-    return this.getBoost() == other.getBoost()
+    return super.equals(o)
             && this.tieBreakerMultiplier == other.tieBreakerMultiplier
             && this.disjuncts.equals(other.disjuncts);
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesRangeQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesRangeQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesRangeQuery.java Thu Mar  5 16:56:21 2015
@@ -85,7 +85,7 @@ public final class DocValuesRangeQuery e
         && Objects.equals(upperVal, that.upperVal)
         && includeLower == that.includeLower
         && includeUpper == that.includeUpper
-        && getBoost() == that.getBoost();
+        && super.equals(obj);
   }
 
   @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesTermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesTermsQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesTermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DocValuesTermsQuery.java Thu Mar  5 16:56:21 2015
@@ -117,10 +117,10 @@ public class DocValuesTermsQuery extends
       return false;
     }
     DocValuesTermsQuery that = (DocValuesTermsQuery) obj;
-    if (!field.equals(that.field)) {
+    if (!super.equals(obj)) {
       return false;
     }
-    if (getBoost() != that.getBoost()) {
+    if (!field.equals(that.field)) {
       return false;
     }
     return Arrays.equals(terms, that.terms);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java Thu Mar  5 16:56:21 2015
@@ -46,7 +46,7 @@ public final class FieldValueQuery exten
       return false;
     }
     final FieldValueQuery that = (FieldValueQuery) obj;
-    return field.equals(that.field) && getBoost() == that.getBoost();
+    return super.equals(obj) && field.equals(that.field);
   }
 
   @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java Thu Mar  5 16:56:21 2015
@@ -63,7 +63,7 @@ public abstract class Filter extends Que
 
   @Override
   public boolean equals(Object that) {
-    // Query's default impl only compares boots but they do not matter in the
+    // Query's default impl only compares boost but they do not matter in the
     // case of filters since it does not influence scores
     return this == that;
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java Thu Mar  5 16:56:21 2015
@@ -144,17 +144,4 @@ public class MatchAllDocsQuery extends Q
     buffer.append(ToStringUtils.boost(getBoost()));
     return buffer.toString();
   }
-
-  @Override
-  public boolean equals(Object o) {
-    if (!(o instanceof MatchAllDocsQuery))
-      return false;
-    MatchAllDocsQuery other = (MatchAllDocsQuery) o;
-    return this.getBoost() == other.getBoost();
-  }
-
-  @Override
-  public int hashCode() {
-    return Float.floatToIntBits(getBoost()) ^ 0x1AA71190;
-  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java Thu Mar  5 16:56:21 2015
@@ -357,7 +357,7 @@ public class MultiPhraseQuery extends Qu
   public boolean equals(Object o) {
     if (!(o instanceof MultiPhraseQuery)) return false;
     MultiPhraseQuery other = (MultiPhraseQuery)o;
-    return this.getBoost() == other.getBoost()
+    return super.equals(o)
       && this.slop == other.slop
       && termArraysEquals(this.termArrays, other.termArrays)
       && this.positions.equals(other.positions);
@@ -366,11 +366,10 @@ public class MultiPhraseQuery extends Qu
   /** Returns a hash code value for this object.*/
   @Override
   public int hashCode() {
-    return Float.floatToIntBits(getBoost())
+    return super.hashCode()
       ^ slop
       ^ termArraysHashCode()
-      ^ positions.hashCode()
-      ^ 0x4AC65113;
+      ^ positions.hashCode();
   }
   
   // Breakout calculation of the termArrays hashcode

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java Thu Mar  5 16:56:21 2015
@@ -303,7 +303,7 @@ public abstract class MultiTermQuery ext
     if (getClass() != obj.getClass())
       return false;
     MultiTermQuery other = (MultiTermQuery) obj;
-    if (Float.floatToIntBits(getBoost()) != Float.floatToIntBits(other.getBoost()))
+    if (!super.equals(obj))
       return false;
     if (!rewriteMethod.equals(other.rewriteMethod)) {
       return false;

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java Thu Mar  5 16:56:21 2015
@@ -428,7 +428,7 @@ public class PhraseQuery extends Query {
     if (!(o instanceof PhraseQuery))
       return false;
     PhraseQuery other = (PhraseQuery)o;
-    return (this.getBoost() == other.getBoost())
+    return super.equals(o)
       && (this.slop == other.slop)
       &&  this.terms.equals(other.terms)
       && this.positions.equals(other.positions);
@@ -437,7 +437,7 @@ public class PhraseQuery extends Query {
   /** Returns a hash code value for this object.*/
   @Override
   public int hashCode() {
-    return Float.floatToIntBits(getBoost())
+    return super.hashCode()
       ^ slop
       ^ terms.hashCode()
       ^ positions.hashCode();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java Thu Mar  5 16:56:21 2015
@@ -210,14 +210,11 @@ public class TermQuery extends Query {
   public boolean equals(Object o) {
     if (!(o instanceof TermQuery)) return false;
     TermQuery other = (TermQuery) o;
-    return (this.getBoost() == other.getBoost())
-        && this.term.equals(other.term);
+    return super.equals(o) && this.term.equals(other.term);
   }
-  
-  /** Returns a hash code value for this object. */
+
   @Override
   public int hashCode() {
-    return Float.floatToIntBits(getBoost()) ^ term.hashCode();
+    return super.hashCode() ^ term.hashCode();
   }
-  
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java Thu Mar  5 16:56:21 2015
@@ -509,7 +509,7 @@ public class TestQueryRescorer extends L
         return false;
       }
       FixedScoreQuery other = (FixedScoreQuery) o;
-      return Float.floatToIntBits(getBoost()) == Float.floatToIntBits(other.getBoost()) &&
+      return super.equals(o) &&
         reverse == other.reverse &&
         Arrays.equals(idToNum, other.idToNum);
     }

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java Thu Mar  5 16:56:21 2015
@@ -192,13 +192,9 @@ public class TermsQuery extends Query im
 
   @Override
   public boolean equals(Object obj) {
-    if (this == obj) {
-      return true;
-    }
-    if ((obj == null) || (obj.getClass() != this.getClass())) {
+    if (!super.equals(obj)) {
       return false;
     }
-
     TermsQuery that = (TermsQuery) obj;
     // first check the fields before even comparing the bytes
     if (that.hashCode == hashCode && getBoost() == that.getBoost() && Arrays.equals(termsAndFields, that.termsAndFields)) {
@@ -213,11 +209,6 @@ public class TermsQuery extends Query im
   }
 
   @Override
-  public int hashCode() {
-    return hashCode ^ Float.floatToIntBits(getBoost());
-  }
-
-  @Override
   public String toString(String defaultField) {
     StringBuilder builder = new StringBuilder();
     BytesRef spare = new BytesRef(termsBytes);

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java Thu Mar  5 16:56:21 2015
@@ -203,14 +203,12 @@ public class FunctionQuery extends Query
   public boolean equals(Object o) {
     if (!FunctionQuery.class.isInstance(o)) return false;
     FunctionQuery other = (FunctionQuery)o;
-    return this.getBoost() == other.getBoost()
+    return super.equals(o)
             && this.func.equals(other.func);
   }
 
-  /** Returns a hash code value for this object. */
   @Override
   public int hashCode() {
-    return func.hashCode()*31 + Float.floatToIntBits(getBoost());
+    return super.hashCode() ^ func.hashCode();
   }
-
 }

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/query/RewriteQuery.java Thu Mar  5 16:56:21 2015
@@ -49,7 +49,7 @@ abstract class RewriteQuery<SQ extends S
 
   @Override
   public int hashCode() {
-    return getClass().hashCode()
+    return super.hashCode()
     ^ fieldName.hashCode()
     ^ qf.hashCode()
     ^ srndQuery.hashCode();
@@ -62,9 +62,10 @@ abstract class RewriteQuery<SQ extends S
     if (! getClass().equals(obj.getClass()))
       return false;
     RewriteQuery other = (RewriteQuery)obj;
-    return fieldName.equals(other.fieldName)
-  && qf.equals(other.qf)
-  && srndQuery.equals(other.srndQuery);
+    return super.equals(obj)
+      && fieldName.equals(other.fieldName)
+      && qf.equals(other.qf)
+      && srndQuery.equals(other.srndQuery);
   }
 
   /** 

Modified: lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java?rev=1664412&r1=1664411&r2=1664412&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java Thu Mar  5 16:56:21 2015
@@ -258,7 +258,7 @@ public class TermAutomatonQuery extends
 
     // NOTE: not quite correct, because if terms were added in different
     // order in each query but the language is the same, we return false:
-    return (this.getBoost() == other.getBoost())
+    return super.equals(o)
       && this.termToID.equals(other.termToID) &&
       Operations.sameLanguage(det, other.det);
   }
@@ -269,7 +269,7 @@ public class TermAutomatonQuery extends
     if (det == null) {
       throw new IllegalStateException("please call finish first");
     }
-    return Float.floatToIntBits(getBoost()) ^ termToID.hashCode() + det.toDot().hashCode();
+    return super.hashCode() ^ termToID.hashCode() + det.toDot().hashCode();
   }
 
   /** Returns the dot (graphviz) representation of this automaton.