Sonar fix - bad equals method
- Sonar deteced that the equals() method was not detecting type mismatch
- Implemented hashCode(), equals(), and toString using guava
Change-Id: I8ffea83e70a9c214d943767c8c6e74e940255c43
diff --git a/apps/castor/src/main/java/org/onosproject/castor/Peer.java b/apps/castor/src/main/java/org/onosproject/castor/Peer.java
index 395981b..787e46c 100644
--- a/apps/castor/src/main/java/org/onosproject/castor/Peer.java
+++ b/apps/castor/src/main/java/org/onosproject/castor/Peer.java
@@ -16,6 +16,8 @@
package org.onosproject.castor;
import javax.xml.bind.annotation.XmlRootElement;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
/**
* POJO class for the Peer and the Route Servers.
@@ -115,17 +117,27 @@
if (ob == null) {
return false;
}
- Peer other = (Peer) ob;
- if (this.ipAddress.equals(other.ipAddress)) {
- return true;
+ if (getClass() != ob.getClass()) {
+ return false;
}
- return false;
+ Peer other = (Peer) ob;
+ return Objects.equal(this.ipAddress, other.ipAddress);
}
@Override
public int hashCode() {
- int hash = 3;
- hash = 53 * hash + (this.ipAddress != null ? this.ipAddress.hashCode() : 0);
- return hash;
+ return Objects.hashCode(this.ipAddress);
+ }
+
+ @Override
+ public String toString() {
+
+ return MoreObjects.toStringHelper(this)
+ .add("ipAddress", ipAddress)
+ .add("name", name)
+ .add("dpid", dpid)
+ .add("port", port)
+ .toString();
+
}
}