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/MastershipEvent.java b/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java
index 589174d..1d54a52 100644
--- a/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java
@@ -89,28 +89,16 @@
         return role;
     }
 
-    /**
-     * Gets the event origin DPID.
-     *
-     * @return the event origin DPID.
-     */
+    @Override
     public Dpid getOriginDpid() {
         return this.dpid;
     }
 
     @Override
-    public String toString() {
-        return "[MastershipEvent " + getDpid() + "@" + getOnosInstanceId() +
-            "->" + getRole() + "]";
-    }
-
-    public byte[] getID() {
-        String keyStr = "M" + getDpid() + "@" + getOnosInstanceId();
-        return keyStr.getBytes(StandardCharsets.UTF_8);
-    }
-
     public ByteBuffer getIDasByteBuffer() {
-        ByteBuffer buf = ByteBuffer.wrap(getID());
+        String keyStr = "M" + getDpid() + "@" + getOnosInstanceId();
+        byte[] id = keyStr.getBytes(StandardCharsets.UTF_8);
+        ByteBuffer buf = ByteBuffer.wrap(id);
         return buf;
     }
 
@@ -124,30 +112,32 @@
      * MastershipEvent objects are equal if they have same DPID and same
      * ONOS Instance ID.
      *
-     * @param obj another object to compare to this
-     * @return true if equal, false otherwise false.
+     * @param o another object to compare to this.
+     * @return true if equal, false otherwise.
      */
     @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()) {
+        // Compare attributes
+        if (!super.equals(o)) {
             return false;
         }
 
-        // compare attributes
-        if (!super.equals(obj)) {
-            return false;
-        }
+        MastershipEvent other = (MastershipEvent) o;
+        return Objects.equals(dpid, other.dpid) &&
+            Objects.equals(onosInstanceId, other.onosInstanceId);
+    }
 
-        MastershipEvent other = (MastershipEvent) obj;
-        return dpid.equals(other.dpid) &&
-            onosInstanceId.equals(other.onosInstanceId);
+    @Override
+    public String toString() {
+        return "[MastershipEvent " + getDpid() + "@" + getOnosInstanceId() +
+            "->" + getRole() + "]";
     }
 }