You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by fr...@apache.org on 2009/02/05 20:38:01 UTC

svn commit: r741255 - /incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/commons/ObjectUtils.java

Author: francisdb
Date: Thu Feb  5 19:38:00 2009
New Revision: 741255

URL: http://svn.apache.org/viewvc?rev=741255&view=rev
Log:
fixed possible threading issues with SimpleDateFormat
added missing javadoc tags

Modified:
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/commons/ObjectUtils.java

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/commons/ObjectUtils.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/commons/ObjectUtils.java?rev=741255&r1=741254&r2=741255&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/commons/ObjectUtils.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/commons/ObjectUtils.java Thu Feb  5 19:38:00 2009
@@ -60,8 +60,8 @@
     // Logger
     private static final Log log = LogFactory.getLog(ObjectUtils.class);
 
-    private static SimpleDateFormat dateFormat   = new SimpleDateFormat("yyyy-MM-dd");
-    private static SimpleDateFormat timeFormat   = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+    private static final String DATE_FORMAT = "yyyy-MM-dd";
+	private static final String DATETIME_FORMAT = "yyyy-MM-dd hh:mm:ss";
 
     private ObjectUtils()
     {
@@ -212,6 +212,7 @@
      * <P>
      * If the object value supplied is null or if conversion is not possible then defValue is returned.
      * @param v the object value to convert
+     * @param defValue the default value
      * @return the Long value of o or defValue
      */
     public static double getDouble(Object v, double defValue)
@@ -319,9 +320,9 @@
         try
         {   String str = v.toString();
             if (str.length() > 10)
-                return timeFormat.parse(str);
+                return new SimpleDateFormat(DATETIME_FORMAT).parse(str);
             else
-                return dateFormat.parse(str);
+                return new SimpleDateFormat(DATE_FORMAT).parse(str);
         } catch (Exception e)
         {
             log.error("Cannot convert value to date!", e);
@@ -340,7 +341,10 @@
      */
     public static String formatDate(Date date, boolean withTime)
     {
-        return (withTime) ? timeFormat.format(date) : dateFormat.format(date);
+    	if(withTime)
+    		return new SimpleDateFormat(DATETIME_FORMAT).format(date);
+    	else
+    		return new SimpleDateFormat(DATE_FORMAT).format(date);
     }
     
     /**
@@ -348,6 +352,7 @@
      * @param c the value type to convert to
      * @param v the object to convert
      * @return the Date value of o or null
+     * @throws ClassCastException 
      */
     @SuppressWarnings("unchecked")
     public static <T> T convert(Class<T> c, Object v)
@@ -405,7 +410,10 @@
     
     /**
      * Generic conversion function that will convert a list to another list type.
+     * @param t the type class
+     * @param source the source collection
      * @return the new list type
+     * @throws ClassCastException 
      */
     public static <T> List<T> convert(Class<T> t, Collection<? extends T> source)
         throws ClassCastException