diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryError.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryError.java
index a5e94ae8b70c..121ca578c0d3 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryError.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryError.java
@@ -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 FROM_PB_FUNCTION =
new Function() {
@@ -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() {
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java
index 3717ff039c7b..e455416bea7b 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CopyJobConfiguration.java
@@ -181,7 +181,9 @@ ToStringHelper toStringHelper() {
@Override
public boolean equals(Object obj) {
- return obj instanceof CopyJobConfiguration && baseEquals((CopyJobConfiguration) obj);
+ return obj == this
+ || obj instanceof CopyJobConfiguration
+ && baseEquals((CopyJobConfiguration) obj);
}
@Override
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CsvOptions.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CsvOptions.java
index e07347f2b873..b621ed2cc6bc 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CsvOptions.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/CsvOptions.java
@@ -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;
@@ -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() {
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Dataset.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Dataset.java
index 31dee897aada..5cc7a260f00f 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Dataset.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Dataset.java
@@ -34,7 +34,7 @@
* {@link DatasetInfo}.
*
*/
-public final class Dataset extends DatasetInfo {
+public class Dataset extends DatasetInfo {
private static final long serialVersionUID = -4272921483363065593L;
@@ -230,14 +230,20 @@ public Builder toBuilder() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof Dataset
- && Objects.equals(toPb(), ((Dataset) obj).toPb())
- && Objects.equals(options, ((Dataset) obj).options);
+ public final boolean equals(Object obj) {
+ 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
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetId.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetId.java
index 634327f2189d..a6f2762da9cd 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetId.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetId.java
@@ -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;
@@ -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
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java
index 284cf5aebeac..3e7da7cc6c87 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java
@@ -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());
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java
index 0b191d3af761..af17c281f7f1 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java
@@ -255,12 +255,15 @@ ToStringHelper toStringHelper() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof ExternalTableDefinition && baseEquals((ExternalTableDefinition) obj);
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ExternalTableDefinition.class)
+ && baseEquals((ExternalTableDefinition) obj);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(baseHashCode(), compression, ignoreUnknownValues, maxBadRecords,
formatOptions, sourceUris);
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExtractJobConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExtractJobConfiguration.java
index 6c31e2781d9e..3dccddcae764 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExtractJobConfiguration.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ExtractJobConfiguration.java
@@ -211,7 +211,9 @@ ToStringHelper toStringHelper() {
@Override
public boolean equals(Object obj) {
- return obj instanceof ExtractJobConfiguration && baseEquals((ExtractJobConfiguration) obj);
+ return obj == this
+ || obj instanceof ExtractJobConfiguration
+ && baseEquals((ExtractJobConfiguration) obj);
}
@Override
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Field.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Field.java
index c1342ead8f2a..dc805e12c2a2 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Field.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Field.java
@@ -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 FROM_PB_FUNCTION =
new Function() {
@@ -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.
@@ -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;
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java
index 0bd15da9d908..1c06b87d639d 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java
@@ -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;
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java
index 98e199f6b644..4267d5384147 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/FormatOptions.java
@@ -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());
}
/**
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllRequest.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllRequest.java
index 6907abaaae33..b46257833b78 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllRequest.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllRequest.java
@@ -37,7 +37,7 @@
* @see Streaming Data into
* BigQuery
*/
-public class InsertAllRequest implements Serializable {
+public final class InsertAllRequest implements Serializable {
private static final long serialVersionUID = 211200307773853078L;
@@ -443,6 +443,9 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
if (!(obj instanceof InsertAllRequest)) {
return false;
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllResponse.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllResponse.java
index 1b998947f068..a145d1037bf7 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllResponse.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/InsertAllResponse.java
@@ -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);
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Job.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Job.java
index 17b58426afc4..bfcca5b5388a 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Job.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Job.java
@@ -30,7 +30,7 @@
* {@link JobInfo}.
*
*/
-public final class Job extends JobInfo {
+public class Job extends JobInfo {
private static final long serialVersionUID = -4324100991693024704L;
@@ -178,14 +178,20 @@ public Builder toBuilder() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof Job
- && Objects.equals(toPb(), ((Job) obj).toPb())
- && Objects.equals(options, ((Job) obj).options);
+ public final boolean equals(Object obj) {
+ 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
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java
index bc81fe11f700..d2981151481f 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java
@@ -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;
@@ -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
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobInfo.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobInfo.java
index 500eaabcaf17..13addc9d6e7a 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobInfo.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobInfo.java
@@ -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());
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java
index 58ae9045e7cc..90ad164a7ce5 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java
@@ -14,7 +14,7 @@
/**
* A Google BigQuery Job statistics.
*/
-public class JobStatistics implements Serializable {
+public abstract class JobStatistics implements Serializable {
private static final long serialVersionUID = 1433024714741660399L;
@@ -22,6 +22,55 @@ public class JobStatistics implements Serializable {
private final Long endTime;
private final Long startTime;
+ /**
+ * A Google BigQuery Copy Job statistics.
+ */
+ public static class CopyStatistics extends JobStatistics {
+
+ private static final long serialVersionUID = 8218325588441660938L;
+
+ static final class Builder extends JobStatistics.Builder {
+
+ private Builder() {}
+
+ private Builder(com.google.api.services.bigquery.model.JobStatistics statisticsPb) {
+ super(statisticsPb);
+ }
+
+ @Override
+ CopyStatistics build() {
+ return new CopyStatistics(this);
+ }
+ }
+
+ private CopyStatistics(Builder builder) {
+ super(builder);
+ }
+
+ @Override
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(CopyStatistics.class)
+ && baseEquals((CopyStatistics) obj);
+ }
+
+ @Override
+ public final int hashCode() {
+ return baseHashCode();
+ }
+
+ static Builder builder() {
+ return new Builder();
+ }
+
+ @SuppressWarnings("unchecked")
+ static CopyStatistics fromPb(
+ com.google.api.services.bigquery.model.JobStatistics statisticPb) {
+ return new Builder(statisticPb).build();
+ }
+ }
+
/**
* A Google BigQuery Extract Job statistics.
*/
@@ -73,14 +122,16 @@ ToStringHelper toStringHelper() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof ExtractStatistics
- && Objects.equals(toPb(), ((ExtractStatistics) obj).toPb());
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ExtractStatistics.class)
+ && baseEquals((ExtractStatistics) obj);
}
@Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), destinationUriFileCounts);
+ public final int hashCode() {
+ return Objects.hash(baseHashCode(), destinationUriFileCounts);
}
@Override
@@ -203,13 +254,16 @@ ToStringHelper toStringHelper() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof LoadStatistics && Objects.equals(toPb(), ((LoadStatistics) obj).toPb());
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(LoadStatistics.class)
+ && baseEquals((LoadStatistics) obj);
}
@Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), inputBytes, inputFiles, outputBytes, outputRows);
+ public final int hashCode() {
+ return Objects.hash(baseHashCode(), inputBytes, inputFiles, outputBytes, outputRows);
}
@Override
@@ -361,14 +415,16 @@ ToStringHelper toStringHelper() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof QueryStatistics
- && Objects.equals(toPb(), ((QueryStatistics) obj).toPb());
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(QueryStatistics.class)
+ && baseEquals((QueryStatistics) obj);
}
@Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), billingTier, cacheHit, totalBytesBilled,
+ public final int hashCode() {
+ return Objects.hash(baseHashCode(), billingTier, cacheHit, totalBytesBilled,
totalBytesProcessed, queryPlan);
}
@@ -396,7 +452,7 @@ static QueryStatistics fromPb(
}
}
- static class Builder> {
+ abstract static class Builder> {
private Long creationTime;
private Long endTime;
@@ -430,10 +486,7 @@ B startTime(Long startTime) {
return self();
}
- @SuppressWarnings("unchecked")
- T build() {
- return (T) new JobStatistics(this);
- }
+ abstract T build();
}
protected JobStatistics(Builder builder) {
@@ -477,14 +530,12 @@ public String toString() {
return toStringHelper().toString();
}
- @Override
- public int hashCode() {
+ final int baseHashCode() {
return Objects.hash(creationTime, endTime, startTime);
}
- @Override
- public boolean equals(Object obj) {
- return obj instanceof JobStatistics && Objects.equals(toPb(), ((JobStatistics) obj).toPb());
+ final boolean baseEquals(JobStatistics jobStatistics) {
+ return Objects.equals(toPb(), jobStatistics.toPb());
}
com.google.api.services.bigquery.model.JobStatistics toPb() {
@@ -496,10 +547,6 @@ com.google.api.services.bigquery.model.JobStatistics toPb() {
return statistics;
}
- static Builder builder() {
- return new Builder();
- }
-
@SuppressWarnings("unchecked")
static T fromPb(
com.google.api.services.bigquery.model.JobStatistics statisticPb) {
@@ -510,7 +557,7 @@ static T fromPb(
} else if (statisticPb.getQuery() != null) {
return (T) QueryStatistics.fromPb(statisticPb);
} else {
- return (T) new Builder(statisticPb).build();
+ return (T) CopyStatistics.fromPb(statisticPb);
}
}
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java
index 8d8da43e00de..7c948e6373f9 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java
@@ -94,13 +94,16 @@ public String toString() {
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(state, error, executionErrors);
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof JobStatus && Objects.equals(toPb(), ((JobStatus) obj).toPb());
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(JobStatus.class)
+ && Objects.equals(toPb(), ((JobStatus) obj).toPb());
}
com.google.api.services.bigquery.model.JobStatus toPb() {
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/LoadJobConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/LoadJobConfiguration.java
index a4abbce89137..03e2d7fea05e 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/LoadJobConfiguration.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/LoadJobConfiguration.java
@@ -269,7 +269,9 @@ ToStringHelper toStringHelper() {
@Override
public boolean equals(Object obj) {
- return obj instanceof LoadJobConfiguration && baseEquals((LoadJobConfiguration) obj);
+ return obj == this
+ || obj instanceof LoadJobConfiguration
+ && baseEquals((LoadJobConfiguration) obj);
}
@Override
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java
index 4c5034a4a0c8..73b1403245c7 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java
@@ -39,6 +39,19 @@ public final class QueryJobConfiguration extends JobConfiguration {
private static final long serialVersionUID = -1108948249081804890L;
+ private final String query;
+ private final TableId destinationTable;
+ private final Map tableDefinitions;
+ private final List userDefinedFunctions;
+ private final CreateDisposition createDisposition;
+ private final WriteDisposition writeDisposition;
+ private final DatasetId defaultDataset;
+ private final Priority priority;
+ private final Boolean allowLargeResults;
+ private final Boolean useQueryCache;
+ private final Boolean flattenResults;
+ private final Boolean dryRun;
+
/**
* Priority levels for a query. If not specified the priority is assumed to be
* {@link Priority#INTERACTIVE}.
@@ -59,19 +72,6 @@ public enum Priority {
BATCH
}
- private final String query;
- private final TableId destinationTable;
- private final Map tableDefinitions;
- private final List userDefinedFunctions;
- private final CreateDisposition createDisposition;
- private final WriteDisposition writeDisposition;
- private final DatasetId defaultDataset;
- private final Priority priority;
- private final Boolean allowLargeResults;
- private final Boolean useQueryCache;
- private final Boolean flattenResults;
- private final Boolean dryRun;
-
public static final class Builder
extends JobConfiguration.Builder {
@@ -450,7 +450,9 @@ ToStringHelper toStringHelper() {
@Override
public boolean equals(Object obj) {
- return obj instanceof QueryJobConfiguration && baseEquals((QueryJobConfiguration) obj);
+ return obj == this
+ || obj instanceof QueryJobConfiguration
+ && baseEquals((QueryJobConfiguration) obj);
}
@Override
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequest.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequest.java
index 8cd3530f9227..166e0db9a18d 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequest.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequest.java
@@ -60,7 +60,7 @@
* @see Query
* @see Query Reference
*/
-public class QueryRequest implements Serializable {
+public final class QueryRequest implements Serializable {
private static final long serialVersionUID = -8727328332415880852L;
@@ -250,7 +250,9 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- return obj instanceof QueryRequest && Objects.equals(toPb(), ((QueryRequest) obj).toPb());
+ return obj == this
+ || obj instanceof QueryRequest
+ && Objects.equals(toPb(), ((QueryRequest) obj).toPb());
}
QueryRequest setProjectId(String projectId) {
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResponse.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResponse.java
index ceb1099d4faf..57a8966b0301 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResponse.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResponse.java
@@ -170,16 +170,16 @@ public String toString() {
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(jobId);
}
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
+ public final boolean equals(Object obj) {
+ if (obj == this) {
return true;
}
- if (obj == null || getClass() != obj.getClass()) {
+ if (obj == null || !obj.getClass().equals(QueryResponse.class)) {
return false;
}
QueryResponse response = (QueryResponse) obj;
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResult.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResult.java
index 74a9e5000b0e..ba036187307c 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResult.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryResult.java
@@ -149,16 +149,16 @@ public String toString() {
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), cacheHit, schema, totalBytesProcessed, totalRows);
}
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
+ public final boolean equals(Object obj) {
+ if (obj == this) {
return true;
}
- if (obj == null || getClass() != obj.getClass()) {
+ if (obj == null || !obj.getClass().equals(QueryResult.class)) {
return false;
}
QueryResult response = (QueryResult) obj;
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java
index b9cfb804b1ac..7276a86e7eeb 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryStage.java
@@ -372,15 +372,18 @@ public String toString() {
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(computeRatioAvg, computeRatioMax, generatedId, name, readRatioAvg,
readRatioMax, recordsRead, recordsWritten, steps, waitRatioAvg, waitRatioMax,
writeRatioAvg);
}
@Override
- public boolean equals(Object obj) {
- if (!(obj instanceof QueryStage)) {
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(QueryStage.class)) {
return false;
}
QueryStage other = (QueryStage) obj;
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Schema.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Schema.java
index 88114d47ae6c..218c2a214e50 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Schema.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/Schema.java
@@ -31,7 +31,7 @@
/**
* This class represents the schema for a Google BigQuery Table or data source.
*/
-public class Schema implements Serializable {
+public final class Schema implements Serializable {
static final Function
FROM_PB_FUNCTION = new Function
*/
-public final class Table extends TableInfo {
+public class Table extends TableInfo {
private static final long serialVersionUID = 5744556727066570096L;
@@ -322,14 +322,20 @@ public Builder toBuilder() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof Table
- && Objects.equals(toPb(), ((Table) obj).toPb())
- && Objects.equals(options, ((Table) obj).options);
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(Table.class)) {
+ return false;
+ }
+ Table other = (Table) obj;
+ return Objects.equals(toPb(), other.toPb())
+ && Objects.equals(options, other.options);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableId.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableId.java
index cee20332db9e..95768a59b5d2 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableId.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableId.java
@@ -27,7 +27,7 @@
/**
* Google BigQuery Table identity.
*/
-public class TableId implements Serializable {
+public final class TableId implements Serializable {
static final Function FROM_PB_FUNCTION =
new Function() {
@@ -92,7 +92,9 @@ public static TableId of(String dataset, String table) {
@Override
public boolean equals(Object obj) {
- return obj instanceof TableId && Objects.equals(toPb(), ((TableId) obj).toPb());
+ return obj == this
+ || obj instanceof TableId
+ && Objects.equals(toPb(), ((TableId) obj).toPb());
}
@Override
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java
index 2c6083eaea75..c27b0dfdf1e5 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java
@@ -339,7 +339,8 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- return obj != null
+ return obj == this
+ || obj != null
&& obj.getClass().equals(TableInfo.class)
&& Objects.equals(toPb(), ((TableInfo) obj).toPb());
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ViewDefinition.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ViewDefinition.java
index 89ca9674508e..1d3a97ba616d 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ViewDefinition.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/ViewDefinition.java
@@ -33,7 +33,7 @@
*
* @see Views
*/
-public final class ViewDefinition extends TableDefinition {
+public class ViewDefinition extends TableDefinition {
private static final long serialVersionUID = -8789311196910794545L;
@@ -146,12 +146,15 @@ ToStringHelper toStringHelper() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof ViewDefinition && baseEquals((ViewDefinition) obj);
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ViewDefinition.class)
+ && baseEquals((ViewDefinition) obj);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(baseHashCode(), query, userDefinedFunctions);
}
diff --git a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/WriteChannelConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/WriteChannelConfiguration.java
index b7bb9db277a3..898063e7e0ed 100644
--- a/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/WriteChannelConfiguration.java
+++ b/gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/WriteChannelConfiguration.java
@@ -33,7 +33,7 @@
* into a table with a {@link com.google.cloud.WriteChannel}
* ({@link BigQuery#writer(WriteChannelConfiguration)}).
*/
-public class WriteChannelConfiguration implements LoadConfiguration, Serializable {
+public final class WriteChannelConfiguration implements LoadConfiguration, Serializable {
private static final long serialVersionUID = 470267591917413578L;
@@ -241,7 +241,8 @@ public String toString() {
@Override
public boolean equals(Object obj) {
- return obj instanceof WriteChannelConfiguration
+ return obj == this
+ || obj instanceof WriteChannelConfiguration
&& Objects.equals(toPb(), ((WriteChannelConfiguration) obj).toPb());
}
diff --git a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobInfoTest.java b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobInfoTest.java
index e6cd2987fbd7..d7fde0957a2f 100644
--- a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobInfoTest.java
+++ b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobInfoTest.java
@@ -23,6 +23,7 @@
import com.google.cloud.bigquery.JobInfo.CreateDisposition;
import com.google.cloud.bigquery.JobInfo.WriteDisposition;
+import com.google.cloud.bigquery.JobStatistics.CopyStatistics;
import com.google.cloud.bigquery.JobStatistics.ExtractStatistics;
import com.google.cloud.bigquery.JobStatistics.LoadStatistics;
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
@@ -42,7 +43,7 @@ public class JobInfoTest {
private static final String EMAIL = "email";
private static final JobId JOB_ID = JobId.of("job");
private static final JobStatus JOB_STATUS = new JobStatus(JobStatus.State.DONE);
- private static final JobStatistics COPY_JOB_STATISTICS = JobStatistics.builder()
+ private static final CopyStatistics COPY_JOB_STATISTICS = CopyStatistics.builder()
.creationTime(1L)
.endTime(3L)
.startTime(2L)
diff --git a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java
index 9fbe43f3903f..c4c8c5ae6f4b 100644
--- a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java
+++ b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java
@@ -18,11 +18,12 @@
import static org.junit.Assert.assertEquals;
+import com.google.common.collect.ImmutableList;
+import com.google.cloud.bigquery.JobStatistics.CopyStatistics;
import com.google.cloud.bigquery.JobStatistics.ExtractStatistics;
import com.google.cloud.bigquery.JobStatistics.LoadStatistics;
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
import com.google.cloud.bigquery.QueryStage.QueryStep;
-import com.google.common.collect.ImmutableList;
import org.junit.Test;
@@ -42,6 +43,11 @@ public class JobStatisticsTest {
private static final Long CREATION_TIME = 10L;
private static final Long END_TIME = 20L;
private static final Long START_TIME = 15L;
+ private static final CopyStatistics COPY_STATISTICS = CopyStatistics.builder()
+ .creationTime(CREATION_TIME)
+ .endTime(END_TIME)
+ .startTime(START_TIME)
+ .build();
private static final ExtractStatistics EXTRACT_STATISTICS = ExtractStatistics.builder()
.creationTime(CREATION_TIME)
.endTime(END_TIME)
@@ -101,17 +107,12 @@ public class JobStatisticsTest {
.billingTier(BILLING_TIER)
.cacheHit(CACHE_HIT)
.build();
- private static final JobStatistics STATISTICS = JobStatistics.builder()
- .creationTime(CREATION_TIME)
- .endTime(END_TIME)
- .startTime(START_TIME)
- .build();
@Test
public void testBuilder() {
- assertEquals(CREATION_TIME, STATISTICS.creationTime());
- assertEquals(START_TIME, STATISTICS.startTime());
- assertEquals(END_TIME, STATISTICS.endTime());
+ assertEquals(CREATION_TIME, COPY_STATISTICS.creationTime());
+ assertEquals(START_TIME, COPY_STATISTICS.startTime());
+ assertEquals(END_TIME, COPY_STATISTICS.endTime());
assertEquals(CREATION_TIME, EXTRACT_STATISTICS.creationTime());
assertEquals(START_TIME, EXTRACT_STATISTICS.startTime());
@@ -160,7 +161,7 @@ public void testToPbAndFromPb() {
ExtractStatistics.fromPb(EXTRACT_STATISTICS.toPb()));
compareLoadStatistics(LOAD_STATISTICS, LoadStatistics.fromPb(LOAD_STATISTICS.toPb()));
compareQueryStatistics(QUERY_STATISTICS, QueryStatistics.fromPb(QUERY_STATISTICS.toPb()));
- compareStatistics(STATISTICS, JobStatistics.fromPb(STATISTICS.toPb()));
+ compareStatistics(COPY_STATISTICS, JobStatistics.fromPb(COPY_STATISTICS.toPb()));
compareLoadStatistics(LOAD_STATISTICS_INCOMPLETE,
LoadStatistics.fromPb(LOAD_STATISTICS_INCOMPLETE.toPb()));
diff --git a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java
index b2a2461f1267..44e5e201e95c 100644
--- a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java
+++ b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java
@@ -27,6 +27,8 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import com.google.cloud.bigquery.JobStatistics.CopyStatistics;
+
import org.junit.After;
import org.junit.Test;
@@ -40,7 +42,7 @@ public class JobTest {
private static final String SELF_LINK = "selfLink";
private static final String EMAIL = "email";
private static final JobStatus JOB_STATUS = new JobStatus(JobStatus.State.DONE);
- private static final JobStatistics COPY_JOB_STATISTICS = JobStatistics.builder()
+ private static final JobStatistics COPY_JOB_STATISTICS = CopyStatistics.builder()
.creationTime(1L)
.endTime(3L)
.startTime(2L)
diff --git a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java
index 7aabcea120e9..30b1b9e067ec 100644
--- a/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java
+++ b/gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/SerializationTest.java
@@ -122,11 +122,12 @@ public class SerializationTest extends BaseSerializationTest {
.etag(ETAG)
.generatedId(GENERATED_ID)
.build();
- private static final JobStatistics JOB_STATISTICS = JobStatistics.builder()
- .creationTime(1L)
- .endTime(3L)
- .startTime(2L)
- .build();
+ private static final JobStatistics.CopyStatistics COPY_STATISTICS =
+ JobStatistics.CopyStatistics.builder()
+ .creationTime(1L)
+ .endTime(3L)
+ .startTime(2L)
+ .build();
private static final JobStatistics.ExtractStatistics EXTRACT_STATISTICS =
JobStatistics.ExtractStatistics.builder()
.creationTime(1L)
@@ -235,7 +236,7 @@ protected Serializable[] serializableObjects() {
return new Serializable[]{DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID,
DATASET_INFO, TABLE_ID, CSV_OPTIONS, STREAMING_BUFFER, TABLE_DEFINITION,
EXTERNAL_TABLE_DEFINITION, VIEW_DEFINITION, TABLE_SCHEMA, TABLE_INFO, VIEW_INFO,
- EXTERNAL_TABLE_INFO, INLINE_FUNCTION, URI_FUNCTION, JOB_STATISTICS, EXTRACT_STATISTICS,
+ EXTERNAL_TABLE_INFO, INLINE_FUNCTION, URI_FUNCTION, COPY_STATISTICS, EXTRACT_STATISTICS,
LOAD_STATISTICS, QUERY_STATISTICS, BIGQUERY_ERROR, JOB_STATUS, JOB_ID,
COPY_JOB_CONFIGURATION, EXTRACT_JOB_CONFIGURATION, LOAD_CONFIGURATION,
LOAD_JOB_CONFIGURATION, QUERY_JOB_CONFIGURATION, JOB_INFO, INSERT_ALL_REQUEST,
diff --git a/gcloud-java-core/src/main/java/com/google/cloud/IamPolicy.java b/gcloud-java-core/src/main/java/com/google/cloud/IamPolicy.java
index 1f214e1b0f71..2d15d9907687 100644
--- a/gcloud-java-core/src/main/java/com/google/cloud/IamPolicy.java
+++ b/gcloud-java-core/src/main/java/com/google/cloud/IamPolicy.java
@@ -219,7 +219,10 @@ public final int hashCode() {
@Override
public final boolean equals(Object obj) {
- if (obj == null || !getClass().equals(obj.getClass())) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(getClass())) {
return false;
}
@SuppressWarnings("rawtypes")
diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequest.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequest.java
index 61864e968ebb..3538a5c411e9 100644
--- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequest.java
+++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequest.java
@@ -192,19 +192,21 @@ public Builder toBuilder() {
}
@Override
- public boolean equals(Object obj) {
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
if (obj == null || !obj.getClass().equals(ChangeRequest.class)) {
return false;
- } else {
- ChangeRequest other = (ChangeRequest) obj;
- return Objects.equals(options, other.options)
- && Objects.equals(zone, other.zone)
- && Objects.equals(toPb(), other.toPb());
}
+ ChangeRequest other = (ChangeRequest) obj;
+ return Objects.equals(toPb(), other.toPb())
+ && Objects.equals(options, other.options)
+ && Objects.equals(zone, other.zone);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options, zone);
}
diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java
index 53bce6cf1380..8ed68765a163 100644
--- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java
+++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java
@@ -335,9 +335,11 @@ static ChangeRequestInfo fromPb(Change pb) {
}
@Override
- public boolean equals(Object other) {
- return other != null && other.getClass().equals(ChangeRequestInfo.class)
- && other instanceof ChangeRequestInfo && toPb().equals(((ChangeRequestInfo) other).toPb());
+ public boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ChangeRequestInfo.class)
+ && toPb().equals(((ChangeRequestInfo) obj).toPb());
}
@Override
diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ProjectInfo.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ProjectInfo.java
index 3d0d4704e6c0..bc35bacc317d 100644
--- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ProjectInfo.java
+++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ProjectInfo.java
@@ -268,12 +268,15 @@ static ProjectInfo fromPb(Project pb) {
}
@Override
- public boolean equals(Object other) {
- return (other instanceof ProjectInfo) && toPb().equals(((ProjectInfo) other).toPb());
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ProjectInfo.class)
+ && toPb().equals(((ProjectInfo) obj).toPb());
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(id, number, quota);
}
diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/RecordSet.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/RecordSet.java
index a8323041a2fb..5e061b5164e8 100644
--- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/RecordSet.java
+++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/RecordSet.java
@@ -43,7 +43,7 @@
* @see Google Cloud DNS
* documentation
*/
-public class RecordSet implements Serializable {
+public final class RecordSet implements Serializable {
static final Function FROM_PB_FUNCTION =
new Function() {
@@ -282,7 +282,9 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- return obj instanceof RecordSet && Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
+ return obj == this
+ || obj instanceof RecordSet
+ && Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
}
ResourceRecordSet toPb() {
diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/Zone.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/Zone.java
index 8c21d79a992f..a01f7212d28e 100644
--- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/Zone.java
+++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/Zone.java
@@ -196,13 +196,20 @@ public Dns dns() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof Zone && Objects.equals(toPb(), ((Zone) obj).toPb())
- && Objects.equals(options, ((Zone) obj).options);
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(Zone.class)) {
+ return false;
+ }
+ Zone other = (Zone) obj;
+ return Objects.equals(toPb(), other.toPb())
+ && Objects.equals(options, other.options);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}
diff --git a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java
index 2b8c79e7fe5c..d6178479b68b 100644
--- a/gcloud-java-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java
+++ b/gcloud-java-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java
@@ -293,7 +293,9 @@ static ZoneInfo fromPb(ManagedZone pb) {
@Override
public boolean equals(Object obj) {
- return obj != null && obj.getClass().equals(ZoneInfo.class)
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ZoneInfo.class)
&& Objects.equals(toPb(), ((ZoneInfo) obj).toPb());
}
diff --git a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Policy.java b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Policy.java
index 41238fd9b9aa..f22b13e96268 100644
--- a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Policy.java
+++ b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Policy.java
@@ -40,7 +40,7 @@
*
* @see Policy
*/
-public class Policy extends IamPolicy {
+public final class Policy extends IamPolicy {
private static final long serialVersionUID = -5573557282693961850L;
diff --git a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Project.java b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Project.java
index 25cda85d1c09..d728ec3ea4df 100644
--- a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Project.java
+++ b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/Project.java
@@ -257,13 +257,20 @@ public Builder toBuilder() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof Project && Objects.equals(toPb(), ((Project) obj).toPb())
- && Objects.equals(options, ((Project) obj).options);
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(Project.class)) {
+ return false;
+ }
+ Project other = (Project) obj;
+ return Objects.equals(toPb(), other.toPb())
+ && Objects.equals(options, other.options);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}
diff --git a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java
index 355236b653f1..762ad3db050f 100644
--- a/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java
+++ b/gcloud-java-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java
@@ -336,7 +336,9 @@ public Long createTimeMillis() {
@Override
public boolean equals(Object obj) {
- return obj != null && obj.getClass().equals(ProjectInfo.class)
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(ProjectInfo.class)
&& Objects.equals(toPb(), ((ProjectInfo) obj).toPb());
}
diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BatchResponse.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BatchResponse.java
index d07d9dc26c2d..d1e56758b9d2 100644
--- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BatchResponse.java
+++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BatchResponse.java
@@ -26,7 +26,7 @@
/**
* Google Storage batch response.
*/
-public final class BatchResponse implements Serializable {
+public class BatchResponse implements Serializable {
private static final long serialVersionUID = 1057416839397037706L;
@@ -121,13 +121,16 @@ static Result empty() {
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(deleteResult, updateResult, getResult);
}
@Override
- public boolean equals(Object obj) {
- if (!(obj instanceof BatchResponse)) {
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(BatchResponse.class)) {
return false;
}
BatchResponse other = (BatchResponse) obj;
diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/Blob.java
index 1adea4f549bd..9b74b686d8f9 100644
--- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/Blob.java
+++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/Blob.java
@@ -526,10 +526,15 @@ public Builder toBuilder() {
@Override
public final boolean equals(Object obj) {
- return this == obj
- || obj instanceof Blob
- && Objects.equals(toPb(), ((Blob) obj).toPb())
- && Objects.equals(options, ((Blob) obj).options);
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(Blob.class)) {
+ return false;
+ }
+ Blob other = (Blob) obj;
+ return Objects.equals(toPb(), other.toPb())
+ && Objects.equals(options, other.options);
}
@Override
diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobId.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobId.java
index 52e7fc5f331e..88664e191f84 100644
--- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobId.java
+++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobId.java
@@ -79,9 +79,16 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- return obj instanceof BlobId && Objects.equals(bucket, ((BlobId) obj).bucket)
- && Objects.equals(name, ((BlobId) obj).name)
- && Objects.equals(generation, ((BlobId) obj).generation);
+ if (obj == this) {
+ return true;
+ }
+ if (obj == null || !obj.getClass().equals(BlobId.class)) {
+ return false;
+ }
+ BlobId other = (BlobId) obj;
+ return Objects.equals(bucket, other.bucket)
+ && Objects.equals(name, other.name)
+ && Objects.equals(generation, other.generation);
}
StorageObject toPb() {
diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobInfo.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobInfo.java
index dd264fa7f92b..f7d21b09a8ee 100644
--- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobInfo.java
+++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BlobInfo.java
@@ -638,7 +638,9 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- return obj != null && obj.getClass().equals(BlobInfo.class)
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(BlobInfo.class)
&& Objects.equals(toPb(), ((BlobInfo) obj).toPb());
}
diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/Bucket.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/Bucket.java
index 989ea87ec9d3..9f5a2e2499a0 100644
--- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/Bucket.java
+++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/Bucket.java
@@ -49,7 +49,7 @@
* {@link BucketInfo}.
*
*/
-public final class Bucket extends BucketInfo {
+public class Bucket extends BucketInfo {
private static final long serialVersionUID = 8574601739542252586L;
@@ -714,13 +714,20 @@ public Builder toBuilder() {
}
@Override
- public boolean equals(Object obj) {
- return obj instanceof Bucket && Objects.equals(toPb(), ((Bucket) obj).toPb())
- && Objects.equals(options, ((Bucket) obj).options);
+ public final boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj != null && !obj.getClass().equals(Bucket.class)) {
+ return false;
+ }
+ Bucket other = (Bucket) obj;
+ return Objects.equals(toPb(), other.toPb())
+ && Objects.equals(options, other.options);
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(super.hashCode(), options);
}
diff --git a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
index 1dcd110808a9..36e0ed54ffa0 100644
--- a/gcloud-java-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
+++ b/gcloud-java-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
@@ -719,7 +719,9 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- return obj != null && obj.getClass().equals(BucketInfo.class)
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(BucketInfo.class)
&& Objects.equals(toPb(), ((BucketInfo) obj).toPb());
}