Skip to content

Commit

Permalink
Avoid primitive boxing for equals
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed May 10, 2024
1 parent 43a5d53 commit f054a9c
Show file tree
Hide file tree
Showing 35 changed files with 53 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean equals(Object obj)
}

ErrorInfo that = (ErrorInfo) obj;
return Objects.equals(this.code, that.code);
return this.code == that.code;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean equals(Object obj)
return false;
}
StageId other = (StageId) obj;
return Objects.equals(this.id, other.id) &&
return this.id == other.id &&
Objects.equals(this.queryId, other.queryId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public boolean equals(Object o)
return false;
}
BufferResult that = (BufferResult) o;
return Objects.equals(token, that.token) &&
Objects.equals(nextToken, that.nextToken) &&
return token == that.token &&
nextToken == that.nextToken &&
Objects.equals(taskInstanceId, that.taskInstanceId) &&
Objects.equals(bufferComplete, that.bufferComplete) &&
bufferComplete == that.bufferComplete &&
Objects.equals(serializedPages, that.serializedPages);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ public boolean equals(Object o)
}
OutputBufferInfo that = (OutputBufferInfo) o;
return Objects.equals(type, that.type) &&
Objects.equals(canAddBuffers, that.canAddBuffers) &&
Objects.equals(canAddPages, that.canAddPages) &&
Objects.equals(totalBufferedBytes, that.totalBufferedBytes) &&
Objects.equals(totalBufferedPages, that.totalBufferedPages) &&
Objects.equals(totalRowsSent, that.totalRowsSent) &&
Objects.equals(totalPagesSent, that.totalPagesSent) &&
canAddBuffers == that.canAddBuffers &&
canAddPages == that.canAddPages &&
totalBufferedBytes == that.totalBufferedBytes &&
totalBufferedPages == that.totalBufferedPages &&
totalRowsSent == that.totalRowsSent &&
totalPagesSent == that.totalPagesSent &&
state == that.state &&
Objects.equals(pipelinedBufferStates, that.pipelinedBufferStates) &&
Objects.equals(utilization, that.utilization);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public boolean equals(Object obj)

