Skip to content

Commit

Permalink
Refactor classes to be either final or have final equals/hashCode
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Apr 12, 2016
1 parent 51c418a commit 9b154a0
Show file tree
Hide file tree
Showing 51 changed files with 320 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* {@link BigQueryException} is thrown the BigQuery Error that caused it, if any, can be accessed
* with {@link BigQueryException#error()}.
*/
public class BigQueryError implements Serializable {
public final class BigQueryError implements Serializable {

static final Function<ErrorProto, BigQueryError> FROM_PB_FUNCTION =
new Function<ErrorProto, BigQueryError>() {
Expand Down Expand Up @@ -98,7 +98,9 @@ public String toString() {

@Override
public boolean equals(Object obj) {
return obj instanceof BigQueryError && Objects.equals(toPb(), ((BigQueryError) obj).toPb());
return obj == this
|| obj instanceof BigQueryError
&& Objects.equals(toPb(), ((BigQueryError) obj).toPb());
}

ErrorProto toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ ToStringHelper toStringHelper() {

@Override
public final boolean equals(Object obj) {
return this == obj
|| obj instanceof CopyJobConfiguration
return obj == this
|| obj != null
&& obj.getClass().equals(CopyJobConfiguration.class)
&& baseEquals((CopyJobConfiguration) obj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Google BigQuery options for CSV format. This class wraps some properties of CSV files used by
* BigQuery to parse external data.
*/
public class CsvOptions extends FormatOptions {
public final class CsvOptions extends FormatOptions {

private static final long serialVersionUID = 2193570529308612708L;

Expand Down Expand Up @@ -224,7 +224,9 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj instanceof CsvOptions && Objects.equals(toPb(), ((CsvOptions) obj).toPb());
return obj == this
|| obj instanceof CsvOptions
&& Objects.equals(toPb(), ((CsvOptions) obj).toPb());
}

com.google.api.services.bigquery.model.CsvOptions toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,15 @@ public Builder toBuilder() {

@Override
public final boolean equals(Object obj) {
return this == obj
|| obj instanceof Dataset
&& Objects.equals(toPb(), ((Dataset) obj).toPb())
&& Objects.equals(options, ((Dataset) obj).options);
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(Dataset.class)) {
return false;
}
Dataset other = (Dataset) obj;
return Objects.equals(toPb(), other.toPb())
&& Objects.equals(options, other.options);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Google BigQuery Dataset identity.
*/
public class DatasetId implements Serializable {
public final class DatasetId implements Serializable {

private static final long serialVersionUID = -6186254820908152300L;

Expand Down Expand Up @@ -68,7 +68,9 @@ public static DatasetId of(String dataset) {

@Override
public boolean equals(Object obj) {
return obj instanceof DatasetId && Objects.equals(toPb(), ((DatasetId) obj).toPb());
return obj == this
|| obj instanceof DatasetId
&& Objects.equals(toPb(), ((DatasetId) obj).toPb());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj != null
return obj == this
|| obj != null
&& obj.getClass().equals(DatasetInfo.class)
&& Objects.equals(toPb(), ((DatasetInfo) obj).toPb());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ ToStringHelper toStringHelper() {

@Override
public final boolean equals(Object obj) {
return this == obj
|| obj instanceof ExternalTableDefinition
return obj == this
|| obj != null
&& obj.getClass().equals(ExternalTableDefinition.class)
&& baseEquals((ExternalTableDefinition) obj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ ToStringHelper toStringHelper() {

@Override
public final boolean equals(Object obj) {
return this == obj
|| obj instanceof ExtractJobConfiguration
return obj == this
|| obj != null
&& obj.getClass().equals(ExtractJobConfiguration.class)
&& baseEquals((ExtractJobConfiguration) obj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import java.util.Objects;

/**
* Google BigQuery Table field. A table field has a name, a value, a mode and possibly a
* description. Supported types are: {@link Type#integer()}, {@link Type#bool()},
* {@link Type#string()}, {@link Type#floatingPoint()}, {@link Type#timestamp()} and
* {@link Type#record(Field...)}. One or more fields form a table's schema.
* Google BigQuery Table field. A table field has a name, a type, a mode and possibly a description.
* Supported types are: {@link Type#integer()}, {@link Type#bool()}, {@link Type#string()},
* {@link Type#floatingPoint()}, {@link Type#timestamp()} and {@link Type#record(Field...)}. One or
* more fields form a table's schema.
*/
public class Field implements Serializable {
public final class Field implements Serializable {

static final Function<TableFieldSchema, Field> FROM_PB_FUNCTION =
new Function<TableFieldSchema, Field>() {
Expand All @@ -56,6 +56,11 @@ public TableFieldSchema apply(Field field) {

private static final long serialVersionUID = -8154262932305199256L;

private final String name;
private final Type type;
private final String mode;
private final String description;

/**
* Data Types for a BigQuery Table field. This class provides factory methods for all BigQuery
* field types. To instantiate a RECORD value the list of sub-fields must be provided.
Expand Down Expand Up @@ -185,11 +190,6 @@ public enum Mode {
NULLABLE, REQUIRED, REPEATED
}

private final String name;
private final Type type;
private final String mode;
private final String description;

public static final class Builder {

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,16 @@ public String toString() {
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(attribute, value);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof FieldValue)) {
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(FieldValue.class)) {
return false;
}
FieldValue other = (FieldValue) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj instanceof FormatOptions && Objects.equals(type, ((FormatOptions) obj).type());
return obj == this
|| obj != null
&& obj.getClass().equals(FormatOptions.class)
&& Objects.equals(type, ((FormatOptions) obj).type());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @see <a href="https://cloud.google.com/bigquery/streaming-data-into-bigquery">Streaming Data into
* BigQuery</a>
*/
public class InsertAllRequest implements Serializable {
public final class InsertAllRequest implements Serializable {

private static final long serialVersionUID = 211200307773853078L;

Expand Down Expand Up @@ -443,6 +443,9 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof InsertAllRequest)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public boolean hasErrors() {
}

@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(insertErrors);
}

@Override
public boolean equals(Object obj) {
return obj instanceof InsertAllResponse
public final boolean equals(Object obj) {
return obj == this
|| obj != null
&& obj.getClass().equals(InsertAllResponse.class)
&& Objects.equals(insertErrors, ((InsertAllResponse) obj).insertErrors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,15 @@ public Builder toBuilder() {

@Override
public final boolean equals(Object obj) {
return this == obj
|| obj instanceof Job
&& Objects.equals(toPb(), ((Job) obj).toPb())
&& Objects.equals(options, ((Job) obj).options);
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(Job.class)) {
return false;
}
Job other = (Job) obj;
return Objects.equals(toPb(), other.toPb())
&& Objects.equals(options, other.options);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Google BigQuery Job identity.
*/
public class JobId implements Serializable {
public final class JobId implements Serializable {

private static final long serialVersionUID = 1225914835379688976L;

Expand Down Expand Up @@ -68,7 +68,9 @@ public static JobId of(String job) {

@Override
public boolean equals(Object obj) {
return obj instanceof JobId && Objects.equals(toPb(), ((JobId) obj).toPb());
return obj == this
|| obj instanceof JobId
&& Objects.equals(toPb(), ((JobId) obj).toPb());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
return obj != null
return obj == this
|| obj != null
&& obj.getClass().equals(JobInfo.class)
&& Objects.equals(toPb(), ((JobInfo) obj).toPb());
}
Expand Down
Loading

0 comments on commit 9b154a0

Please sign in to comment.