Cleanup the implementation of class TopologyEvent and associated classes.
The major addition is the new method TopologyEvent.getEventType() that
returns the type of the event: SWITCH, PORT, LINK, HOST, MASTERSHIP
* Refactor and move around the implementation of methods like
hashCode() equals() and toString()
* Remove method getID() from classes MastershipEvent, SwitchEvent, PortEvent
LinkEvent, HostEvent, and keep it only in TopologyEvent where it is
actually needed.
* Changed class TopologyElement to abstract, and added two abstract
methods: getOriginDpid() and getIDasByteBuffer() which are already
implemented by all FooEvent derived classes.
No functional changes.
Change-Id: I62f4723cb3f4b519f365c04e7b736abda9b1973b
diff --git a/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java b/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
index 47f8e81..ad078c6 100644
--- a/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
@@ -56,48 +56,6 @@
return dpid;
}
- /**
- * Gets the event origin DPID.
- *
- * @return the event origin DPID.
- */
- public Dpid getOriginDpid() {
- return this.dpid;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
-
- if (o == null) {
- return false;
- }
-
- if (getClass() != o.getClass()) {
- return false;
- }
- SwitchEvent other = (SwitchEvent) o;
-
- // compare attributes
- if (!super.equals(o)) {
- return false;
- }
-
- return Objects.equals(this.dpid, other.dpid);
- }
-
- @Override
- public int hashCode() {
- return 31 * super.hashCode() + Objects.hashCode(dpid);
- }
-
- @Override
- public String toString() {
- return "[SwitchEvent " + dpid + "]";
- }
-
public static final int SWITCHID_BYTES = 2 + 8;
public static ByteBuffer getSwitchID(Dpid dpid) {
@@ -112,11 +70,42 @@
.putChar('S').putLong(dpid).flip();
}
- public byte[] getID() {
- return getSwitchID(dpid.value()).array();
+ @Override
+ public Dpid getOriginDpid() {
+ return this.dpid;
}
+ @Override
public ByteBuffer getIDasByteBuffer() {
return getSwitchID(dpid.value());
}
+
+ @Override
+ public int hashCode() {
+ return 31 * super.hashCode() + Objects.hashCode(dpid);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ // Compare attributes
+ if (!super.equals(o)) {
+ return false;
+ }
+
+ SwitchEvent other = (SwitchEvent) o;
+ return Objects.equals(this.dpid, other.dpid);
+ }
+
+ @Override
+ public String toString() {
+ return "[SwitchEvent " + dpid + "]";
+ }
}