return this.type == other.type &&
this.startType == other.startType &&
Objects.equals(this.startChannel, other.startChannel) &&
Objects.equals(this.sortKeyChannelForStartComparison, other.sortKeyChannelForStartComparison) &&
this.startChannel == other.startChannel &&
this.sortKeyChannelForStartComparison == other.sortKeyChannelForStartComparison &&
this.endType == other.endType &&
Objects.equals(this.endChannel, other.endChannel) &&
Objects.equals(this.sortKeyChannelForEndComparison, other.sortKeyChannelForEndComparison) &&
Objects.equals(this.sortKeyChannel, other.sortKeyChannel) &&
this.endChannel == other.endChannel &&
this.sortKeyChannelForEndComparison == other.sortKeyChannelForEndComparison &&
this.sortKeyChannel == other.sortKeyChannel &&
Objects.equals(this.ordering, other.ordering);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public boolean equals(Object obj)
return false;
}
Constraint o = (Constraint) obj;
return Objects.equals(isNone, o.isNone) &&
return isNone == o.isNone &&
Objects.equals(columnConstraints, o.columnConstraints);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean equals(Object obj)
return false;
}
BooleanLiteral other = (BooleanLiteral) obj;
return Objects.equals(this.value, other.value);
return this.value == other.value;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public boolean equals(Object obj)
}
CreateCatalog o = (CreateCatalog) obj;
return Objects.equals(catalogName, o.catalogName) &&
Objects.equals(notExists, o.notExists) &&
notExists == o.notExists &&
Objects.equals(properties, o.properties) &&
Objects.equals(comment, o.comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean equals(Object obj)
{
return (obj instanceof CreateFunction other) &&
Objects.equals(specification, other.specification) &&
Objects.equals(replace, other.replace);
replace == other.replace;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public boolean equals(Object obj)
CreateMaterializedView o = (CreateMaterializedView) obj;
return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& Objects.equals(replace, o.replace)
&& Objects.equals(notExists, o.notExists)
&& replace == o.replace
&& notExists == o.notExists
&& Objects.equals(gracePeriod, o.gracePeriod)
&& Objects.equals(properties, o.properties)
&& Objects.equals(comment, o.comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean equals(Object obj)
}
CreateSchema o = (CreateSchema) obj;
return Objects.equals(schemaName, o.schemaName) &&
Objects.equals(notExists, o.notExists) &&
notExists == o.notExists &&
Objects.equals(properties, o.properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public boolean equals(Object obj)
CreateTableAsSelect o = (CreateTableAsSelect) obj;
return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& Objects.equals(saveMode, o.saveMode)
&& saveMode == o.saveMode
&& Objects.equals(properties, o.properties)
&& Objects.equals(withData, o.withData)
&& withData == o.withData
&& Objects.equals(columnAliases, o.columnAliases)
&& Objects.equals(comment, o.comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public boolean equals(Object obj)
CreateView o = (CreateView) obj;
return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& Objects.equals(replace, o.replace)
&& replace == o.replace
&& Objects.equals(comment, o.comment)
&& Objects.equals(security, o.security)
&& Objects.equals(properties, o.properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean equals(Object obj)
Except o = (Except) obj;
return Objects.equals(left, o.left) &&
Objects.equals(right, o.right) &&
Objects.equals(isDistinct(), o.isDistinct());
isDistinct() == o.isDistinct();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public boolean equals(Object obj)
Objects.equals(window, o.window) &&
Objects.equals(filter, o.filter) &&
Objects.equals(orderBy, o.orderBy) &&
Objects.equals(distinct, o.distinct) &&
distinct == o.distinct &&
Objects.equals(nullTreatment, o.nullTreatment) &&
Objects.equals(processingMode, o.processingMode) &&
Objects.equals(arguments, o.arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public boolean equals(Object obj)
return Objects.equals(privileges, o.privileges) &&
Objects.equals(grantObject, o.grantObject) &&
Objects.equals(grantee, o.grantee) &&
Objects.equals(grantOption, o.grantOption);
grantOption == o.grantOption;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean equals(Object obj)
}
Intersect o = (Intersect) obj;
return Objects.equals(relations, o.relations) &&
Objects.equals(isDistinct(), o.isDistinct());
isDistinct() == o.isDistinct();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class Parameter
Expand Down Expand Up @@ -68,7 +67,7 @@ public boolean equals(Object o)
}

Parameter that = (Parameter) o;
return Objects.equals(id, that.id);
return id == that.id;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean equals(Object obj)
RenameMaterializedView o = (RenameMaterializedView) obj;
return Objects.equals(source, o.source) &&
Objects.equals(target, o.target) &&
Objects.equals(exists, o.exists);
exists == o.exists;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean equals(Object obj)
return false;
}
Revoke o = (Revoke) obj;
return Objects.equals(grantOptionFor, o.grantOptionFor) &&
return grantOptionFor == o.grantOptionFor &&
Objects.equals(privileges, o.privileges) &&
Objects.equals(grantObject, o.grantObject) &&
Objects.equals(grantee, o.grantee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public boolean equals(Object obj)
return Objects.equals(tableName, o.tableName) &&
Objects.equals(columnName, o.columnName) &&
Objects.equals(type, o.type) &&
Objects.equals(tableExists, o.tableExists);
tableExists == o.tableExists;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean equals(Object obj)
}
Union o = (Union) obj;
return Objects.equals(relations, o.relations) &&
Objects.equals(isDistinct(), o.isDistinct());
isDistinct() == o.isDistinct();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public boolean equals(Object obj)
return false;
}
With o = (With) obj;
return Objects.equals(recursive, o.recursive) &&
return recursive == o.recursive &&
Objects.equals(queries, o.queries);
}

Expand Down
2 changes: 1 addition & 1 deletion core/trino-spi/src/main/java/io/trino/spi/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean equals(Object obj)
}

