Cleanups to REST code suggested by Sonar

Change-Id: Ia399da70e7cd140514e07b63d9b2965fe86bbce7
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
index f77bb43..45529a4 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
@@ -142,21 +142,21 @@
                                InputStream stream) {
         URI location;
         try {
-            FlowRuleService service = get(FlowRuleService.class);
-            ObjectNode root = (ObjectNode) mapper().readTree(stream);
-            JsonNode specifiedDeviceId = root.get("deviceId");
+            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+            JsonNode specifiedDeviceId = jsonTree.get("deviceId");
             if (specifiedDeviceId != null &&
                     !specifiedDeviceId.asText().equals(deviceId)) {
                 throw new IllegalArgumentException(
                         "Invalid deviceId in flow creation request");
             }
-            root.put("deviceId", deviceId);
-            FlowRule rule = codec(FlowRule.class).decode(root, this);
+            jsonTree.put("deviceId", deviceId);
+            FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
             service.applyFlowRules(rule);
             location = new URI(Long.toString(rule.id().value()));
         } catch (IOException | URISyntaxException ex) {
-            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new IllegalArgumentException(ex);
         }
+
         return Response
                 .created(location)
                 .build();
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
index b34d4eb..9d3fd7f 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
@@ -125,7 +125,7 @@
             hostProviderRegistry.unregister(hostProvider);
 
         } catch (IOException ex) {
-            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            throw new IllegalArgumentException(ex);
         }
         return Response
                 .created(location)
@@ -137,19 +137,20 @@
                 new ProviderId("host", "org.onosproject.rest", true);
         private HostProviderService hostProviderService;
 
-        // Not implemented since there is no need to check for hosts on network
-        public void triggerProbe(Host host) {
+        private InternalHostProvider() {
         }
 
-        // Creates new InternalHostProvider with a HostProviderRegistry param.
-        private InternalHostProvider() {
+        public void triggerProbe(Host host) {
+            // Not implemented since there is no need to check for hosts on network
         }
 
         public void setHostProviderService(HostProviderService service) {
             this.hostProviderService = service;
         }
 
-        // Return the ProviderId of "this"
+        /*
+         * Return the ProviderId of "this"
+         */
         public ProviderId id() {
             return providerId;
         }
@@ -161,7 +162,7 @@
          */
         private HostId parseHost(JsonNode node) {
             MacAddress mac = MacAddress.valueOf(node.get("mac").asText());
-            VlanId vlanId = VlanId.vlanId(((short) node.get("vlan").asInt((VlanId.UNTAGGED))));
+            VlanId vlanId = VlanId.vlanId((short) node.get("vlan").asInt(VlanId.UNTAGGED));
             JsonNode locationNode = node.get("location");
             String deviceAndPort = locationNode.get("elementId").asText() + "/" +
                     locationNode.get("port").asText();
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
index 1ef6b3f..1922d03 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
@@ -35,7 +35,11 @@
 @Path("links")
 public class LinksWebResource extends AbstractWebResource {
 
-    enum Direction { ALL, INGRESS, EGRESS }
+    enum Direction {
+        ALL,
+        INGRESS,
+        EGRESS
+    }
 
     @GET
     public Response getLinks(@QueryParam("device") String deviceId,
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
index 4e2c790..ff7502d 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
@@ -280,13 +280,11 @@
     @SuppressWarnings("unchecked")
     public Response delete() {
         NetworkConfigService service = get(NetworkConfigService.class);
-        service.getSubjectClasses().forEach(subjectClass -> {
-            service.getSubjects(subjectClass).forEach(subject -> {
-                service.getConfigs(subject).forEach(config -> {
-                    service.removeConfig(subject, config.getClass());
-                });
-            });
-        });
+        service.getSubjectClasses()
+                .forEach(subjectClass -> service.getSubjects(subjectClass)
+                        .forEach(subject -> service.getConfigs(subject)
+                                .forEach(config -> service
+                                        .removeConfig(subject, config.getClass()))));
         return Response.ok().build();
     }
 
@@ -303,11 +301,10 @@
     @SuppressWarnings("unchecked")
     public Response delete(@PathParam("subjectKey") String subjectKey) {
         NetworkConfigService service = get(NetworkConfigService.class);
-        service.getSubjects(service.getSubjectFactory(subjectKey).getClass()).forEach(subject -> {
-            service.getConfigs(subject).forEach(config -> {
-                service.removeConfig(subject, config.getClass());
-            });
-        });
+        service.getSubjects(service.getSubjectFactory(subjectKey).getClass())
+                .forEach(subject -> service.getConfigs(subject)
+                        .forEach(config -> service
+                                .removeConfig(subject, config.getClass())));
         return Response.ok().build();
     }
 }
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java
index a97a933..42bd4e1 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java
@@ -38,25 +38,16 @@
 @Path("paths")
 public class PathsWebResource extends AbstractWebResource {
 
-    // Host id format is 00:00:00:00:00:01/-1
-    private static final int VLAN_SEPARATOR_OFFSET = 17;
-    private static final int FIRST_MAC_ADDRESS_SEPARATOR_OFFSET = 2;
-    private static final int SECOND_MAC_ADDRESS_SEPARATOR_OFFSET = 5;
-    private static final int THIRD_MAC_ADDRESS_SEPARATOR_OFFSET = 8;
-
     /**
      * Determines if the id appears to be the id of a host.
+     * Host id format is 00:00:00:00:00:01/-1
      *
      * @param id id string
      * @return HostId if the id is valid, null otherwise
      */
     private HostId isHostId(String id) {
 
-        if (id.length() < VLAN_SEPARATOR_OFFSET + 1 ||
-            id.charAt(FIRST_MAC_ADDRESS_SEPARATOR_OFFSET) != ':' ||
-            id.charAt(SECOND_MAC_ADDRESS_SEPARATOR_OFFSET) != ':' ||
-            id.charAt(THIRD_MAC_ADDRESS_SEPARATOR_OFFSET) != ':' ||
-            id.charAt(VLAN_SEPARATOR_OFFSET) != '/') {
+        if (!id.matches("..:..:..:..:..:../.*")) {
             return null;
         }