commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r534011 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/converters/ test/org/apache/commons/beanutils/converters/
Date Tue, 01 May 2007 11:26:18 GMT
Author: niallp
Date: Tue May  1 04:26:17 2007
New Revision: 534011

URL: http://svn.apache.org/viewvc?view=rev&rev=534011
Log:
Remove StringBuffer conversion functionality (reverts r471625) - over complicates matters,
as per comments on BEANUTILS-258 

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/AbstractConverter.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/CharacterConverter.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ClassConverter.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/DateTimeConverter.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/NumberConverter.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ClassConverterTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/AbstractConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/AbstractConverter.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/AbstractConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/AbstractConverter.java
Tue May  1 04:26:17 2007
@@ -159,21 +159,9 @@
         if (value == null) {
             return handleMissing(targetType);
 
-        // Convert --> String or StringBuffer
-        } else if (targetType.equals(String.class) ||
-                targetType.equals(StringBuffer.class)) {
-            Object result = convertToString(value);
-            if (result == null) {
-                return getDefault(targetType);
-            } else if (type.equals(StringBuffer.class)) {
-                if (result instanceof StringBuffer) {
-                    return result;
-                } else {
-                    return new StringBuffer(result.toString());
-                }
-            } else {
-                return result.toString();
-            }
+        // Convert --> String
+        } else if (targetType.equals(String.class)) {
+            return convertToString(value);
 
         // No conversion necessary
         } else if (targetType.equals(sourceType)) {
@@ -200,18 +188,18 @@
     }
 
     /**
-     * Convert the input object into a String (or StringBuffer).
+     * Convert the input object into a String.
      * <p>
-     * <b>N.B.</b>This implementation simply returns the value unchanged.
-     * The {@link AbstractConverter#convert(Class, Object)} method
-     * checks the value returned by this method, converting to either
-     * a String or StringBuffer as required.
+     * <b>N.B.</b>This implementation simply uses the value's
+     * <code>toString()</code> method and should be overriden if a
+     * more sophisticated mechanism for <i>conversion to a String</i>
+     * is required.
      *
      * @param value The input value to be converted.
      * @return the converted String value.
      */
-    protected Object convertToString(Object value) {
-        return value;
+    protected String convertToString(Object value) {
+        return value.toString();
     }
 
     /**
@@ -288,7 +276,7 @@
      */
     protected Object handleMissing(Class type) {
 
-        if (useDefault || type.equals(String.class) || type.equals(StringBuffer.class)) {
+        if (useDefault || type.equals(String.class)) {
             Object value = getDefault(type);
             if (useDefault && value != null && !(type.equals(value.getClass())))
{
                 try {
@@ -333,8 +321,6 @@
     protected Object getDefault(Class type) {
         if (type.equals(String.class)) {
             return null;
-        } else if (type.equals(StringBuffer.class)) {
-            return new StringBuffer();
         } else {
             return defaultValue;
         }

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ArrayConverter.java
Tue May  1 04:26:17 2007
@@ -176,7 +176,7 @@
      * @param value The value to be converted.
      * @return the converted String value.
      */
-    protected Object convertToString(Object value) {
+    protected String convertToString(Object value) {
 
         Class type = value.getClass();
         if (!type.isArray()) {
@@ -187,7 +187,7 @@
 
         int size = Array.getLength(value);
         if (size == 0) {
-            return "";
+            return (String)getDefault(String.class);
         }
 
         // Create a StringBuffer containing a delimited list of the values
@@ -203,7 +203,7 @@
             }
         }
 
-        return buffer;
+        return buffer.toString();
 
     }
 

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/CharacterConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/CharacterConverter.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/CharacterConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/CharacterConverter.java
Tue May  1 04:26:17 2007
@@ -57,7 +57,7 @@
      * @param value The input value to be converted
      * @return the converted String value.
      */
-    protected Object convertToString(Object value) {
+    protected String convertToString(Object value) {
         String strValue = value.toString();
         return strValue.length() == 0 ? "" : strValue.substring(0, 1);
     }

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ClassConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ClassConverter.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ClassConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/ClassConverter.java
Tue May  1 04:26:17 2007
@@ -61,8 +61,8 @@
      * @param value The input value to be converted
      * @return the converted String value.
      */
-    protected Object convertToString(Object value) {
-        return (value instanceof Class) ? ((Class)value).getName() : value;
+    protected String convertToString(Object value) {
+        return (value instanceof Class) ? ((Class)value).getName() : value.toString();
     }
 
     /**

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/DateTimeConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/DateTimeConverter.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/DateTimeConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/DateTimeConverter.java
Tue May  1 04:26:17 2007
@@ -191,7 +191,7 @@
      * @param value The input value to be converted
      * @return the converted String value.
      */
-    protected Object convertToString(Object value) {
+    protected String convertToString(Object value) {
 
         Date date = null;
         if (value instanceof Date) {
@@ -202,7 +202,7 @@
             date = new Date(((Long)value).longValue());
         }
 
-        Object result = value;
+        String result = null;
         if (useLocaleFormat && date != null) {
             DateFormat format = null;
             if (patterns != null && patterns.length > 0) {
@@ -215,6 +215,11 @@
             if (log().isDebugEnabled()) {
                 log().debug("    Converted  to String using format '" + result + "'");
             }
+        } else {
+            result = value.toString();
+            if (log().isDebugEnabled()) {
+                log().debug("    Converted  to String using toString() '" + result + "'");
+             }
         }
         return result;
     }

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/NumberConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/NumberConverter.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/NumberConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/NumberConverter.java
Tue May  1 04:26:17 2007
@@ -167,15 +167,21 @@
      * @param value The input value to be converted
      * @return the converted String value.
      */
-    protected Object convertToString(Object value) {
+    protected String convertToString(Object value) {
 
-        Object result = value;
+        String result = null;
         if (useLocaleFormat && value instanceof Number) {
             NumberFormat format = getFormat();
             format.setGroupingUsed(false);
             result = format.format(value);
             if (log().isDebugEnabled()) {
                 log().debug("    Converted  to String using format '" + result + "'");
+            }
+
+        } else {
+            result = value.toString();
+            if (log().isDebugEnabled()) {
+                log().debug("    Converted  to String using toString() '" + result + "'");
             }
         }
         return result;

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ArrayConverterTestCase.java
Tue May  1 04:26:17 2007
@@ -147,16 +147,6 @@
             fail(msg + " failed " + e);
         }
 
-        // LONG[] --> StringBuffer
-        try {
-            msg = "LONG[] --> StringBuffer";
-            Object result = arrayConverter.convert(StringBuffer.class, LONGArray);
-            assertEquals(msg, StringBuffer.class, result.getClass());
-            assertEquals(msg, stringB, result.toString());
-        } catch (Exception e) {
-            fail(msg + " failed " + e);
-        }
-
         // LONG[] --> String[]
         try {
             msg = "long[] --> String[]";

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ClassConverterTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ClassConverterTestCase.java?view=diff&rev=534011&r1=534010&r2=534011
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ClassConverterTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/ClassConverterTestCase.java
Tue May  1 04:26:17 2007
@@ -68,14 +68,6 @@
         assertEquals("Value Test", "foo", converter.convert(String.class, "foo"));
         assertEquals("Value Test", "bar", converter.convert(String.class, new StringBuffer("bar")));
         assertEquals("Null Test",   null, converter.convert(String.class, null));
-
-        // StringBuffer Tests
-        Object result = converter.convert(StringBuffer.class, Integer.class);
-        assertEquals("StringBuffer Test", StringBuffer.class, result.getClass());
-        assertEquals("StringBuffer Test", "java.lang.Integer", result.toString());
-        result = converter.convert(StringBuffer.class, null);
-        assertEquals("StringBuffer Null", StringBuffer.class, result.getClass());
-        assertEquals("StringBuffer Null", "", result.toString());
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message