Add static factory method to create ConnectPoints from strings.

Change-Id: I743b4a4fb433ad07cf6f2cbed3da7b6e19a74ebb
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
index 08f1fa4..c8d91d5 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
@@ -63,7 +63,6 @@
 
     @Override
     protected void execute() {
-
         FlowRuleService flowService = get(FlowRuleService.class);
         DeviceService deviceService = get(DeviceService.class);
         CoreService coreService = get(CoreService.class);
@@ -99,7 +98,6 @@
         }
 
         for (int i = 0; i < num; i++) {
-
             latch = new CountDownLatch(2);
             flowService.apply(rules.build(new FlowRuleOperationsContext() {
 
@@ -121,7 +119,6 @@
                 }
             }));
 
-
             flowService.apply(remove.build(new FlowRuleOperationsContext() {
                 @Override
                 public void onSuccess(FlowRuleOperations ops) {
@@ -135,14 +132,8 @@
             }
 
         }
-
-
-
-
     }
 
-
-
     private Object json(ObjectMapper mapper, boolean isSuccess, ArrayList<Long> elapsed) {
         ObjectNode result = mapper.createObjectNode();
         result.put("Success", isSuccess);
@@ -159,6 +150,4 @@
             print("  Run %s : %s", i, elapsed.get(i));
         }
     }
-
-
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java b/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java
index 8396e9d..0983aff 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java
@@ -1,23 +1,18 @@
 package org.onosproject.cli.net;
 
-import java.util.List;
-import java.util.Optional;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.onlab.packet.MplsLabel;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.MplsIntent;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
+import java.util.List;
+import java.util.Optional;
 
 /**
  * Installs MPLS intents.
@@ -53,19 +48,14 @@
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingress = new ConnectPoint(ingressDeviceId,
-                                                ingressPortNumber);
+        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
         Optional<MplsLabel> ingressLabel = Optional.empty();
         if (!ingressLabelString.isEmpty()) {
             ingressLabel = Optional
                     .ofNullable(MplsLabel.mplsLabel(parseInt(ingressLabelString)));
         }
 
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
         Optional<MplsLabel> egressLabel = Optional.empty();
         if (!ingressLabelString.isEmpty()) {
@@ -92,34 +82,6 @@
         service.submit(intent);
     }
 
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    public static String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    public static String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
-
     protected Integer parseInt(String value) {
         try {
             return Integer.parseInt(value);
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
index 66083b8..dc792f4 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
@@ -18,8 +18,6 @@
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
@@ -31,9 +29,6 @@
 import java.util.List;
 import java.util.Set;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Installs connectivity intent between multiple ingress devices and a single egress device.
  */
@@ -55,16 +50,12 @@
         }
 
         String egressDeviceString = deviceStrings[deviceStrings.length - 1];
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
-        Set<ConnectPoint> ingressPoints = new HashSet<>();
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
+        Set<ConnectPoint> ingressPoints = new HashSet<>();
         for (int index = 0; index < deviceStrings.length - 1; index++) {
             String ingressDeviceString = deviceStrings[index];
-            DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-            PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-            ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+            ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
             ingressPoints.add(ingress);
         }
 
@@ -85,32 +76,4 @@
         service.submit(intent);
         print("Multipoint to single point intent submitted:\n%s", intent.toString());
     }
-
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    private String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    private String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
index 4a9cac8..f0e2bd2 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
@@ -15,14 +15,9 @@
  */
 package org.onosproject.cli.net;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.OpticalConnectivityIntent;
@@ -48,13 +43,9 @@
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
 
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
         Intent intent = OpticalConnectivityIntent.builder()
                 .appId(appId())
@@ -65,32 +56,4 @@
         service.submit(intent);
         print("Optical intent submitted:\n%s", intent.toString());
     }
-
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    private String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    private String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
index e06a682..7c27dd3 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
@@ -15,13 +15,9 @@
  */
 package org.onosproject.cli.net;
 
