Removing code smells
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / JSONUtilities.java
index 886a85c..9abd5a8 100644 (file)
@@ -7,9 +7,9 @@
  * * Licensed under the Apache License, Version 2.0 (the "License");\r
  * * you may not use this file except in compliance with the License.\r
  * * You may obtain a copy of the License at\r
- * * \r
+ * *\r
  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
+ * *\r
  *  * Unless required by applicable law or agreed to in writing, software\r
  * * distributed under the License is distributed on an "AS IS" BASIS,\r
  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 import java.util.Collection;\r
@@ -35,42 +37,52 @@ import java.util.Collection;
  * @version $Id: JSONUtilities.java,v 1.1 2013/04/26 21:00:26 eby Exp $\r
  */\r
 public class JSONUtilities {\r
-       /**\r
-        * Does the String <i>v</i> represent a valid Internet address (with or without a\r
-        * mask length appended).\r
-        * @param v the string to check\r
-        * @return true if valid, false otherwise\r
-        */\r
-       public static boolean validIPAddrOrSubnet(String v) {\r
-               String[] pp = { v, "" };\r
-               if (v.indexOf('/') > 0)\r
-                       pp = v.split("/");\r
-               try {\r
-                       InetAddress addr = InetAddress.getByName(pp[0]);\r
-                       if (pp[1].length() > 0) {\r
-                               // check subnet mask\r
-                               int mask = Integer.parseInt(pp[1]);\r
-                               if (mask > (addr.getAddress().length * 8))\r
-                                       return false;\r
-                       }\r
-                       return true;\r
-               } catch (UnknownHostException e) {\r
-                       return false;\r
-               }\r
-       }\r
-       /**\r
-        * Build a JSON array from a collection of Strings.\r
-        * @param coll the collection\r
-        * @return a String containing a JSON array\r
-        */\r
-       public static String createJSONArray(Collection<String> coll) {\r
-               StringBuilder sb = new StringBuilder("[");\r
-               String pfx = "\n";\r
-               for (String t : coll) {\r
-                       sb.append(pfx).append("  \"").append(t).append("\"");\r
-                       pfx = ",\n";\r
-               }\r
-               sb.append("\n]\n");\r
-               return sb.toString();\r
-       }\r
+\r
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+\r
+    private JSONUtilities(){\r
+\r
+    }\r
+    /**\r
+     * Does the String <i>v</i> represent a valid Internet address (with or without a\r
+     * mask length appended).\r
+     *\r
+     * @param v the string to check\r
+     * @return true if valid, false otherwise\r
+     */\r
+    public static boolean validIPAddrOrSubnet(String v) {\r
+        String[] pp = {v, ""};\r
+        if (v.indexOf('/') > 0)\r
+            pp = v.split("/");\r
+        try {\r
+            InetAddress addr = InetAddress.getByName(pp[0]);\r
+            if (pp[1].length() > 0) {\r
+                // check subnet mask\r
+                int mask = Integer.parseInt(pp[1]);\r
+                if (mask > (addr.getAddress().length * 8))\r
+                    return false;\r
+            }\r
+            return true;\r
+        } catch (UnknownHostException e) {\r
+            intlogger.error("PROV0001: " + e.getMessage(), e);\r
+            return false;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Build a JSON array from a collection of Strings.\r
+     *\r
+     * @param coll the collection\r
+     * @return a String containing a JSON array\r
+     */\r
+    public static String createJSONArray(Collection<String> coll) {\r
+        StringBuilder sb = new StringBuilder("[");\r
+        String pfx = "\n";\r
+        for (String t : coll) {\r
+            sb.append(pfx).append("  \"").append(t).append("\"");\r
+            pfx = ",\n";\r
+        }\r
+        sb.append("\n]\n");\r
+        return sb.toString();\r
+    }\r
 }\r