ONOS-6259: Topo2 - Implement server-side highlighting model
- NOTE: Still WIP
- Implement doAggregation() in Traffic2Monitor.
- Plumb through call to get relevantSynthLinks().
- Create UiLinkId from LinkKey.
- Add reference to original UiLink in the UiSynthLink, (so we can use as a key later).
- TrafficLink enhancements:
-- Implement equals/hashCode
-- add a copy constructor
-- add mergeStats() method
-- add stats accessor methods

Change-Id: I693626971b3511b842e80cee7fcd2a252087597f
diff --git a/core/api/src/main/java/org/onosproject/ui/model/topo/UiLinkId.java b/core/api/src/main/java/org/onosproject/ui/model/topo/UiLinkId.java
index c8dae05..dd1b3b8 100644
--- a/core/api/src/main/java/org/onosproject/ui/model/topo/UiLinkId.java
+++ b/core/api/src/main/java/org/onosproject/ui/model/topo/UiLinkId.java
@@ -16,11 +16,13 @@
 
 package org.onosproject.ui.model.topo;
 
+import org.onlab.util.Identifier;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.ElementId;
 import org.onosproject.net.HostId;
 import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.region.RegionId;
 
@@ -40,7 +42,7 @@
     private static final String E_IDENTICAL = "Region IDs cannot be same";
 
     private static final Comparator<RegionId> REGION_ID_COMPARATOR =
-            (o1, o2) -> o1.toString().compareTo(o2.toString());
+            Comparator.comparing(Identifier::toString);
 
     /**
      * Designates the directionality of an underlying (uni-directional) link.
@@ -257,16 +259,28 @@
      *
      * @param link link for which the identifier is required
      * @return link identifier
-     * @throws NullPointerException if any of the required fields are null
+     * @throws NullPointerException if src or dst connect point is null
      */
     public static UiLinkId uiLinkId(Link link) {
-        ConnectPoint src = link.src();
-        ConnectPoint dst = link.dst();
+        return canonicalizeIdentifier(link.src(), link.dst());
+    }
+
+    /**
+     * Creates the canonical link identifier from the given link key.
+     *
+     * @param lk link key
+     * @return equivalent link identifier
+     * @throws NullPointerException if src or dst connect point is null
+     */
+    public static UiLinkId uiLinkId(LinkKey lk) {
+        return canonicalizeIdentifier(lk.src(), lk.dst());
+    }
+
+    private static UiLinkId canonicalizeIdentifier(ConnectPoint src, ConnectPoint dst) {
         if (src == null || dst == null) {
             throw new NullPointerException(
-                    "null src or dst connect point: " + link);
+                    "null src or dst connect point (illegal for UiLinkId)");
         }
-
         ElementId srcId = src.elementId();
         ElementId dstId = dst.elementId();