Correct unusual equals implementations

Found with FindBugs.
This commit is contained in:
Andrew Gaul 2014-08-27 10:15:38 -07:00
parent df996f3231
commit 63d43f236e
9 changed files with 95 additions and 25 deletions

View File

@ -272,10 +272,30 @@ public class Node {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof Node)) {
return false;
}
Node that = (Node) obj;
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.description, that.description)
&& Objects.equal(this.hostname, that.hostname)
&& Objects.equal(this.locationId, that.locationId)
&& Objects.equal(this.osArch, that.osArch)
&& Objects.equal(this.osFamily, that.osFamily)
&& Objects.equal(this.osDescription, that.osDescription)
&& Objects.equal(this.osVersion, that.osVersion)
&& Objects.equal(this.loginPort, that.loginPort)
&& Objects.equal(this.os64Bit, that.os64Bit)
&& Objects.equal(this.group, that.group)
&& Objects.equal(this.tags, that.tags)
&& Objects.equal(this.metadata, that.metadata)
&& Objects.equal(this.username, that.username)
// not comparing credential and credentialUrl
&& Objects.equal(this.sudoPassword, that.sudoPassword);
}
@Override

View File

@ -135,10 +135,20 @@ public class WellKnownImage {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof WellKnownImage)){
return false;
}
WellKnownImage that = (WellKnownImage) obj;
return Objects.equal(this.loginUser, that.loginUser)
&& Objects.equal(this.uuid, that.uuid)
&& Objects.equal(this.description, that.description)
&& Objects.equal(this.osFamily, that.osFamily)
&& Objects.equal(this.osVersion, that.osVersion)
&& Objects.equal(this.size, that.size)
&& Objects.equal(this.is64bit, that.is64bit);
}
@Override

View File

@ -48,10 +48,15 @@ public class AuthenticationResponse {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof AuthenticationResponse)) {
return false;
}
AuthenticationResponse that = (AuthenticationResponse) obj;
return Objects.equal(this.authToken, that.authToken)
&& Objects.equal(this.services, that.services);
}
@Override

View File

@ -74,7 +74,7 @@ public class CreateRecord<D extends Map<String, Object>> {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || !obj.getClass().equals(CreateRecord.class))
if (obj == null || !(obj instanceof CreateRecord))
return false;
CreateRecord<?> that = CreateRecord.class.cast(obj);
return equal(this.fqdn, that.fqdn) && equal(this.type, that.type) && equal(this.ttl, that.ttl)

View File

@ -299,10 +299,14 @@ public class InitScript extends ForwardingObject implements Statement, AcceptsSt
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return equal(this.toString(), that.toString());
if (!(obj instanceof InitScript)) {
return false;
}
InitScript that = (InitScript) obj;
return equal(this.instanceName, that.instanceName);
}
@Override

View File

@ -38,10 +38,15 @@ public class Datacenter {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof Datacenter)) {
return false;
}
Datacenter that = (Datacenter) obj;
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name);
}
@Override

View File

@ -44,10 +44,18 @@ public class Hardware {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof Hardware)) {
return false;
}
Hardware that = (Hardware) obj;
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.cores, that.cores)
&& Objects.equal(this.ram, that.ram)
&& Objects.equal(this.disk, that.disk);
}
@Override

View File

@ -38,10 +38,15 @@ public class Image {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof Image)) {
return false;
}
Image that = (Image) obj;
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name);
}
@Override

View File

@ -46,10 +46,23 @@ public class Server {
}
@Override
public boolean equals(Object that) {
if (that == null)
public boolean equals(Object obj) {
if (obj == null)
return false;
return Objects.equal(this.toString(), that.toString());
if (!(obj instanceof Server)) {
return false;
}
Server that = (Server) obj;
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.status, that.status)
&& Objects.equal(this.datacenter, that.datacenter)
&& Objects.equal(this.imageId, that.imageId)
&& Objects.equal(this.hardwareId, that.hardwareId)
&& Objects.equal(this.publicAddress, that.publicAddress)
&& Objects.equal(this.privateAddress, that.privateAddress)
&& Objects.equal(this.loginUser, that.loginUser)
&& Objects.equal(this.password, that.password);
}
@Override