Implemented hashcode() and equals() on Dpid, Port and SwitchPort in order to make SwitchPort comparison easier
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/SwitchPort.java b/src/main/java/net/onrc/onos/ofcontroller/util/SwitchPort.java
index 95a934f..898b9b0 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/SwitchPort.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/SwitchPort.java
@@ -6,83 +6,103 @@
* The class representing a Switch-Port.
*/
public class SwitchPort {
- private Dpid dpid; // The DPID of the switch
- private Port port; // The port of the switch
+ private Dpid dpid; // The DPID of the switch
+ private Port port; // The port of the switch
- /**
- * Default constructor.
- */
- public SwitchPort() {
- }
+ /**
+ * Default constructor.
+ */
+ public SwitchPort() {
+ }
- /**
- * Constructor for a given DPID and a port.
- *
- * @param dpid the DPID to use.
- * @param port the port to use.
- */
- public SwitchPort(Dpid dpid, Port port) {
- this.dpid = dpid;
- this.port = port;
- }
+ /**
+ * Constructor for a given DPID and a port.
+ *
+ * @param dpid the DPID to use.
+ * @param port the port to use.
+ */
+ public SwitchPort(Dpid dpid, Port port) {
+ this.dpid = dpid;
+ this.port = port;
+ }
- /**
- * Get the DPID value of the Switch-Port.
- *
- * @return the DPID value of the Switch-Port.
- */
- @JsonProperty("dpid")
- public Dpid dpid() { return dpid; }
+ /**
+ * Get the DPID value of the Switch-Port.
+ *
+ * @return the DPID value of the Switch-Port.
+ */
+ @JsonProperty("dpid")
+ public Dpid dpid() { return dpid; }
- /**
- * Set the DPID value of the Switch-Port.
- *
- * @param dpid the DPID to use.
- */
- @JsonProperty("dpid")
- public void setDpid(Dpid dpid) {
- this.dpid = dpid;
- }
+ /**
+ * Set the DPID value of the Switch-Port.
+ *
+ * @param dpid the DPID to use.
+ */
+ @JsonProperty("dpid")
+ public void setDpid(Dpid dpid) {
+ this.dpid = dpid;
+ }
- /**
- * Get the port value of the Switch-Port.
- *
- * @return the port value of the Switch-Port.
- */
- @JsonProperty("port")
- public Port port() { return port; }
+ /**
+ * Get the port value of the Switch-Port.
+ *
+ * @return the port value of the Switch-Port.
+ */
+ @JsonProperty("port")
+ public Port port() { return port; }
- /**
- * Set the port value of the Switch-Port.
- *
- * @param port the port to use.
- */
- @JsonProperty("port")
- public void setPort(Port port) {
- this.port = port;
- }
+ /**
+ * Set the port value of the Switch-Port.
+ *
+ * @param port the port to use.
+ */
+ @JsonProperty("port")
+ public void setPort(Port port) {
+ this.port = port;
+ }
- /**
- * Set the DPID and port values of the Switch-Port.
- *
- * @param dpid the DPID to use.
- * @param port the port to use.
- */
- public void setValue(Dpid dpid, Port port) {
- this.dpid = dpid;
- this.port = port;
- }
+ /**
+ * Set the DPID and port values of the Switch-Port.
+ *
+ * @param dpid the DPID to use.
+ * @param port the port to use.
+ */
+ public void setValue(Dpid dpid, Port port) {
+ this.dpid = dpid;
+ this.port = port;
+ }
- /**
- * Convert the Switch-Port value to a string.
- *
- * The string has the following form:
- * 01:02:03:04:05:06:07:08/1234
- *
- * @return the Switch-Port value as a string.
- */
- @Override
- public String toString() {
- return this.dpid.toString() + "/" + this.port;
- }
+ /**
+ * Convert the Switch-Port value to a string.
+ *
+ * The string has the following form:
+ * 01:02:03:04:05:06:07:08/1234
+ *
+ * @return the Switch-Port value as a string.
+ */
+ @Override
+ public String toString() {
+ return this.dpid.toString() + "/" + this.port;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof SwitchPort)) {
+ return false;
+ }
+
+ SwitchPort otherSwitchPort = (SwitchPort) other;
+
+ return (dpid.equals(otherSwitchPort.dpid) &&
+ port.equals(otherSwitchPort.port));
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash += 31 * hash + dpid.hashCode();
+ hash += 31 * hash + port.hashCode();
+ return hash;
+ }
}