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/LinkEvent.java b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
index 807dcaf..bc5aa93 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
@@ -122,20 +122,6 @@
this.capacity = capacity;
}
- /**
- * Gets the event origin DPID.
- *
- * @return the event origin DPID.
- */
- public Dpid getOriginDpid() {
- return this.id.getDst().getDpid();
- }
-
- @Override
- public String toString() {
- return "[LinkEvent " + getSrc() + "->" + getDst() + "]";
- }
-
public static final int LINKID_BYTES = 2 + PortEvent.PORTID_BYTES * 2;
public static ByteBuffer getLinkID(Dpid srcDpid, PortNumber srcPortNo,
@@ -152,10 +138,12 @@
.put(PortEvent.getPortID(dstDpid, dstPortNo)).flip();
}
- public byte[] getID() {
- return getIDasByteBuffer().array();
+ @Override
+ public Dpid getOriginDpid() {
+ return this.id.getDst().getDpid();
}
+ @Override
public ByteBuffer getIDasByteBuffer() {
return getLinkID(getSrc().getDpid(), getSrc().getPortNumber(),
getDst().getDpid(), getDst().getPortNumber());
@@ -163,32 +151,30 @@
@Override
public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + Objects.hashCode(id);
- return result;
+ return 31 * super.hashCode() + Objects.hashCode(id);
}
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
- if (obj == null) {
+ if (o == null || getClass() != o.getClass()) {
return false;
}
- if (getClass() != obj.getClass()) {
- return false;
- }
- LinkEvent other = (LinkEvent) obj;
-
- // compare attributes
- if (!super.equals(obj)) {
+ // Compare attributes
+ if (!super.equals(o)) {
return false;
}
+ LinkEvent other = (LinkEvent) o;
return Objects.equals(this.id, other.id);
}
+
+ @Override
+ public String toString() {
+ return "[LinkEvent " + getSrc() + "->" + getDst() + "]";
+ }
}