Cleanup utility classes 89/5489/7
authorRobert Varga <rovarga@cisco.com>
Thu, 27 Feb 2014 16:26:21 +0000 (17:26 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 14 Apr 2014 07:47:59 +0000 (07:47 +0000)
Do not allow them to be instantiated, add a few comments and eliminate
e.printStackTrace();

Change-Id: I2e84bd81f2b91431791305fb61ca597337e98ae8
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/InventoryUtils.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfInventoryUtils.java

index 5c6702ae640f66d412aae775e80d044f84d08df5..e6dc59cc107dafa859b3b2a5481d2ec3e12fff37 100644 (file)
@@ -14,9 +14,11 @@ import java.util.Date;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class InventoryUtils {
-
+    private static final Logger LOG = LoggerFactory.getLogger(InventoryUtils.class);
     private static final URI INVENTORY_NAMESPACE = URI.create("urn:opendaylight:inventory");
     private static final URI NETCONF_INVENTORY_NAMESPACE = URI.create("urn:opendaylight:netconf-node-inventory");
     private static final Date INVENTORY_REVISION = dateFromString("2013-08-19");
@@ -33,18 +35,23 @@ public class InventoryUtils {
             .toInstance();
     public static final QName NETCONF_INVENTORY_MOUNT = null;
 
+    private InventoryUtils() {
+        throw new UnsupportedOperationException("Utility class cannot be instantiated");
+    }
+
     /**
      * Converts date in string format yyyy-MM-dd to java.util.Date.
-     * 
+     *
      * @return java.util.Date conformant to string formatted date yyyy-MM-dd.
      */
     private static Date dateFromString(final String date) {
+        // We do not reuse the formatter because it's not thread-safe
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
         try {
             return formatter.parse(date);
         } catch (ParseException e) {
-            e.printStackTrace();
+            LOG.error("Failed to parse date {}", date, e);
+            return null;
         }
-        return null;
     }
 }
index bae0f089473be0b5dab92d717dc52b800a4cf57d..b68f18f52ebb06a47dc57249ae990469b5d0693b 100644 (file)
@@ -11,18 +11,19 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 public class NetconfInventoryUtils {
-
-    
     public static final QName NETCONF_MOUNT = null;
     public static final QName NETCONF_ENDPOINT = null;
     public static final QName NETCONF_ENDPOINT_ADDRESS = null;
     public static final QName NETCONF_ENDPOINT_PORT = null;
 
+    private NetconfInventoryUtils() {
+        throw new UnsupportedOperationException("Utility class cannot be instantiated");
+    }
 
     public static String getEndpointAddress(CompositeNode node) {
         return node.getCompositesByName(NETCONF_ENDPOINT).get(0).getFirstSimpleByName(NETCONF_ENDPOINT_ADDRESS).getValue().toString();
     }
-    
+
     public static String getEndpointPort(CompositeNode node) {
         return node.getCompositesByName(NETCONF_ENDPOINT).get(0).getFirstSimpleByName(NETCONF_ENDPOINT_PORT).getValue().toString();
     }