SQL: Fix checkstyle / add missing hashCode (elastic/x-pack-elasticsearch#3323)

* Fix checkstyle / add missing hashCode
* Improve formatting

Original commit: elastic/x-pack-elasticsearch@a3ad2793bb
This commit is contained in:
Costin Leau 2017-12-14 17:17:26 +02:00 committed by GitHub
parent 59e6d34c29
commit 624a1530c0
10 changed files with 82 additions and 48 deletions

View File

@ -9,7 +9,6 @@
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]SqlBase(Base(Listener|Visitor)|Lexer|Listener|Parser|Visitor).java" checks="." /> <suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]SqlBase(Base(Listener|Visitor)|Lexer|Listener|Parser|Visitor).java" checks="." />
<suppress files="sql[/\\]server[/\\].*.java" checks="LineLength" /> <suppress files="sql[/\\]server[/\\].*.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]expression[/\\].*.java" checks="EqualsHashCode" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]common[/\\]action[/\\]XPackDeleteByQueryAction.java" checks="LineLength" /> <suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]common[/\\]action[/\\]XPackDeleteByQueryAction.java" checks="LineLength" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]ml[/\\]action[/\\]StopDatafeedAction.java" checks="LineLength" /> <suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]ml[/\\]action[/\\]StopDatafeedAction.java" checks="LineLength" />

View File

@ -43,6 +43,7 @@ public abstract class Attribute extends NamedExpression {
return qualifier == null ? name() : qualifier + "." + name(); return qualifier == null ? name() : qualifier + "." + name();
} }
@Override
public boolean nullable() { public boolean nullable() {
return nullable; return nullable;
} }
@ -89,6 +90,22 @@ public abstract class Attribute extends NamedExpression {
return other instanceof Attribute ? id().equals(((Attribute) other).id()) : false; return other instanceof Attribute ? id().equals(((Attribute) other).id()) : false;
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), qualifier, nullable);
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
Attribute other = (Attribute) obj;
return Objects.equals(qualifier, other.qualifier)
&& Objects.equals(nullable, other.nullable);
}
return false;
}
@Override @Override
public String toString() { public String toString() {
return name() + "{" + label() + "}" + "#" + id(); return name() + "{" + label() + "}" + "#" + id();

View File

@ -5,11 +5,11 @@
*/ */
package org.elasticsearch.xpack.sql.expression; package org.elasticsearch.xpack.sql.expression;
import java.util.Objects;
import org.elasticsearch.xpack.sql.tree.Location; import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.type.DataType; import org.elasticsearch.xpack.sql.type.DataType;
import java.util.Objects;
public abstract class TypedAttribute extends Attribute { public abstract class TypedAttribute extends Attribute {
private final DataType dataType; private final DataType dataType;
@ -29,21 +29,17 @@ public abstract class TypedAttribute extends Attribute {
} }
@Override @Override
public boolean equals(Object obj) { public int hashCode() {
if (this == obj) { return Objects.hash(super.hashCode(), dataType);
return true; }
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
TypedAttribute other = (TypedAttribute) obj;
return Objects.equals(dataType, other.dataType);
} }
if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
TypedAttribute other = (TypedAttribute) obj;
return Objects.equals(name(), other.name())
&& Objects.equals(id(), other.id())
&& Objects.equals(nullable(), other.nullable())
&& Objects.equals(dataType(), other.dataType())
&& Objects.equals(qualifier(), other.qualifier())
&& Objects.equals(synthetic(), other.synthetic());
}
} }

View File

@ -34,18 +34,14 @@ public class UnresolvedAlias extends UnresolvedNamedExpression {
throw new UnresolvedException("nullable", this); throw new UnresolvedException("nullable", this);
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), child);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { return super.equals(obj) && Objects.equals(child, ((UnresolvedAlias) obj).child);
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
UnresolvedAlias other = (UnresolvedAlias) obj;
return Objects.equals(child, other.child);
} }
@Override @Override

View File

@ -92,6 +92,11 @@ public class UnresolvedAttribute extends Attribute implements Unresolvable {
return msg; return msg;
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), resolutionMetadata, unresolvedMsg);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (super.equals(obj)) { if (super.equals(obj)) {

View File

@ -31,20 +31,21 @@ public class UnresolvedStar extends UnresolvedNamedExpression {
return qualifier; return qualifier;
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), qualifier);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (super.equals(obj)) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
UnresolvedStar other = (UnresolvedStar) obj; UnresolvedStar other = (UnresolvedStar) obj;
return Objects.equals(qualifier, other.qualifier); return Objects.equals(qualifier, other.qualifier);
} }
return false;
}
private String message() { private String message() {
return (qualifier() != null ? qualifier() + "." : "") + "*"; return (qualifier() != null ? qualifier() + "." : "") + "*";
} }

View File

@ -26,6 +26,11 @@ public abstract class FunctionAttribute extends TypedAttribute {
return functionId; return functionId;
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), functionId);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(functionId, ((FunctionAttribute) obj).functionId()); return super.equals(obj) && Objects.equals(functionId, ((FunctionAttribute) obj).functionId());

View File

@ -47,6 +47,11 @@ public class AggregateFunctionAttribute extends FunctionAttribute {
return new AggregateFunctionAttribute(location(), name(), dataType(), qualifier(), nullable(), id(), synthetic(), functionId, propertyPath); return new AggregateFunctionAttribute(location(), name(), dataType(), qualifier(), nullable(), id(), synthetic(), functionId, propertyPath);
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), propertyPath);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(propertyPath(), ((AggregateFunctionAttribute) obj).propertyPath()); return super.equals(obj) && Objects.equals(propertyPath(), ((AggregateFunctionAttribute) obj).propertyPath());

View File

@ -77,6 +77,11 @@ public class Cast extends UnaryScalarFunction {
return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()), new CastProcessor(DataTypeConversion.conversionFor(from(), to()))); return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()), new CastProcessor(DataTypeConversion.conversionFor(from(), to())));
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dataType);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(dataType, ((Cast) obj).dataType()); return super.equals(obj) && Objects.equals(dataType, ((Cast) obj).dataType());

View File

@ -59,6 +59,11 @@ public class ScalarFunctionAttribute extends FunctionAttribute {
processorDef); processorDef);
} }
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), orderBy);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(orderBy, ((ScalarFunctionAttribute) obj).orderBy()); return super.equals(obj) && Objects.equals(orderBy, ((ScalarFunctionAttribute) obj).orderBy());