lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwe...@apache.org
Subject [3/3] lucene-solr:branch_6x: LUCENE-7277: Make Query.hashCode and Query.equals abstract.
Date Tue, 24 May 2016 08:38:20 GMT
LUCENE-7277: Make Query.hashCode and Query.equals abstract.


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

Branch: refs/heads/branch_6x
Commit: d6264eb4756013fcfd9f6c2d9a224851c331767a
Parents: afe1964
Author: Dawid Weiss <dweiss@apache.org>
Authored: Tue May 24 10:36:15 2016 +0200
Committer: Dawid Weiss <dweiss@apache.org>
Committed: Tue May 24 10:36:15 2016 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |   3 +
 lucene/MIGRATE.txt                              |   5 +
 .../apache/lucene/search/BlendedTermQuery.java  |  21 ++--
 .../org/apache/lucene/search/BooleanQuery.java  |  19 ++--
 .../org/apache/lucene/search/BoostQuery.java    |  17 +--
 .../lucene/search/ConstantScoreQuery.java       |  15 +--
 .../lucene/search/DisjunctionMaxQuery.java      |  18 +--
 .../lucene/search/DocValuesRewriteMethod.java   |  24 ++--
 .../apache/lucene/search/FieldValueQuery.java   |  11 +-
 .../apache/lucene/search/MatchAllDocsQuery.java |  10 ++
 .../apache/lucene/search/MatchNoDocsQuery.java  |  29 +++--
 .../apache/lucene/search/MultiPhraseQuery.java  |  20 ++--
 .../apache/lucene/search/MultiTermQuery.java    |  27 ++---
 .../MultiTermQueryConstantScoreWrapper.java     |  11 +-
 .../apache/lucene/search/NGramPhraseQuery.java  |  16 +--
 .../org/apache/lucene/search/PhraseQuery.java   |  19 ++--
 .../apache/lucene/search/PointInSetQuery.java   |  22 ++--
 .../apache/lucene/search/PointRangeQuery.java   |  38 ++-----
 .../java/org/apache/lucene/search/Query.java    |  49 ++++++--
 .../org/apache/lucene/search/SynonymQuery.java  |  15 +--
 .../org/apache/lucene/search/TermQuery.java     |   9 +-
 .../search/spans/FieldMaskingSpanQuery.java     |  24 ++--
 .../lucene/search/spans/SpanBoostQuery.java     |  18 +--
 .../lucene/search/spans/SpanContainQuery.java   |  16 +--
 .../search/spans/SpanMultiTermQueryWrapper.java |  14 +--
 .../lucene/search/spans/SpanNearQuery.java      |  40 +++++--
 .../lucene/search/spans/SpanNotQuery.java       |  21 ++--
 .../apache/lucene/search/spans/SpanOrQuery.java |  13 +--
 .../search/spans/SpanPositionCheckQuery.java    |  13 +--
 .../lucene/search/spans/SpanTermQuery.java      |  14 +--
 .../apache/lucene/search/JustCompileSearch.java |  33 ++++--
 .../apache/lucene/search/TestBooleanScorer.java |  12 +-
 .../lucene/search/TestConstantScoreQuery.java   |  11 +-
 .../apache/lucene/search/TestLRUQueryCache.java |  15 ++-
 .../apache/lucene/search/TestNeedsScores.java   |  25 ++--
 .../apache/lucene/search/TestQueryRescorer.java |  31 +++--
 .../apache/lucene/search/TestScorerPerf.java    |  10 +-
 .../apache/lucene/search/TestSortRandom.java    |  16 +--
 .../search/spans/JustCompileSearchSpans.java    |  14 ++-
 .../org/apache/lucene/facet/DrillDownQuery.java |  21 ++--
 .../apache/lucene/facet/DrillSidewaysQuery.java |  31 +++--
 .../apache/lucene/facet/range/DoubleRange.java  |  19 ++--
 .../apache/lucene/facet/range/LongRange.java    |  19 ++--
 .../apache/lucene/facet/TestDrillSideways.java  |  25 ++--
 .../facet/range/TestRangeFacetCounts.java       |  11 +-
 .../search/highlight/HighlighterTest.java       |   8 +-
 .../custom/HighlightCustomQueryTest.java        |  25 +---
 .../search/vectorhighlight/FieldQueryTest.java  | 102 +++++++++--------
 .../lucene/search/join/GlobalOrdinalsQuery.java |  23 ++--
 .../join/GlobalOrdinalsWithScoreQuery.java      |  29 +++--
 .../join/PointInSetIncludingScoreQuery.java     |  23 ++--
 .../search/join/TermsIncludingScoreQuery.java   |  27 ++---
 .../search/join/ToChildBlockJoinQuery.java      |  19 ++--
 .../search/join/ToParentBlockJoinQuery.java     |  21 ++--
 .../lucene/search/join/TestBlockJoin.java       | 114 ++++++++++---------
 .../apache/lucene/search/join/TestJoinUtil.java |  31 +++--
 .../uninverting/TestFieldCacheSortRandom.java   |  19 ++--
 .../apache/lucene/queries/BoostingQuery.java    |  27 ++---
 .../apache/lucene/queries/CommonTermsQuery.java |  48 ++++----
 .../apache/lucene/queries/CustomScoreQuery.java |  28 ++---
 .../org/apache/lucene/queries/TermsQuery.java   |  20 ++--
 .../lucene/queries/function/BoostedQuery.java   |  15 ++-
 .../lucene/queries/function/FunctionQuery.java  |  10 +-
 .../queries/function/FunctionRangeQuery.java    |  23 ++--
 .../lucene/queries/mlt/MoreLikeThisQuery.java   |  55 ++++-----
 .../queries/payloads/PayloadScoreQuery.java     |  29 +++--
 .../queries/payloads/SpanPayloadCheckQuery.java |  13 +--
 .../complexPhrase/ComplexPhraseQueryParser.java |  50 +++-----
 .../surround/query/RewriteQuery.java            |  33 +++---
 .../queryparser/classic/TestMultiAnalyzer.java  |  49 ++++----
 .../lucene/document/LatLonPointBoxQuery.java    |  36 ++----
 .../document/LatLonPointDistanceQuery.java      |  22 ++--
 .../document/LatLonPointInPolygonQuery.java     |  18 +--
 .../sandbox/queries/FuzzyLikeThisQuery.java     |  45 +++-----
 .../lucene/search/DocValuesNumbersQuery.java    |  20 ++--
 .../lucene/search/DocValuesRangeQuery.java      |  24 ++--
 .../lucene/search/DocValuesTermsQuery.java      |  19 ++--
 .../lucene/search/TermAutomatonQuery.java       |  35 +++---
 .../lucene/search/TestTermAutomatonQuery.java   |  18 +--
 .../spatial/composite/CompositeVerifyQuery.java |  21 ++--
 .../composite/IntersectsRPTVerifyQuery.java     |  17 ++-
 .../spatial/prefix/AbstractPrefixTreeQuery.java |  18 ++-
 .../serialized/SerializedDVStrategy.java        |  14 +--
 .../geopoint/search/GeoPointInBBoxQuery.java    |  25 ++--
 .../GeoPointTermQueryConstantScoreWrapper.java  |  11 +-
 .../spatial3d/PointInGeo3DShapeQuery.java       |  26 ++---
 .../search/suggest/document/ContextQuery.java   |  13 ++-
 .../suggest/document/PrefixCompletionQuery.java |  10 ++
 .../suggest/document/RegexCompletionQuery.java  |   9 ++
 .../apache/lucene/search/AssertingQuery.java    |   9 +-
 .../org/apache/lucene/search/QueryUtils.java    |  53 +++++----
 .../lucene/search/RandomApproximationQuery.java |  14 +--
 .../lucene/search/spans/AssertingSpanQuery.java |  24 ++--
 .../java/org/apache/solr/schema/LatLonType.java |   9 +-
 .../java/org/apache/solr/search/BitDocSet.java  |  16 ++-
 .../solr/search/CollapsingQParserPlugin.java    |  22 ++--
 .../java/org/apache/solr/search/DocSetBase.java |  17 ++-
 .../apache/solr/search/ExportQParserPlugin.java |  25 ++--
 .../apache/solr/search/ExtendedQueryBase.java   |   2 +-
 .../solr/search/GraphTermsQParserPlugin.java    |  12 +-
 .../apache/solr/search/HashQParserPlugin.java   |  37 ++++--
 .../apache/solr/search/JoinQParserPlugin.java   |  26 +++--
 .../apache/solr/search/QueryWrapperFilter.java  |  12 +-
 .../apache/solr/search/ReRankQParserPlugin.java |  13 ++-
 .../solr/search/SolrConstantScoreQuery.java     |  11 +-
 .../apache/solr/search/SolrIndexSearcher.java   |  27 ++++-
 .../org/apache/solr/search/SortedIntDocSet.java |  12 ++
 .../solr/search/join/BlockJoinFacetFilter.java  |  17 +++
 .../search/join/BlockJoinParentQParser.java     |  11 +-
 .../org/apache/solr/search/join/GraphQuery.java |  64 ++++-------
 .../search/join/ScoreJoinQParserPlugin.java     |  40 +++----
 .../solr/update/DeleteByQueryWrapper.java       |  28 ++---
 .../solr/search/TestFilteredDocIdSet.java       |  21 ++++
 .../solr/search/TestQueryWrapperFilter.java     |  14 +--
 .../test/org/apache/solr/search/TestSort.java   |  10 ++
 115 files changed, 1364 insertions(+), 1288 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 981a041..cd911b2 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -129,6 +129,9 @@ Documentation
 
 Other
 