ErrorCode that = (ErrorCode) obj;
return Objects.equals(this.code, that.code);
return this.code == that.code;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/trino-spi/src/main/java/io/trino/spi/HostAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ public boolean equals(Object obj)
return false;
}
HostAddress other = (HostAddress) obj;
return Objects.equals(this.host, other.host) &&
Objects.equals(this.port, other.port);
return this.port == other.port &&
Objects.equals(this.host, other.host);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ public boolean equals(Object obj)
ColumnMetadata other = (ColumnMetadata) obj;
return Objects.equals(this.name, other.name) &&
Objects.equals(this.type, other.type) &&
Objects.equals(this.nullable, other.nullable) &&
this.nullable == other.nullable &&
Objects.equals(this.comment, other.comment) &&
Objects.equals(this.extraInfo, other.extraInfo) &&
Objects.equals(this.hidden, other.hidden);
this.hidden == other.hidden;
}

public static Builder builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean equals(Object o)

FieldDereference that = (FieldDereference) o;
return Objects.equals(target, that.target)
&& Objects.equals(field, that.field)
&& field == that.field
&& Objects.equals(getType(), that.getType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public boolean equals(Object obj)
Objects.equals(this.longVariableConstraints, other.longVariableConstraints) &&
Objects.equals(this.returnType, other.returnType) &&
Objects.equals(this.argumentTypes, other.argumentTypes) &&
Objects.equals(this.variableArity, other.variableArity);
this.variableArity == other.variableArity;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public boolean equals(Object o)
}
PrivilegeInfo privilegeInfo = (PrivilegeInfo) o;
return privilege == privilegeInfo.privilege &&
Objects.equals(grantOption, privilegeInfo.grantOption);
grantOption == privilegeInfo.grantOption;
}
}
3 changes: 1 addition & 2 deletions core/trino-spi/src/main/java/io/trino/spi/type/CharType.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ public boolean equals(Object o)
}

CharType other = (CharType) o;

return Objects.equals(this.length, other.length);
return this.length == other.length;
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions core/trino-spi/src/main/java/io/trino/spi/type/SqlDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.fasterxml.jackson.annotation.JsonValue;

import java.time.LocalDate;
import java.util.Objects;

public final class SqlDate
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public boolean equals(Object obj)
return false;
}
SqlDate other = (SqlDate) obj;
return Objects.equals(days, other.days);
return days == other.days;
}

@JsonValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ public boolean equals(Object obj)
return false;
}
TimeZoneKey other = (TimeZoneKey) obj;
return Objects.equals(this.id, other.id) && Objects.equals(this.key, other.key);
return this.key == other.key &&
Objects.equals(this.id, other.id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ public boolean equals(Object o)
}

VarcharType other = (VarcharType) o;

return Objects.equals(this.length, other.length);
return this.length == other.length;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public boolean equals(Object obj)
return false;
}
TpchSplit other = (TpchSplit) obj;
return Objects.equals(this.totalParts, other.totalParts) &&
Objects.equals(this.partNumber, other.partNumber);
return this.totalParts == other.totalParts &&
this.partNumber == other.partNumber;
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,8 @@
-Xep:NullOptional:ERROR \
-Xep:NullableOptional:ERROR \
-Xep:NullablePrimitive:ERROR \
<!-- requires https://github.com/google/error-prone/issues/4390 before switching to ERROR -->
-Xep:ObjectEqualsForPrimitives:WARN \
-Xep:ObjectToString:ERROR \
-Xep:OptionalNotPresent:ERROR \
-Xep:OrphanedFormatString:ERROR \
Expand Down

0 comments on commit f054a9c

Please sign in to comment.