Skip to content

Commit 44fedd6

Browse files
committed
Remove repeated casts in identities'equals method
1 parent 1d5f171 commit 44fedd6

10 files changed

Lines changed: 79 additions & 31 deletions

File tree

gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskTypeId.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ public int hashCode() {
9494

9595
@Override
9696
public boolean equals(Object obj) {
97-
return obj instanceof DiskTypeId
98-
&& baseEquals((DiskTypeId) obj)
99-
&& Objects.equals(zone, ((DiskTypeId) obj).zone)
100-
&& Objects.equals(diskType, ((DiskTypeId) obj).diskType);
97+
if (obj == this) {
98+
return true;
99+
}
100+
if (!(obj instanceof DiskTypeId)) {
101+
return false;
102+
}
103+
DiskTypeId other = (DiskTypeId) obj;
104+
return baseEquals(other)
105+
&& Objects.equals(zone, other.zone)
106+
&& Objects.equals(diskType, other.diskType);
101107
}
102108

103109
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/ForwardingRuleId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Objects;
2424

2525
/**
26-
* Interface for Google Compute Engine forwarding rule identities.
26+
* Base class for Google Compute Engine forwarding rule identities.
2727
*/
2828
public abstract class ForwardingRuleId extends ResourceId {
2929

gcloud-java-compute/src/main/java/com/google/gcloud/compute/InstanceId.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ public int hashCode() {
100100

101101
@Override
102102
public boolean equals(Object obj) {
103-
return obj instanceof InstanceId
104-
&& baseEquals((InstanceId) obj)
105-
&& Objects.equals(zone, ((InstanceId) obj).zone)
106-
&& Objects.equals(instance, ((InstanceId) obj).instance);
103+
if (obj == this) {
104+
return true;
105+
}
106+
if (!(obj instanceof InstanceId)) {
107+
return false;
108+
}
109+
InstanceId other = (InstanceId) obj;
110+
return baseEquals(other)
111+
&& Objects.equals(zone, other.zone)
112+
&& Objects.equals(instance, other.instance);
107113
}
108114

109115
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/LicenseId.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ public int hashCode() {
7878

7979
@Override
8080
public boolean equals(Object obj) {
81-
return obj instanceof LicenseId
82-
&& baseEquals((LicenseId) obj)
83-
&& Objects.equals(license, ((LicenseId) obj).license);
81+
if (obj == this) {
82+
return true;
83+
}
84+
if (!(obj instanceof LicenseId)) {
85+
return false;
86+
}
87+
LicenseId other = (LicenseId) obj;
88+
return baseEquals(other) && Objects.equals(license, other.license);
8489
}
8590

8691
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/MachineTypeId.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,16 @@ public int hashCode() {
9696

9797
@Override
9898
public boolean equals(Object obj) {
99-
return obj instanceof MachineTypeId
100-
&& baseEquals((MachineTypeId) obj)
101-
&& Objects.equals(zone, ((MachineTypeId) obj).zone)
102-
&& Objects.equals(machineType, ((MachineTypeId) obj).machineType);
99+
if (obj == this) {
100+
return true;
101+
}
102+
if (!(obj instanceof MachineTypeId)) {
103+
return false;
104+
}
105+
MachineTypeId other = (MachineTypeId) obj;
106+
return baseEquals(other)
107+
&& Objects.equals(zone, other.zone)
108+
&& Objects.equals(machineType, other.machineType);
103109
}
104110

105111
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/RegionAddressId.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ public int hashCode() {
7676

7777
@Override
7878
public boolean equals(Object obj) {
79-
return obj instanceof RegionAddressId
80-
&& baseEquals((RegionAddressId) obj)
81-
&& Objects.equals(region, ((RegionAddressId) obj).region);
79+
if (obj == this) {
80+
return true;
81+
}
82+
if (!(obj instanceof RegionAddressId)) {
83+
return false;
84+
}
85+
RegionAddressId other = (RegionAddressId) obj;
86+
return baseEquals(other) && Objects.equals(region, other.region);
8287
}
8388

8489
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/RegionForwardingRuleId.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ public int hashCode() {
9292

9393
@Override
9494
public boolean equals(Object obj) {
95-
return obj instanceof RegionForwardingRuleId
96-
&& baseEquals((RegionForwardingRuleId) obj)
97-
&& Objects.equals(region, ((RegionForwardingRuleId) obj).region);
95+
if (obj == this) {
96+
return true;
97+
}
98+
if (!(obj instanceof RegionForwardingRuleId)) {
99+
return false;
100+
}
101+
RegionForwardingRuleId other = (RegionForwardingRuleId) obj;
102+
return baseEquals(other) && Objects.equals(region, other.region);
98103
}
99104

100105
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/RegionId.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ public int hashCode() {
8383

8484
@Override
8585
public boolean equals(Object obj) {
86-
return obj instanceof RegionId
87-
&& baseEquals((RegionId) obj)
88-
&& Objects.equals(region, ((RegionId) obj).region);
86+
if (obj == this) {
87+
return true;
88+
}
89+
if (!(obj instanceof RegionId)) {
90+
return false;
91+
}
92+
RegionId other = (RegionId) obj;
93+
return baseEquals(other) && Objects.equals(region, other.region);
8994
}
9095

9196
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/RegionOperationId.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ public int hashCode() {
7676

7777
@Override
7878
public boolean equals(Object obj) {
79-
return obj instanceof RegionOperationId
80-
&& baseEquals((RegionOperationId) obj)
81-
&& Objects.equals(region, ((RegionOperationId) obj).region);
79+
if (obj == this) {
80+
return true;
81+
}
82+
if (!(obj instanceof RegionOperationId)) {
83+
return false;
84+
}
85+
RegionOperationId other = (RegionOperationId) obj;
86+
return baseEquals(other) && Objects.equals(region, other.region);
8287
}
8388

8489
@Override

gcloud-java-compute/src/main/java/com/google/gcloud/compute/ZoneId.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ public int hashCode() {
7878

7979
@Override
8080
public boolean equals(Object obj) {
81-
return obj instanceof ZoneId
82-
&& baseEquals((ZoneId) obj)
83-
&& Objects.equals(zone, ((ZoneId) obj).zone);
81+
if (obj == this) {
82+
return true;
83+
}
84+
if (!(obj instanceof ZoneId)) {
85+
return false;
86+
}
87+
ZoneId other = (ZoneId) obj;
88+
return baseEquals(other) && Objects.equals(zone, other.zone);
8489
}
8590

8691
@Override

0 commit comments

Comments
 (0)