+* LUCENE-7277: Make Query.hashCode and Query.equals abstract. (Paul Elschot, 
+  Dawid Weiss)
+
 * LUCENE-7174: Upgrade randomizedtesting to 2.3.4. (Uwe Schindler, Dawid Weiss)
 
 * LUCENE-7205: Remove repeated nl.getLength() calls in

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/MIGRATE.txt
----------------------------------------------------------------------
diff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txt
index b94c12d..2db5cf0 100644
--- a/lucene/MIGRATE.txt
+++ b/lucene/MIGRATE.txt
@@ -1,5 +1,10 @@
 # Apache Lucene Migration Guide
 
+## Query.hashCode and Query.equals are now abstract methods (LUCENE-7277)
+Any custom query subclasses should redeclare equivalence relationship according
+to the subclass's details. See code patterns used in existing core Lucene query
+classes for details.
+
 ## The way how number of document calculated is changed (LUCENE-6711)
 The number of documents (numDocs) is used to calculate term specificity (idf) and average document length (avdl).
 Prior to LUCENE-6711, collectionStats.maxDoc() was used for the statistics.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
index c0ac6bb..ca9459f 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java
@@ -224,20 +224,21 @@ public final class BlendedTermQuery extends Query {
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (super.equals(obj) == false) {
-      return false;
-    }
-    BlendedTermQuery that = (BlendedTermQuery) obj;
-    return Arrays.equals(terms, that.terms)
-        && Arrays.equals(contexts, that.contexts)
-        && Arrays.equals(boosts, that.boosts)
-        && rewriteMethod.equals(that.rewriteMethod);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(BlendedTermQuery other) {
+    return Arrays.equals(terms, other.terms) && 
+           Arrays.equals(contexts, other.contexts) && 
+           Arrays.equals(boosts, other.boosts) && 
+           rewriteMethod.equals(other.rewriteMethod);
   }
 
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = 31 * h + Arrays.hashCode(terms);
     h = 31 * h + Arrays.hashCode(contexts);
     h = 31 * h + Arrays.hashCode(boosts);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
index 4699df4..3371b50 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
@@ -421,17 +421,18 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
    */
   @Override
   public boolean equals(Object o) {
-    if (super.equals(o) == false) {
-      return false;
-    }
-    BooleanQuery that = (BooleanQuery)o;
-    return this.getMinimumNumberShouldMatch() == that.getMinimumNumberShouldMatch()
-        && this.disableCoord == that.disableCoord
-        && clauseSets.equals(that.clauseSets);
+    return sameClassAs(o) &&
+           equalsTo(getClass().cast(o));
+  }
+
+  private boolean equalsTo(BooleanQuery other) {
+    return getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch() && 
+           disableCoord == other.disableCoord &&
+           clauseSets.equals(other.clauseSets);
   }
 
   private int computeHashCode() {
-    int hashCode = 31 * super.hashCode() + Objects.hash(disableCoord, minimumNumberShouldMatch, clauseSets);
+    int hashCode = Objects.hash(disableCoord, minimumNumberShouldMatch, clauseSets);
     if (hashCode == 0) {
       hashCode = 1;
     }
@@ -443,8 +444,8 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
 
   @Override
   public int hashCode() {
+    // no need for synchronization, in the worst case we would just compute the hash several times.
     if (hashCode == 0) {
-      // no need for synchronization, in the worst case we would just compute the hash several times
       hashCode = computeHashCode();
       assert hashCode != 0;
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java b/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java
index c7d0aea..eb7f4b9 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java
@@ -58,18 +58,19 @@ public final class BoostQuery extends Query {
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (super.equals(obj) == false) {
-      return false;
-    }
-    BoostQuery that = (BoostQuery) obj;
-    return query.equals(that.query)
-        && Float.floatToIntBits(boost) == Float.floatToIntBits(that.boost);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(BoostQuery other) {
+    return query.equals(other.query) && 
+           Float.floatToIntBits(boost) == Float.floatToIntBits(other.boost);
   }
 
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = 31 * h + query.hashCode();
     h = 31 * h + Float.floatToIntBits(boost);
     return h;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
index 4ca80e2..eb5e2d3 100644
--- a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
@@ -162,20 +162,13 @@ public final class ConstantScoreQuery extends Query {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (!super.equals(o))
-      return false;
-    if (o instanceof ConstantScoreQuery) {
-      final ConstantScoreQuery other = (ConstantScoreQuery) o;
-      return this.query.equals(other.query);
-    }
-    return false;
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           query.equals(((ConstantScoreQuery) other).query);
   }
 
   @Override
   public int hashCode() {
-    return 31 * super.hashCode() + query.hashCode();
+    return 31 * classHash() + query.hashCode();
   }
-
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
index 9bcd05f..8b1c45d 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
@@ -241,16 +241,18 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
   }
 
   /** Return true iff we represent the same query as o
-   * @param o another object
+   * @param other another object
    * @return true iff o is a DisjunctionMaxQuery with the same boost and the same subqueries, in the same order, as us
    */
   @Override
-  public boolean equals(Object o) {
-    if (! (o instanceof DisjunctionMaxQuery) ) return false;
-    DisjunctionMaxQuery other = (DisjunctionMaxQuery)o;
-    return super.equals(o)
-            && this.tieBreakerMultiplier == other.tieBreakerMultiplier
-            && Arrays.equals(disjuncts, other.disjuncts);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(DisjunctionMaxQuery other) {
+    return tieBreakerMultiplier == other.tieBreakerMultiplier && 
+           Arrays.equals(disjuncts, other.disjuncts);
   }
 
   /** Compute a hash code for hashing us
@@ -258,7 +260,7 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
    */
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = 31 * h + Float.floatToIntBits(tieBreakerMultiplier);
     h = 31 * h + Arrays.hashCode(disjuncts);
     return h;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java b/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java
index 0c544e3..261e8e5 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java
@@ -59,17 +59,14 @@ public final class DocValuesRewriteMethod extends MultiTermQuery.RewriteMethod {
     }
     
     @Override
-    public final boolean equals(final Object o) {
-      if (super.equals(o) == false) {
-        return false;
-      }
-      MultiTermQueryDocValuesWrapper that = (MultiTermQueryDocValuesWrapper) o;
-      return query.equals(that.query);
+    public final boolean equals(final Object other) {
+      return sameClassAs(other) &&
+             query.equals(((MultiTermQueryDocValuesWrapper) other).query);
     }
-    
+
     @Override
     public final int hashCode() {
-      return 31 * super.hashCode() + query.hashCode();
+      return 31 * classHash() + query.hashCode();
     }
     
     /** Returns the field name for this query */
@@ -169,14 +166,9 @@ public final class DocValuesRewriteMethod extends MultiTermQuery.RewriteMethod {
   }
   
   @Override
-  public boolean equals(Object obj) {
-    if (this == obj)
-      return true;
-    if (obj == null)
-      return false;
-    if (getClass() != obj.getClass())
-      return false;
-    return true;
+  public boolean equals(Object other) {
+    return other != null &&
+           getClass() == other.getClass();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java b/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java
index 4bc081c..ed3c5e7 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FieldValueQuery.java
@@ -43,17 +43,14 @@ public final class FieldValueQuery extends Query {
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (super.equals(obj) == false) {
-      return false;
-    }
-    final FieldValueQuery that = (FieldValueQuery) obj;
-    return field.equals(that.field);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           field.equals(((FieldValueQuery) other).field);
   }
 
   @Override
   public int hashCode() {
-    return 31 * super.hashCode() + field.hashCode();
+    return 31 * classHash() + field.hashCode();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
index 4f62f74..2566cf0 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
@@ -71,4 +71,14 @@ public final class MatchAllDocsQuery extends Query {
   public String toString(String field) {
     return "*:*";
   }
+
+  @Override
+  public boolean equals(Object o) {
+    return sameClassAs(o);
+  }
+
+  @Override
+  public int hashCode() {
+    return classHash();
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/MatchNoDocsQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MatchNoDocsQuery.java b/lucene/core/src/java/org/apache/lucene/search/MatchNoDocsQuery.java
index d0bc18c..77b7952 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MatchNoDocsQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MatchNoDocsQuery.java
@@ -22,18 +22,27 @@ import java.io.IOException;
 import org.apache.lucene.index.IndexReader;
 
 /**
- * A query that matches no documents.
+     * A query that matches no documents.
  */
 public class MatchNoDocsQuery extends Query {
+  @Override
+  public Query rewrite(IndexReader reader) throws IOException {
+    // Rewrite to an empty BooleanQuery so no Scorer or Weight is required
+    return new BooleanQuery.Builder().build();
+  }
 
-    @Override
-    public Query rewrite(IndexReader reader) throws IOException {
-        // Rewrite to an empty BooleanQuery so no Scorer or Weight is required
-        return new BooleanQuery.Builder().build();
-    }
+  @Override
+  public String toString(String field) {
+      return "";
+  }
 
-    @Override
-    public String toString(String field) {
-        return "";
-    }
+  @Override
+  public boolean equals(Object o) {
+    return sameClassAs(o);
+  }
+
+  @Override
+  public int hashCode() {
+    return classHash();
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
index d703ebd..cf4f39c 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
@@ -383,20 +383,22 @@ public class MultiPhraseQuery extends Query {
 
   /** Returns true if <code>o</code> is equal to this. */
   @Override
-  public boolean equals(Object o) {
-    if (super.equals(o) == false) {
-      return false;
-    }
-    MultiPhraseQuery other = (MultiPhraseQuery)o;
-    return this.slop == other.slop
-      && termArraysEquals(this.termArrays, other.termArrays) // terms equal implies field equal
-      && Arrays.equals(this.positions, other.positions);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+
+  private boolean equalsTo(MultiPhraseQuery other) {
+    return this.slop == other.slop && 
+           termArraysEquals(this.termArrays, other.termArrays) && /* terms equal implies field equal */ 
+           Arrays.equals(this.positions, other.positions);
+
   }
 
   /** Returns a hash code value for this object.*/
   @Override
   public int hashCode() {
-    return super.hashCode()
+    return classHash()
       ^ slop
       ^ termArraysHashCode() // terms equal implies field equal
       ^ Arrays.hashCode(positions);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java
index 6b5c65f..ef2b014 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MultiTermQuery.java
@@ -332,27 +332,20 @@ public abstract class MultiTermQuery extends Query {
   @Override
   public int hashCode() {
     final int prime = 31;
-    int result = 1;
+    int result = classHash();
     result = prime * result + rewriteMethod.hashCode();
-    if (field != null) result = prime * result + field.hashCode();
+    result = prime * result + field.hashCode();
     return result;
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (this == obj)
-      return true;
-    if (obj == null)
-      return false;
-    if (getClass() != obj.getClass())
-      return false;
-    MultiTermQuery other = (MultiTermQuery) obj;
-    if (!super.equals(obj))
-      return false;
-    if (!rewriteMethod.equals(other.rewriteMethod)) {
-      return false;
-    }
-    return (other.field == null ? field == null : other.field.equals(field));
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+
+  private boolean equalsTo(MultiTermQuery other) {
+    return rewriteMethod.equals(other.rewriteMethod) && 
+           field.equals(other.field);
   }
- 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java
index eb7436f..6657757 100644
--- a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java
+++ b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java
@@ -91,17 +91,14 @@ final class MultiTermQueryConstantScoreWrapper<Q extends MultiTermQuery> extends
   }
 
   @Override
-  public final boolean equals(final Object o) {
-    if (super.equals(o) == false) {
-      return false;
-    }
-    final MultiTermQueryConstantScoreWrapper<?> that = (MultiTermQueryConstantScoreWrapper<?>) o;
-    return this.query.equals(that.query);
+  public final boolean equals(final Object other) {
+    return sameClassAs(other) &&
+           query.equals(((MultiTermQueryConstantScoreWrapper<?>) other).query);
   }
 
   @Override
   public final int hashCode() {
-    return 31 * super.hashCode() + query.hashCode();
+    return 31 * classHash() + query.hashCode();
   }
 
   /** Returns the encapsulated query */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
index e6f085c..db997d3 100644
--- a/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/NGramPhraseQuery.java
@@ -78,17 +78,19 @@ public class NGramPhraseQuery extends Query {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (super.equals(o) == false) {
-      return false;
-    }
-    NGramPhraseQuery other = (NGramPhraseQuery) o;
-    return n == other.n && phraseQuery.equals(other.phraseQuery);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+
+  private boolean equalsTo(NGramPhraseQuery other) {
+    return n == other.n && 
+           phraseQuery.equals(other.phraseQuery);
   }
 
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = 31 * h + phraseQuery.hashCode();
     h = 31 * h + n;
     return h;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
index 143ed17..459d664 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
@@ -561,20 +561,21 @@ public class PhraseQuery extends Query {
 
   /** Returns true iff <code>o</code> is equal to this. */
   @Override
-  public boolean equals(Object o) {
-    if (super.equals(o) == false) {
-      return false;
-    }
-    PhraseQuery that = (PhraseQuery) o;
-    return slop == that.slop
-        && Arrays.equals(terms, that.terms)
-        && Arrays.equals(positions, that.positions);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(PhraseQuery other) {
+    return slop == other.slop && 
+           Arrays.equals(terms, other.terms) && 
+           Arrays.equals(positions, other.positions);
   }
 
   /** Returns a hash code value for this object.*/
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = 31 * h + slop;
     h = 31 * h + Arrays.hashCode(terms);
     h = 31 * h + Arrays.hashCode(positions);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
index 0549077..c19e457 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
@@ -305,7 +305,7 @@ public abstract class PointInSetQuery extends Query {
 
   @Override
   public final int hashCode() {
-    int hash = super.hashCode();
+    int hash = classHash();
     hash = 31 * hash + field.hashCode();
     hash = 31 * hash + sortedPackedPointsHashCode;
     hash = 31 * hash + numDims;
@@ -315,16 +315,16 @@ public abstract class PointInSetQuery extends Query {
 
   @Override
   public final boolean equals(Object other) {
-    if (super.equals(other)) {
-      final PointInSetQuery q = (PointInSetQuery) other;
-      return q.field.equals(field) &&
-        q.numDims == numDims &&
-        q.bytesPerDim == bytesPerDim &&
-        q.sortedPackedPointsHashCode == sortedPackedPointsHashCode &&
-        q.sortedPackedPoints.equals(sortedPackedPoints);
-    }
-
-    return false;
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(PointInSetQuery other) {
+    return other.field.equals(field) &&
+           other.numDims == numDims &&
+           other.bytesPerDim == bytesPerDim &&
+           other.sortedPackedPointsHashCode == sortedPackedPointsHashCode &&
+           other.sortedPackedPoints.equals(sortedPackedPoints);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
index abd4cbc..fb7051d 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -220,7 +220,7 @@ public abstract class PointRangeQuery extends Query {
 
   @Override
   public final int hashCode() {
-    int hash = super.hashCode();
+    int hash = classHash();
     hash = 31 * hash + field.hashCode();
     hash = 31 * hash + Arrays.hashCode(lowerPoint);
     hash = 31 * hash + Arrays.hashCode(upperPoint);
@@ -230,33 +230,17 @@ public abstract class PointRangeQuery extends Query {
   }
 
   @Override
-  public final boolean equals(Object other) {
-    if (super.equals(other) == false) {
-      return false;
-    }
-
-    final PointRangeQuery q = (PointRangeQuery) other;
-    if (field.equals(q.field) == false) {
-      return false;
-    }
-
-    if (q.numDims != numDims) {
-      return false;
-    }
-
-    if (q.bytesPerDim != bytesPerDim) {
-      return false;
-    }
-
-    if (Arrays.equals(lowerPoint, q.lowerPoint) == false) {
-      return false;
-    }
-    
-    if (Arrays.equals(upperPoint, q.upperPoint) == false) {
-      return false;
-    }
+  public final boolean equals(Object o) {
+    return sameClassAs(o) &&
+           equalsTo(getClass().cast(o));
+  }
 
-    return true;
+  private boolean equalsTo(PointRangeQuery other) {
+    return Objects.equals(field, other.field) &&
+           numDims == other.numDims &&
+           bytesPerDim == other.bytesPerDim &&
+           Arrays.equals(lowerPoint, other.lowerPoint) &&
+           Arrays.equals(upperPoint, other.upperPoint);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/Query.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/Query.java b/lucene/core/src/java/org/apache/lucene/search/Query.java
index 49134ec..8cab2d1 100644
--- a/lucene/core/src/java/org/apache/lucene/search/Query.java
+++ b/lucene/core/src/java/org/apache/lucene/search/Query.java
@@ -74,15 +74,50 @@ public abstract class Query {
     return this;
   }
 
+  /**
+   * Override and implement query instance equivalence properly in a subclass. 
+   * This is required so that {@link QueryCache} works properly.
+   * 
+   * Typically a query will be equal to another only if it's an instance of 
+   * the same class and its document-filtering properties are identical that other
+   * instance. Utility methods are provided for certain repetitive code. 
+   * 
+   * @see #sameClassAs(Object)
+   * @see #classHash()
+   */
   @Override
-  public int hashCode() {
-    return getClass().hashCode();
-  }
+  public abstract boolean equals(Object obj);
 
+  /**
+   * Override and implement query hash code properly in a subclass. 
+   * This is required so that {@link QueryCache} works properly.
+   * 
+   * @see #equals(Object)
+   */
   @Override
-  public boolean equals(Object obj) {
-    if (obj == null)
-      return false;
-    return getClass() == obj.getClass();
+  public abstract int hashCode();
+
+  /**
+   * Utility method to check whether <code>other</code> is not null and is exactly 
+   * of the same class as this object's class.
+   * 
+   * When this method is used in an implementation of {@link #equals(Object)},
+   * consider using {@link #classHash()} in the implementation
+   * of {@link #hashCode} to differentiate different class
+   */
+  protected final boolean sameClassAs(Object other) {
+    return other != null && getClass() == other.getClass();
+  }
+
+  private final int CLASS_NAME_HASH = getClass().getName().hashCode();
+
+  /**
+   * Provides a constant integer for a given class, derived from the name of the class.
+   * The rationale for not using just {@link Class#hashCode()} is that classes may be
+   * assigned different hash codes for each execution and we want hashes to be possibly
+   * consistent to facilitate debugging.    
+   */
+  protected final int classHash() {
+    return CLASS_NAME_HASH;
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java
index 4a0ca56..4d49cd9 100644
--- a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java
@@ -88,20 +88,13 @@ public final class SynonymQuery extends Query {
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = super.hashCode();
-    result = prime * result + Arrays.hashCode(terms);
-    return result;
+    return 31 * classHash() + Arrays.hashCode(terms);
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (this == obj) return true;
-    if (!super.equals(obj)) return false;
-    if (getClass() != obj.getClass()) return false;
-    SynonymQuery other = (SynonymQuery) obj;
-    if (!Arrays.equals(terms, other.terms)) return false;
-    return true;
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           Arrays.equals(terms, ((SynonymQuery) other).terms);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
index b7b6d29..e815ff6 100644
--- a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
@@ -211,14 +211,13 @@ public class TermQuery extends Query {
 
   /** Returns true iff <code>o</code> is equal to this. */
   @Override
-  public boolean equals(Object o) {
-    if (!(o instanceof TermQuery)) return false;
-    TermQuery other = (TermQuery) o;
-    return super.equals(o) && this.term.equals(other.term);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           term.equals(((TermQuery) other).term);
   }
 
   @Override
   public int hashCode() {
-    return super.hashCode() ^ term.hashCode();
+    return classHash() ^ term.hashCode();
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
index 8a2dae3..5c5e4dc 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
@@ -95,8 +95,6 @@ public final class FieldMaskingSpanQuery extends SpanQuery {
 
   @Override
   public Query rewrite(IndexReader reader) throws IOException {
-    FieldMaskingSpanQuery clone = null;
-
     SpanQuery rewritten = (SpanQuery) maskedQuery.rewrite(reader);
     if (rewritten != maskedQuery) {
       return new FieldMaskingSpanQuery(rewritten, field);
@@ -117,20 +115,20 @@ public final class FieldMaskingSpanQuery extends SpanQuery {
   }
   
   @Override
-  public boolean equals(Object o) {
-    if (! super.equals(o)) {
-      return false;
-    }
-    FieldMaskingSpanQuery other = (FieldMaskingSpanQuery) o;
-    return (this.getField().equals(other.getField())
-            && this.getMaskedQuery().equals(other.getMaskedQuery()));
-
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
   }
   
+  private boolean equalsTo(FieldMaskingSpanQuery other) {
+    return getField().equals(other.getField()) && 
+           getMaskedQuery().equals(other.getMaskedQuery());
+  }
+
   @Override
   public int hashCode() {
-    return super.hashCode()
-          ^ getMaskedQuery().hashCode()
-          ^ getField().hashCode();
+    return classHash() ^ 
+           getMaskedQuery().hashCode() ^ 
+           getField().hashCode();
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java
index 911fdc0..9ecd743 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java
@@ -31,7 +31,6 @@ import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Scorer;
 
 /**
  * Counterpart of {@link BoostQuery} for spans.
@@ -63,18 +62,19 @@ public final class SpanBoostQuery extends SpanQuery {
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (super.equals(obj) == false) {
-      return false;
-    }
-    SpanBoostQuery that = (SpanBoostQuery) obj;
-    return query.equals(that.query)
-        && Float.floatToIntBits(boost) == Float.floatToIntBits(that.boost);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(SpanBoostQuery other) {
+    return query.equals(other.query) && 
+           Float.floatToIntBits(boost) == Float.floatToIntBits(other.boost);
   }
 
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = 31 * h + query.hashCode();
     h = 31 * h + Float.floatToIntBits(boost);
     return h;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java
index 551138d..b122a09 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainQuery.java
@@ -129,17 +129,19 @@ abstract class SpanContainQuery extends SpanQuery implements Cloneable {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (! super.equals(o)) {
-      return false;
-    }
-    SpanContainQuery other = (SpanContainQuery)o;
-    return big.equals(other.big) && little.equals(other.little);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  } 
+  
+  private boolean equalsTo(SpanContainQuery other) {
+    return big.equals(other.big) && 
+           little.equals(other.little);
   }
 
   @Override
   public int hashCode() {
-    int h = Integer.rotateLeft(super.hashCode(), 1);
+    int h = Integer.rotateLeft(classHash(), 1);
     h ^= big.hashCode();
     h = Integer.rotateLeft(h, 1);
     h ^= little.hashCode();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
index 95b7e93..f4c6f24 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
@@ -123,19 +123,13 @@ public class SpanMultiTermQueryWrapper<Q extends MultiTermQuery> extends SpanQue
   
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = super.hashCode();
-    result = prime * result + query.hashCode();
-    return result;
+    return classHash() * 31 + query.hashCode();
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (! super.equals(obj)) {
-      return false;
-    }
-    SpanMultiTermQueryWrapper<?> other = (SpanMultiTermQueryWrapper<?>) obj;
-    return query.equals(other.query);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           query.equals(((SpanMultiTermQueryWrapper<?>) other).query);
   }
 
   /** Abstract class that defines how the query is rewritten. */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
index d542227..217d75f 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
@@ -253,22 +253,21 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
     return super.rewrite(reader);
   }
 
-  /** Returns true iff <code>o</code> is equal to this. */
   @Override
-  public boolean equals(Object o) {
-    if (! super.equals(o)) {
-      return false;
-    }
-    final SpanNearQuery spanNearQuery = (SpanNearQuery) o;
-
-    return (inOrder == spanNearQuery.inOrder)
-        && (slop == spanNearQuery.slop)
-        && clauses.equals(spanNearQuery.clauses);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(SpanNearQuery other) {
+    return inOrder == other.inOrder && 
+           slop == other.slop &&
+           clauses.equals(other.clauses);
   }
 
   @Override
   public int hashCode() {
-    int result = super.hashCode();
+    int result = classHash();
     result ^= clauses.hashCode();
     result += slop;
     int fac = 1 + (inOrder ? 8 : 4);
@@ -321,6 +320,25 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
 
       }
     }
+
+    @Override
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             equalsTo(getClass().cast(other));
+    }
+    
+    private boolean equalsTo(SpanGapQuery other) {
+      return width == other.width &&
+             field.equals(other.field);
+    }
+
+    @Override
+    public int hashCode() {
+      int result = classHash();
+      result -= 7 * width;
+      return result * 15 - field.hashCode();
+    }
+
   }
 
   static class GapSpans extends Spans {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
index 5b2aeac..9b07abf 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
@@ -200,20 +200,21 @@ public final class SpanNotQuery extends SpanQuery {
   }
     /** Returns true iff <code>o</code> is equal to this. */
   @Override
-  public boolean equals(Object o) {
-    if (!super.equals(o))
-      return false;
-
-    SpanNotQuery other = (SpanNotQuery)o;
-    return this.include.equals(other.include)
-            && this.exclude.equals(other.exclude)
-            && this.pre == other.pre
-            && this.post == other.post;
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  } 
+
+  private boolean equalsTo(SpanNotQuery other) { 
+    return include.equals(other.include) && 
+           exclude.equals(other.exclude) && 
+           pre == other.pre && 
+           post == other.post;
   }
 
   @Override
   public int hashCode() {
-    int h = super.hashCode();
+    int h = classHash();
     h = Integer.rotateLeft(h, 1);
     h ^= include.hashCode();
     h = Integer.rotateLeft(h, 1);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
index c07ec38..37e5863 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
@@ -103,19 +103,14 @@ public final class SpanOrQuery extends SpanQuery {
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (! super.equals(o)) {
-      return false;
-    }
-    final SpanOrQuery that = (SpanOrQuery) o;
-    return clauses.equals(that.clauses);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           clauses.equals(((SpanOrQuery) other).clauses);
   }
 
   @Override
   public int hashCode() {
-    int h = super.hashCode();
-    h = (h * 7) ^ clauses.hashCode();
-    return h;
+    return classHash() ^ clauses.hashCode();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
index b2166e4..21c3a03 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
@@ -120,18 +120,15 @@ public abstract class SpanPositionCheckQuery extends SpanQuery implements Clonea
     return super.rewrite(reader);
   }
 
-  /** Returns true iff <code>o</code> is equal to this. */
+  /** Returns true iff <code>other</code> is equal to this. */
   @Override
-  public boolean equals(Object o) {
-    if (! super.equals(o)) {
-      return false;
-    }
-    SpanPositionCheckQuery spcq = (SpanPositionCheckQuery) o;
-    return match.equals(spcq.match);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           match.equals(((SpanPositionCheckQuery) other).match);
   }
 
   @Override
   public int hashCode() {
-    return match.hashCode() ^ super.hashCode();
+    return classHash() ^ match.hashCode();
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
index bf6c6d0..43e0dcc 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
@@ -163,19 +163,13 @@ public class SpanTermQuery extends SpanQuery {
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = super.hashCode();
-    result = prime * result + term.hashCode();
-    return result;
+    return classHash() ^ term.hashCode();
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (! super.equals(obj)) {
-      return false;
-    }
-    SpanTermQuery other = (SpanTermQuery) obj;
-    return term.equals(other.term);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           term.equals(((SpanTermQuery) other).term);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
index ca586cf..b46a46e 100644
--- a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
+++ b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
@@ -28,7 +28,7 @@ import org.apache.lucene.util.PriorityQueue;
 
 /**
  * Holds all implementations of classes in the o.a.l.search package as a
- * back-compatibility test. It does not run any tests per-se, however if 
+ * back-compatibility test. It does not run any tests per-se, however if
  * someone adds a method to an interface or abstract method to an abstract
  * class, one of the implementations here will fail to compile and so we know
  * back-compat policy was violated.
@@ -59,7 +59,7 @@ final class JustCompileSearch {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
   }
-  
+
   static final class JustCompileDocIdSet extends DocIdSet {
 
     @Override
@@ -84,18 +84,18 @@ final class JustCompileSearch {
     public int nextDoc() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
     @Override
     public int advance(int target) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
     @Override
     public long cost() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
   }
-  
+
   static final class JustCompileFieldComparator extends FieldComparator<Object> {
 
     @Override
@@ -126,7 +126,7 @@ final class JustCompileSearch {
         int sortPos, boolean reversed) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
   }
 
   static final class JustCompileFilteredDocIdSetIterator extends FilteredDocIdSetIterator {
@@ -139,7 +139,7 @@ final class JustCompileSearch {
     protected boolean match(int doc) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
     @Override
     public long cost() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
@@ -152,9 +152,18 @@ final class JustCompileSearch {
     public String toString(String field) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
+    @Override
+    public boolean equals(Object obj) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    @Override
+    public int hashCode() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
   }
-  
+
   static final class JustCompileScorer extends Scorer {
 
     protected JustCompileScorer(Weight weight) {
@@ -165,7 +174,7 @@ final class JustCompileSearch {
     public float score() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
     @Override
     public int freq() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
@@ -181,7 +190,7 @@ final class JustCompileSearch {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
   }
-  
+
   static final class JustCompileSimilarity extends Similarity {
 
     @Override
@@ -264,5 +273,5 @@ final class JustCompileSearch {
     }
 
   }
-  
+
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
index df1be3e..90c86c8 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
@@ -39,7 +39,7 @@ import org.apache.lucene.util.TestUtil;
 
 public class TestBooleanScorer extends LuceneTestCase {
   private static final String FIELD = "category";
-  
+
   public void testMethod() throws Exception {
     Directory directory = newDirectory();
 
@@ -122,6 +122,16 @@ public class TestBooleanScorer extends LuceneTestCase {
         }
       };
     }
+
+    @Override
+    public boolean equals(Object obj) {
+      return this == obj;
+    }
+
+    @Override
+    public int hashCode() {
+      return System.identityHashCode(this);
+    }
   }
 
   /** Make sure BooleanScorer can embed another

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
index 2253294..0a49259 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
@@ -148,17 +148,14 @@ public class TestConstantScoreQuery extends LuceneTestCase {
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (super.equals(obj) == false) {
-        return false;
-      }
-      QueryWrapper that = (QueryWrapper) obj;
-      return in.equals(that.in);
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             in.equals(((QueryWrapper) other).in);
     }
 
     @Override
     public int hashCode() {
-      return 31 * super.hashCode() + in.hashCode();
+      return 31 * classHash() + in.hashCode();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
index 63ccdd8..48dcdf0 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
@@ -357,11 +357,9 @@ public class TestLRUQueryCache extends LuceneTestCase {
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (obj instanceof DummyQuery == false) {
-        return false;
-      }
-      return id == ((DummyQuery) obj).id;
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             id == ((DummyQuery) other).id;
     }
 
     @Override
@@ -950,9 +948,14 @@ public class TestLRUQueryCache extends LuceneTestCase {
 
     @Override
     public int hashCode() {
-      return super.hashCode() ^ i[0];
+      return classHash() ^ i[0];
     }
 
+    @Override
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             i[0] == ((BadQuery) other).i[0];
+    }
   }
 
   public void testDetectMutatedQueries() throws IOException {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java b/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
index fa63759..2723ce8 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
@@ -19,6 +19,7 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 import java.util.Set;
+import java.util.Objects;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -95,7 +96,7 @@ public class TestNeedsScores extends LuceneTestCase {
     final boolean value;
     
     AssertNeedsScores(Query in, boolean value) {
-      this.in = in;
+      this.in = Objects.requireNonNull(in);
       this.value = value;
     }
 
@@ -144,23 +145,21 @@ public class TestNeedsScores extends LuceneTestCase {
     @Override
     public int hashCode() {
       final int prime = 31;
-      int result = super.hashCode();
-      result = prime * result + ((in == null) ? 0 : in.hashCode());
+      int result = classHash();
+      result = prime * result + in.hashCode();
       result = prime * result + (value ? 1231 : 1237);
       return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (this == obj) return true;
-      if (!super.equals(obj)) return false;
-      if (getClass() != obj.getClass()) return false;
-      AssertNeedsScores other = (AssertNeedsScores) obj;
-      if (in == null) {
-        if (other.in != null) return false;
-      } else if (!in.equals(other.in)) return false;
-      if (value != other.value) return false;
-      return true;
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             equalsTo(getClass().cast(other));
+    }
+    
+    private boolean equalsTo(AssertNeedsScores other) {
+      return in.equals(other.in) && 
+             value == other.value;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
index d029e01..c0428f4 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
@@ -503,30 +503,27 @@ public class TestQueryRescorer extends LuceneTestCase {
     }
 
     @Override
-    public boolean equals(Object o) {
-      if ((o instanceof FixedScoreQuery) == false) {
-        return false;
-      }
-      FixedScoreQuery other = (FixedScoreQuery) o;
-      return super.equals(o) &&
-        reverse == other.reverse &&
-        Arrays.equals(idToNum, other.idToNum);
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             equalsTo(getClass().cast(other));
     }
 
-    @Override
-    public Query clone() {
-      return new FixedScoreQuery(idToNum, reverse);
+    private boolean equalsTo(FixedScoreQuery other) {
+      return reverse == other.reverse && 
+             Arrays.equals(idToNum, other.idToNum);
     }
 
     @Override
     public int hashCode() {
-      int PRIME = 31;
-      int hash = super.hashCode();
-      if (reverse) {
-        hash = PRIME * hash + 3623;
-      }
-      hash = PRIME * hash + Arrays.hashCode(idToNum);
+      int hash = classHash();
+      hash = 31 * hash + (reverse ? 0 : 1);
+      hash = 31 * hash + Arrays.hashCode(idToNum);
       return hash;
     }
+
+    @Override
+    public Query clone() {
+      return new FixedScoreQuery(idToNum, reverse);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java b/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java
index 82d5e18..4b1a4d2 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java
@@ -165,16 +165,14 @@ public class TestScorerPerf extends LuceneTestCase {
     }
     
     @Override
-    public boolean equals(Object obj) {
-      if (super.equals(obj) == false) {
-        return false;
-      }
-      return docs == ((BitSetQuery) obj).docs;
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             docs.equals(((BitSetQuery) other).docs);
     }
 
     @Override
     public int hashCode() {
-      return 31 * super.hashCode() + System.identityHashCode(docs);
+      return 31 * classHash() + docs.hashCode();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java b/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java
index c362fd6..32bce9e 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java
@@ -257,19 +257,21 @@ public class TestSortRandom extends LuceneTestCase {
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (super.equals(obj) == false) {
-        return false;
-      }
-      RandomQuery other = (RandomQuery) obj;
-      return seed == other.seed && docValues == other.docValues;
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             equalsTo(getClass().cast(other));
+    }
+    
+    private boolean equalsTo(RandomQuery other) {
+      return seed == other.seed && 
+             docValues == other.docValues;
     }
 
     @Override
     public int hashCode() {
       int h = Objects.hash(seed, density);
       h = 31 * h + System.identityHashCode(docValues);
-      h = 31 * h + super.hashCode();
+      h = 31 * h + classHash();
       return h;
     }
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java b/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
index f844795..6e6102f 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
@@ -48,7 +48,7 @@ final class JustCompileSearchSpans {
     public int advance(int target) throws IOException {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
     @Override
     public int startPosition() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
@@ -101,7 +101,17 @@ final class JustCompileSearchSpans {
     public String toString(String field) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
+    @Override
+    public boolean equals(Object o) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    @Override
+    public int hashCode() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java
index 91d5b0f..bb52ede 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java
@@ -122,19 +122,20 @@ public final class DrillDownQuery extends Query {
   
   @Override
   public int hashCode() {
-    return 31 * super.hashCode() + Objects.hash(baseQuery, dimQueries);
+    return classHash() + Objects.hash(baseQuery, dimQueries);
   }
-  
+
   @Override
-  public boolean equals(Object obj) {
-    if (super.equals(obj) == false) {
-      return false;
-    }
-    DrillDownQuery other = (DrillDownQuery) obj;
-    return Objects.equals(baseQuery, other.baseQuery)
-        && dimQueries.equals(other.dimQueries);
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
   }
-  
+
+  private boolean equalsTo(DrillDownQuery other) {
+    return Objects.equals(baseQuery, other.baseQuery) && 
+           dimQueries.equals(other.dimQueries);
+  }
+
   @Override
   public Query rewrite(IndexReader r) throws IOException {
     BooleanQuery rewritten = getBooleanQuery();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
index b3ffb0d..48883ea 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
@@ -161,29 +161,24 @@ class DrillSidewaysQuery extends Query {
   @Override
   public int hashCode() {
     final int prime = 31;
-    int result = super.hashCode();
-    result = prime * result + ((baseQuery == null) ? 0 : baseQuery.hashCode());
-    result = prime * result
-        + ((drillDownCollector == null) ? 0 : drillDownCollector.hashCode());
+    int result = classHash();
+    result = prime * result + Objects.hashCode(baseQuery);
+    result = prime * result + Objects.hashCode(drillDownCollector);
     result = prime * result + Arrays.hashCode(drillDownQueries);
     result = prime * result + Arrays.hashCode(drillSidewaysCollectors);
     return result;
   }
 
   @Override
-  public boolean equals(Object obj) {
-    if (this == obj) return true;
-    if (!super.equals(obj)) return false;
-    if (getClass() != obj.getClass()) return false;
-    DrillSidewaysQuery other = (DrillSidewaysQuery) obj;
-    if (baseQuery == null) {
-      if (other.baseQuery != null) return false;
-    } else if (!baseQuery.equals(other.baseQuery)) return false;
-    if (drillDownCollector == null) {
-      if (other.drillDownCollector != null) return false;
-    } else if (!drillDownCollector.equals(other.drillDownCollector)) return false;
-    if (!Arrays.equals(drillDownQueries, other.drillDownQueries)) return false;
-    if (!Arrays.equals(drillSidewaysCollectors, other.drillSidewaysCollectors)) return false;
-    return true;
+  public boolean equals(Object other) {
+    return sameClassAs(other) &&
+           equalsTo(getClass().cast(other));
+  }
+  
+  private boolean equalsTo(DrillSidewaysQuery other) {
+    return Objects.equals(baseQuery, other.baseQuery) &&
+           Objects.equals(drillDownCollector, other.drillDownCollector) &&
+           Arrays.equals(drillDownQueries, other.drillDownQueries) &&
+           Arrays.equals(drillSidewaysCollectors, other.drillSidewaysCollectors);
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
index 6f005ed..8893c65 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
@@ -104,19 +104,20 @@ public final class DoubleRange extends Range {
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (super.equals(obj) == false) {
-        return false;
-      }
-      ValueSourceQuery other = (ValueSourceQuery) obj;
-      return range.equals(other.range)
-          && Objects.equals(fastMatchQuery, other.fastMatchQuery)
-          && valueSource.equals(other.valueSource);
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             equalsTo(getClass().cast(other));
+    }
+
+    private boolean equalsTo(ValueSourceQuery other) {
+      return range.equals(other.range) && 
+             Objects.equals(fastMatchQuery, other.fastMatchQuery) && 
+             valueSource.equals(other.valueSource);
     }
 
     @Override
     public int hashCode() {
-      return 31 * Objects.hash(range, fastMatchQuery, valueSource) + super.hashCode();
+      return classHash() + 31 * Objects.hash(range, fastMatchQuery, valueSource);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
index ef789c5..46ee00b 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
@@ -96,19 +96,20 @@ public final class LongRange extends Range {
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (super.equals(obj) == false) {
-        return false;
-      }
-      ValueSourceQuery other = (ValueSourceQuery) obj;
-      return range.equals(other.range)
-          && Objects.equals(fastMatchQuery, other.fastMatchQuery)
-          && valueSource.equals(other.valueSource);
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             equalsTo(getClass().cast(other));
+    }
+
+    private boolean equalsTo(ValueSourceQuery other) {
+      return range.equals(other.range) && 
+             Objects.equals(fastMatchQuery, other.fastMatchQuery) && 
+             valueSource.equals(other.valueSource);
     }
 
     @Override
     public int hashCode() {
-      return 31 * Objects.hash(range, fastMatchQuery, valueSource) + super.hashCode();
+      return classHash() + 31 * Objects.hash(range, fastMatchQuery, valueSource);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
index e37215e..97247e0 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
@@ -117,7 +117,7 @@ public class TestDrillSideways extends FacetTestCase {
 
     //  case: drill-down on a single field; in this
     // case the drill-sideways + drill-down counts ==
-    // drill-down of just the query: 
+    // drill-down of just the query:
     DrillDownQuery ddq = new DrillDownQuery(config);
     ddq.add("Author", "Lisa");
     DrillSidewaysResult r = ds.search(null, ddq, 10);
@@ -361,7 +361,7 @@ public class TestDrillSideways extends FacetTestCase {
     String contentToken;
 
     public Doc() {}
-    
+
     // -1 if the doc is missing this dim, else the index
     // -into the values for this dim:
     int[] dims;
@@ -437,7 +437,7 @@ public class TestDrillSideways extends FacetTestCase {
         if (s.length() > 0) {
           values.add(s);
         }
-      } 
+      }
       dimValues[dim] = values.toArray(new String[values.size()]);
       valueCount *= 2;
     }
@@ -560,7 +560,7 @@ public class TestDrillSideways extends FacetTestCase {
 
     final SortedSetDocValuesReaderState sortedSetDVState;
     IndexSearcher s = newSearcher(r);
-    
+
     if (doUseDV) {
       sortedSetDVState = new DefaultSortedSetDocValuesReaderState(s.getIndexReader());
     } else {
@@ -669,7 +669,7 @@ public class TestDrillSideways extends FacetTestCase {
                   public int length() {
                     return context.reader().maxDoc();
                   }
-                  
+
                 };
               }
             };
@@ -680,6 +680,15 @@ public class TestDrillSideways extends FacetTestCase {
             return "drillSidewaysTestFilter";
           }
 
+          @Override
+          public boolean equals(Object o) {
+            return o == this;
+          }
+
+          @Override
+          public int hashCode() {
+            return System.identityHashCode(this);
+          }
         };
       } else {
         filter = null;
@@ -823,7 +832,7 @@ public class TestDrillSideways extends FacetTestCase {
     int[] uniqueCounts;
     public TestFacetResult() {}
   }
-  
+
   private int[] getTopNOrds(final int[] counts, final String[] values, int topN) {
     final int[] ids = new int[counts.length];
     for(int i=0;i<ids.length;i++) {
@@ -1050,7 +1059,7 @@ public class TestDrillSideways extends FacetTestCase {
             if (expected.counts[dim][i] != 0) {
               System.out.println("        " + idx + ": " + new BytesRef(value) + ": " + expected.counts[dim][i]);
               idx++;
-            } 
+            }
           }
         }
 
@@ -1084,7 +1093,7 @@ public class TestDrillSideways extends FacetTestCase {
     DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
     DrillDownQuery ddq = new DrillDownQuery(config);
     ddq.add("Author", "Lisa");
-    
+
     DrillSidewaysResult r = ds.search(ddq, 10); // this used to fail on IllegalArgEx
     assertEquals(0, r.hits.totalHits);
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
index 18645e7..b9ff1ce 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
@@ -658,17 +658,14 @@ public class TestRangeFacetCounts extends FacetTestCase {
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (super.equals(obj) == false) {
-        return false;
-      }
-      UsedQuery that = (UsedQuery) obj;
-      return in.equals(that.in);
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             in.equals(((UsedQuery) other).in);
     }
 
     @Override
     public int hashCode() {
-      return 31 * super.hashCode() + in.hashCode();
+      return classHash() + in.hashCode();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
index 0a034f1..3c6f108 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
@@ -222,8 +222,8 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
     fragment = highlighter.getBestFragment(stream, storedField);
     assertEquals("This piece of text refers to Kennedy at the beginning then has a longer piece of text that is <B>very</B>", fragment);
   }
-  
-  public void testHighlightUnknowQueryAfterRewrite() throws IOException, InvalidTokenOffsetsException {
+
+  public void testHighlightUnknownQueryAfterRewrite() throws IOException, InvalidTokenOffsetsException {
     Query query = new Query() {
       
       @Override
@@ -242,12 +242,12 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
 
       @Override
       public int hashCode() {
-        return 31 * super.hashCode();
+        return System.identityHashCode(this);
       }
 
       @Override
       public boolean equals(Object obj) {
-        return super.equals(obj);
+        return obj == this;
       }
     };
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d6264eb4/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java
index bbb3bb9..a54687d 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/custom/HighlightCustomQueryTest.java
@@ -38,6 +38,7 @@ import org.apache.lucene.util.LuceneTestCase;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * Tests the extensibility of {@link WeightedSpanTermExtractor} and
@@ -161,7 +162,6 @@ public class HighlightCustomQueryTest extends LuceneTestCase {
     private final Term term;
 
     public CustomQuery(Term term) {
-      super();
       this.term = term;
     }
 
@@ -177,28 +177,13 @@ public class HighlightCustomQueryTest extends LuceneTestCase {
 
     @Override
     public int hashCode() {
-      final int prime = 31;
-      int result = super.hashCode();
-      result = prime * result + ((term == null) ? 0 : term.hashCode());
-      return result;
+      return classHash() + Objects.hashCode(term);
     }
 
     @Override
-    public boolean equals(Object obj) {
-      if (this == obj)
-        return true;
-      if (!super.equals(obj))
-        return false;
-      if (getClass() != obj.getClass())
-        return false;
-      CustomQuery other = (CustomQuery) obj;
-      if (term == null) {
-        if (other.term != null)
-          return false;
-      } else if (!term.equals(other.term))
-        return false;
-      return true;
+    public boolean equals(Object other) {
+      return sameClassAs(other) &&
+             Objects.equals(term, ((CustomQuery) other).term);
     }
-
   }
 }


Mime
View raw message