mirror of https://github.com/apache/lucene.git
LUCENE-6333: Clean up overridden .equals and .hashCode methods in Query subclasses.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1664384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a43843701d
commit
800fcb8927
|
@ -218,6 +218,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
|
||||
|
|
|
@ -304,7 +304,7 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
|
|||
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 implements Iterable<BooleanClause> {
|
|||
/** 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ public class DisjunctionMaxQuery extends Query implements Iterable<Query> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public final class DocValuesRangeQuery extends Query {
|
|||
&& Objects.equals(upperVal, that.upperVal)
|
||||
&& includeLower == that.includeLower
|
||||
&& includeUpper == that.includeUpper
|
||||
&& getBoost() == that.getBoost();
|
||||
&& super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -117,10 +117,10 @@ public class DocValuesTermsQuery extends Query {
|
|||
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);
|
||||
|
|
|
@ -46,7 +46,7 @@ public final class FieldValueQuery extends Query {
|
|||
return false;
|
||||
}
|
||||
final FieldValueQuery that = (FieldValueQuery) obj;
|
||||
return field.equals(that.field) && getBoost() == that.getBoost();
|
||||
return super.equals(obj) && field.equals(that.field);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,7 +63,7 @@ public abstract class Filter extends Query {
|
|||
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -144,17 +144,4 @@ public class MatchAllDocsQuery extends Query {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -357,7 +357,7 @@ public class MultiPhraseQuery extends Query {
|
|||
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 Query {
|
|||
/** 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
|
||||
|
|
|
@ -288,7 +288,7 @@ public abstract class MultiTermQuery extends Query {
|
|||
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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -509,7 +509,7 @@ public class TestQueryRescorer extends LuceneTestCase {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -192,13 +192,9 @@ public class TermsQuery extends Query implements Accountable {
|
|||
|
||||
@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)) {
|
||||
|
@ -212,11 +208,6 @@ public class TermsQuery extends Query implements Accountable {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode ^ Float.floatToIntBits(getBoost());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String defaultField) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ abstract class RewriteQuery<SQ extends SrndQuery> extends Query {
|
|||
|
||||
@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 SrndQuery> extends Query {
|
|||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -258,7 +258,7 @@ public class TermAutomatonQuery extends Query {
|
|||
|
||||
// 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 Query {
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue