svn commit: r834549 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion: Converters.java DateTimeConverters.java MiscConverters.java NumberConverters.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r834549 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion: Converters.java DateTimeConverters.java MiscConverters.java NumberConverters.java

adrianc
Author: adrianc
Date: Tue Nov 10 17:14:58 2009
New Revision: 834549

URL: http://svn.apache.org/viewvc?rev=834549&view=rev
Log:
Minor improvements to the new object type Converters.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java?rev=834549&r1=834548&r2=834549&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java Tue Nov 10 17:14:58 2009
@@ -148,6 +148,9 @@
     @SuppressWarnings("unchecked")
     public static <S, T> Converter<S, T> getConverter(Class<S> sourceClass, Class<T> targetClass) throws ClassNotFoundException {
         String key = sourceClass.getName().concat(DELIMITER).concat(targetClass.getName());
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Getting converter: " + key, module);
+        }
         Converter<?, ?> result = converterMap.get(key);
         if (result == null) {
             if (!noConversions.contains(key)) {
@@ -216,33 +219,4 @@
         
     }
 
-/*
-    public static String mapSize() {
-        return "Map size = " + converterMap.size();
-    }
-
-    @SuppressWarnings("unchecked")
-    public static String runPerformanceTest() {
-        Object[] intArray = {1,2,3,4};
-        List obj = null;
-        try {
-            Converter<Object[],  List> converter = Converters.getConverter(Object[].class, List.class);
-            obj = converter.convert(intArray);
-        } catch (Exception e) {}
-        System.gc();
-        long newStart = System.currentTimeMillis();
-        try {
-            for (int i = 0; i < 1000000; i++) {
-                Converter<Object[],  List> converter = Converters.getConverter(Object[].class, List.class);
-                obj = converter.convert(intArray);
-            }
-        } catch (Exception e) {
-            Debug.logError(e, module);
-        }
-        long newStop = System.currentTimeMillis();
-        Debug.logInfo("Elapsed time = " + (newStop - newStart), module);
-        return "Elapsed time = " + (newStop - newStart) + ", List size = " + obj.size();
-    }
-*/
-
 }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java?rev=834549&r1=834548&r2=834549&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java Tue Nov 10 17:14:58 2009
@@ -291,6 +291,9 @@
         }
 
         public Calendar convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
+            if (obj.length() == 0) {
+                return null;
+            }
             DateFormat df = null;
             if (formatString == null || formatString.length() == 0) {
                 df = UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, locale);
@@ -318,6 +321,9 @@
     public static class StringToDate extends GenericLocalizedConverter<String, java.util.Date> {
 
         public java.util.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
+            if (obj.length() == 0) {
+                return null;
+            }
             DateFormat df = null;
             if (formatString == null || formatString.length() == 0) {
                 df = UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, locale);
@@ -360,6 +366,9 @@
     public static class StringToSqlDate extends GenericLocalizedConverter<String, java.sql.Date> {
 
         public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
+            if (obj.length() == 0) {
+                return null;
+            }
             DateFormat df = null;
             if (formatString == null || formatString.length() == 0) {
                 df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, locale);
@@ -386,6 +395,9 @@
     public static class StringToSqlTime extends GenericLocalizedConverter<String, java.sql.Time> {
 
         public java.sql.Time convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
+            if (obj.length() == 0) {
+                return null;
+            }
             DateFormat df = null;
             if (formatString == null || formatString.length() == 0) {
                 df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, locale);
@@ -412,6 +424,9 @@
     public static class StringToTimestamp extends GenericLocalizedConverter<String, java.sql.Timestamp> {
 
         public java.sql.Timestamp convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
+            if (obj.length() == 0) {
+                return null;
+            }
             DateFormat df = null;
             if (formatString == null || formatString.length() == 0) {
                 df = UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, locale);

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java?rev=834549&r1=834548&r2=834549&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java Tue Nov 10 17:14:58 2009
@@ -30,6 +30,41 @@
 
     public static final int CHAR_BUFFER_SIZE = 4096;
 
+    public static class ClobToString extends AbstractConverter<Clob, String> {
+
+        public String convert(Clob obj) throws ConversionException {
+            StringBuilder strBuf = new StringBuilder();
+            char[] inCharBuffer = new char[CHAR_BUFFER_SIZE];
+            int charsRead = 0;
+            Reader clobReader = null;
+            try {
+                clobReader =  obj.getCharacterStream();
+                while ((charsRead = clobReader.read(inCharBuffer, 0, CHAR_BUFFER_SIZE)) > 0) {
+                    strBuf.append(inCharBuffer, 0, charsRead);
+                }
+            } catch (Exception e) {
+                throw new ConversionException(e);
+            }
+            finally {
+                if (clobReader != null) {
+                    try {
+                        clobReader.close();
+                    } catch (IOException e) {}
+                }
+            }
+            return strBuf.toString();
+        }
+
+        public Class<Clob> getSourceClass() {
+            return Clob.class;
+        }
+
+        public Class<String> getTargetClass() {
+            return String.class;
+        }
+
+    }
+
     public static class LocaleToString extends AbstractConverter<Locale, String> {
 
         public String convert(Locale obj) throws ConversionException {
@@ -67,39 +102,4 @@
 
     }
 
-    public static class ClobToString extends AbstractConverter<Clob, String> {
-
-        public String convert(Clob obj) throws ConversionException {
-            StringBuilder strBuf = new StringBuilder();
-            char[] inCharBuffer = new char[CHAR_BUFFER_SIZE];
-            int charsRead = 0;
-            Reader clobReader = null;
-            try {
-                clobReader =  obj.getCharacterStream();
-                while ((charsRead = clobReader.read(inCharBuffer, 0, CHAR_BUFFER_SIZE)) > 0) {
-                    strBuf.append(inCharBuffer, 0, charsRead);
-                }
-            } catch (Exception e) {
-                throw new ConversionException(e);
-            }
-            finally {
-                if (clobReader != null) {
-                    try {
-                        clobReader.close();
-                    } catch (IOException e) {}
-                }
-            }
-            return strBuf.toString();
-        }
-
-        public Class<Clob> getSourceClass() {
-            return Clob.class;
-        }
-
-        public Class<String> getTargetClass() {
-            return String.class;
-        }
-
-    }
-
 }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java?rev=834549&r1=834548&r2=834549&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java Tue Nov 10 17:14:58 2009
@@ -710,6 +710,9 @@
     public static class StringToLong extends AbstractToNumberConverter<String, Long> {
 
         public Long convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
+            if (obj.length() == 0) {
+                return null;
+            }
             return this.fromString(obj, locale).longValue();
         }