-import java.util.List;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
@@ -29,8 +25,7 @@
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.PointToPointIntent;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
+import java.util.List;
 
 /**
  * Installs point-to-point connectivity intents.
@@ -49,18 +44,13 @@
               required = true, multiValued = false)
     String egressDeviceString = null;
 
-
     @Override
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
 
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
         TrafficSelector selector = buildTrafficSelector();
         TrafficTreatment treatment = buildTrafficTreatment();
@@ -80,32 +70,4 @@
         service.submit(intent);
         print("Point to point intent submitted:\n%s", intent.toString());
     }
-
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    public static String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    public static String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
index cdf4a73..2939afa 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
@@ -15,15 +15,9 @@
  */
 package org.onosproject.cli.net;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
@@ -31,8 +25,9 @@
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * Installs connectivity intent between a single ingress device and multiple egress devices.
@@ -54,18 +49,12 @@
         }
 
         String ingressDeviceString = deviceStrings[0];
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingressPoint = new ConnectPoint(ingressDeviceId,
-                                                     ingressPortNumber);
+        ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString);
 
         Set<ConnectPoint> egressPoints = new HashSet<>();
         for (int index = 1; index < deviceStrings.length; index++) {
             String egressDeviceString = deviceStrings[index];
-            DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-            PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-            ConnectPoint egress = new ConnectPoint(egressDeviceId,
-                                                   egressPortNumber);
+            ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
             egressPoints.add(egress);
         }
 
@@ -88,32 +77,4 @@
         print("Single point to multipoint intent submitted:\n%s", intent.toString());
     }
 
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    private String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    private String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
-
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java b/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
index 0f5ad07..626777e 100644
--- a/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
@@ -25,11 +25,6 @@
 import java.util.List;
 import java.util.SortedSet;
 
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Link destination end-point completer.
  */
@@ -49,8 +44,7 @@
         // Generate the device ID/port number identifiers
         SortedSet<String> strings = delegate.getStrings();
         try {
-            ConnectPoint src = new ConnectPoint(deviceId(getDeviceId(srcArg)),
-                                                portNumber(getPortNumber(srcArg)));
+            ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg);
             service.getEgressLinks(src)
                     .forEach(link -> strings.add(link.dst().elementId().toString() +
                                                          "/" + link.dst().port()));
diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java
index d125399..d45be27f 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java
@@ -19,18 +19,11 @@
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.link.LinkService;
 import org.onosproject.net.resource.LinkResourceAllocations;
 import org.onosproject.net.resource.LinkResourceService;
 
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Lists allocations by link.
  */
@@ -55,13 +48,9 @@
 
         Iterable<LinkResourceAllocations> itr = null;
         try {
-            DeviceId ingressDeviceId = deviceId(getDeviceId(srcString));
-            PortNumber ingressPortNumber = portNumber(getPortNumber(srcString));
-            ConnectPoint src = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+            ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
 
-            DeviceId egressDeviceId = deviceId(getDeviceId(dstString));
-            PortNumber egressPortNumber = portNumber(getPortNumber(dstString));
-            ConnectPoint dst = new ConnectPoint(egressDeviceId, egressPortNumber);
+            ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
 
             Link link = linkService.getLink(src, dst);
 
diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java
index 65416b2..42824ab 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java
@@ -19,18 +19,11 @@
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.link.LinkService;
 import org.onosproject.net.resource.LinkResourceService;
 import org.onosproject.net.resource.ResourceRequest;
 
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Lists allocations by link.
  */
@@ -55,13 +48,9 @@
 
         Iterable<ResourceRequest> itr = null;
         try {
-            DeviceId ingressDeviceId = deviceId(getDeviceId(srcString));
-            PortNumber ingressPortNumber = portNumber(getPortNumber(srcString));
-            ConnectPoint src = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+            ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
 
-            DeviceId egressDeviceId = deviceId(getDeviceId(dstString));
-            PortNumber egressPortNumber = portNumber(getPortNumber(dstString));
-            ConnectPoint dst = new ConnectPoint(egressDeviceId, egressPortNumber);
+            ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
 
             Link link = linkService.getLink(src, dst);