Query refactoring: simplify equals implementation and dedup code
Closes #11818
This commit is contained in:
parent
0da9f2038f
commit
7653376ece
|
@ -66,6 +66,38 @@ public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXC
|
|||
return null;
|
||||
}
|
||||
|
||||
//norelease remove this once all builders implement readFrom themselves
|
||||
@Override
|
||||
public QB readFrom(StreamInput in) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
//norelease remove this once all builders implement writeTo themselves
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
QB other = (QB) obj;
|
||||
return doEquals(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether some other {@link QueryBuilder} object of the same type is "equal to" this one.
|
||||
*/
|
||||
//norelease to be made abstract once all queries are refactored
|
||||
protected boolean doEquals(QB other) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper method checks if the object passed in is a string, if so it
|
||||
* converts it to a {@link BytesRef}.
|
||||
|
@ -112,15 +144,4 @@ public abstract class AbstractQueryBuilder<QB extends QueryBuilder> extends ToXC
|
|||
}
|
||||
return queries;
|
||||
}
|
||||
|
||||
//norelease remove this once all builders implement readFrom themselves
|
||||
@Override
|
||||
public QB readFrom(StreamInput in) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
//norelease remove this once all builders implement writeTo themselves
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,14 +136,7 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
AndQueryBuilder other = (AndQueryBuilder) obj;
|
||||
public boolean doEquals(AndQueryBuilder other) {
|
||||
return Objects.equals(filters, other.filters) &&
|
||||
Objects.equals(queryName, other.queryName);
|
||||
}
|
||||
|
|
|
@ -194,14 +194,7 @@ public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BaseTermQueryBuilder other = (BaseTermQueryBuilder) obj;
|
||||
public final boolean doEquals(BaseTermQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(value, other.value) &&
|
||||
Objects.equals(boost, other.boost) &&
|
||||
|
|
|
@ -335,14 +335,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BoolQueryBuilder other = (BoolQueryBuilder) obj;
|
||||
public boolean doEquals(BoolQueryBuilder other) {
|
||||
return Objects.equals(boost, other.boost) &&
|
||||
Objects.equals(adjustPureNegative, other.adjustPureNegative) &&
|
||||
Objects.equals(disableCoord, other.disableCoord) &&
|
||||
|
|
|
@ -176,14 +176,7 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BoostingQueryBuilder other = (BoostingQueryBuilder) obj;
|
||||
public boolean doEquals(BoostingQueryBuilder other) {
|
||||
return Objects.equals(this.boost, other.boost) &&
|
||||
Objects.equals(this.negativeBoost, other.negativeBoost) &&
|
||||
Objects.equals(this.positiveQuery, other.positiveQuery) &&
|
||||
|
|
|
@ -114,14 +114,7 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ConstantScoreQueryBuilder other = (ConstantScoreQueryBuilder) obj;
|
||||
public boolean doEquals(ConstantScoreQueryBuilder other) {
|
||||
return Objects.equals(boost, other.boost) &&
|
||||
Objects.equals(filterBuilder, other.filterBuilder);
|
||||
}
|
||||
|
|
|
@ -181,14 +181,7 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DisMaxQueryBuilder other = (DisMaxQueryBuilder) obj;
|
||||
public boolean doEquals(DisMaxQueryBuilder other) {
|
||||
return Objects.equals(queries, other.queries) &&
|
||||
Objects.equals(tieBreaker, other.tieBreaker) &&
|
||||
Objects.equals(boost, other.boost) &&
|
||||
|
|
|
@ -141,14 +141,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ExistsQueryBuilder other = (ExistsQueryBuilder) obj;
|
||||
public boolean doEquals(ExistsQueryBuilder other) {
|
||||
return Objects.equals(name, other.name) &&
|
||||
Objects.equals(queryName, other.queryName);
|
||||
}
|
||||
|
|
|
@ -110,14 +110,7 @@ public class FQueryFilterBuilder extends AbstractQueryBuilder<FQueryFilterBuilde
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
FQueryFilterBuilder other = (FQueryFilterBuilder) obj;
|
||||
public boolean doEquals(FQueryFilterBuilder other) {
|
||||
return Objects.equals(queryBuilder, other.queryBuilder) &&
|
||||
Objects.equals(queryName, other.queryName);
|
||||
}
|
||||
|
|
|
@ -161,14 +161,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
FieldMaskingSpanQueryBuilder other = (FieldMaskingSpanQueryBuilder) obj;
|
||||
public boolean doEquals(FieldMaskingSpanQueryBuilder other) {
|
||||
return Objects.equals(queryBuilder, other.queryBuilder) &&
|
||||
Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(boost, other.boost) &&
|
||||
|
|
|
@ -217,14 +217,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
IdsQueryBuilder other = (IdsQueryBuilder) obj;
|
||||
public boolean doEquals(IdsQueryBuilder other) {
|
||||
return Objects.equals(ids, other.ids) &&
|
||||
Arrays.equals(types, other.types) &&
|
||||
Objects.equals(boost, other.boost) &&
|
||||
|
|
|
@ -56,15 +56,8 @@ public class LimitQueryBuilder extends AbstractQueryBuilder<LimitQueryBuilder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
LimitQueryBuilder that = (LimitQueryBuilder) o;
|
||||
return Integer.compare(that.limit, limit) == 0;
|
||||
public boolean doEquals(LimitQueryBuilder other) {
|
||||
return Integer.compare(other.limit, limit) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,15 +76,8 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuil
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MatchAllQueryBuilder that = (MatchAllQueryBuilder) o;
|
||||
return Float.compare(that.boost, boost) == 0;
|
||||
public boolean doEquals(MatchAllQueryBuilder other) {
|
||||
return Float.compare(other.boost, boost) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -108,14 +108,7 @@ public class NotQueryBuilder extends AbstractQueryBuilder<NotQueryBuilder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
NotQueryBuilder other = (NotQueryBuilder) obj;
|
||||
public boolean doEquals(NotQueryBuilder other) {
|
||||
return Objects.equals(filter, other.filter) &&
|
||||
Objects.equals(queryName, other.queryName);
|
||||
}
|
||||
|
|
|
@ -135,14 +135,7 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
OrQueryBuilder other = (OrQueryBuilder) obj;
|
||||
public boolean doEquals(OrQueryBuilder other) {
|
||||
return Objects.equals(filters, other.filters) &&
|
||||
Objects.equals(queryName, other.queryName);
|
||||
}
|
||||
|
|
|
@ -83,14 +83,7 @@ public class QueryFilterBuilder extends AbstractQueryBuilder<QueryFilterBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
QueryFilterBuilder other = (QueryFilterBuilder) obj;
|
||||
public boolean doEquals(QueryFilterBuilder other) {
|
||||
return Objects.equals(queryBuilder, other.queryBuilder);
|
||||
}
|
||||
|
||||
|
|
|
@ -378,14 +378,7 @@ public class RangeQueryBuilder extends MultiTermQueryBuilder<RangeQueryBuilder>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RangeQueryBuilder other = (RangeQueryBuilder) obj;
|
||||
public boolean doEquals(RangeQueryBuilder other) {
|
||||
return Objects.equals(fieldName, other.fieldName) &&
|
||||
Objects.equals(from, other.from) &&
|
||||
Objects.equals(to, other.to) &&
|
||||
|
|
Loading…
Reference in New Issue