You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/05/15 09:33:02 UTC

svn commit: r775045 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/builder/ test/org/apache/commons/lang/builder/

Author: bayard
Date: Fri May 15 07:33:02 2009
New Revision: 775045

URL: http://svn.apache.org/viewvc?rev=775045&view=rev
Log:
Genericizing per LANG-336. Removed two lines in the test that were trying to build a to string up to a class that was not in the hierarchy. The compiler now protects against this. 

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringBuilder.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java?rev=775045&r1=775044&r2=775045&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java Fri May 15 07:33:02 2009
@@ -303,8 +303,8 @@
      *            the superclass to reflect up to (inclusive), may be <code>null</code>
      * @return int hash code
      */
-    public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object object,
-            boolean testTransients, Class<?> reflectUpToClass) {
+    public static <T> int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object,
+            boolean testTransients, Class<? super T> reflectUpToClass) {
         return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients,
                 reflectUpToClass, null);
     }
@@ -354,8 +354,8 @@
      *             if the number is zero or even
      * @since 2.0
      */
-    public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object object,
-            boolean testTransients, Class<?> reflectUpToClass, String[] excludeFields) {
+    public static <T> int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object,
+            boolean testTransients, Class<? super T> reflectUpToClass, String[] excludeFields) {
 
         if (object == null) {
             throw new IllegalArgumentException("The object to build a hash code for must not be null");

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java?rev=775045&r1=775044&r2=775045&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java Fri May 15 07:33:02 2009
@@ -95,7 +95,7 @@
  * @since 2.0
  * @version $Id$
  */
-public class ReflectionToStringBuilder extends ToStringBuilder {
+public class ReflectionToStringBuilder<T> extends ToStringBuilder<T> {
 
     /**
      * <p>
@@ -284,9 +284,9 @@
      *             if the Object is <code>null</code>
      * @since 2.1
      */
-    public static String toString(Object object, ToStringStyle style, boolean outputTransients, boolean outputStatics,
-            Class<?> reflectUpToClass) {
-        return new ReflectionToStringBuilder(object, style, null, reflectUpToClass, outputTransients, outputStatics)
+    public static <T> String toString(T object, ToStringStyle style, boolean outputTransients, boolean outputStatics,
+            Class<? super T> reflectUpToClass) {
+        return new ReflectionToStringBuilder<T>(object, style, null, reflectUpToClass, outputTransients, outputStatics)
                 .toString();
     }
 
@@ -361,8 +361,8 @@
      *            The field names to exclude
      * @return The toString value.
      */
-    public static String toStringExclude(Object object, String[] excludeFieldNames) {
-        return new ReflectionToStringBuilder(object).setExcludeFieldNames(excludeFieldNames).toString();
+    public static <T> String toStringExclude(T object, String[] excludeFieldNames) {
+        return new ReflectionToStringBuilder<T>(object).setExcludeFieldNames(excludeFieldNames).toString();
     }
 
     /**
@@ -383,7 +383,7 @@
     /**
      * The last super class to stop appending fields for.
      */
-    private Class<?> upToClass = null;
+    private Class<? super T> upToClass = null;
 
     /**
      * <p>
@@ -399,7 +399,7 @@
      * @throws IllegalArgumentException
      *             if the Object passed in is <code>null</code>
      */
-    public ReflectionToStringBuilder(Object object) {
+    public ReflectionToStringBuilder(T object) {
         super(object);
     }
 
@@ -419,7 +419,7 @@
      * @throws IllegalArgumentException
      *             if the Object passed in is <code>null</code>
      */
-    public ReflectionToStringBuilder(Object object, ToStringStyle style) {
+    public ReflectionToStringBuilder(T object, ToStringStyle style) {
         super(object, style);
     }
 
@@ -445,7 +445,7 @@
      * @throws IllegalArgumentException
      *             if the Object passed in is <code>null</code>
      */
-    public ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer) {
+    public ReflectionToStringBuilder(T object, ToStringStyle style, StringBuffer buffer) {
         super(object, style, buffer);
     }
 
@@ -466,7 +466,7 @@
      *            whether to include static fields
      * @since 2.1
      */
-    public ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer, Class<?> reflectUpToClass,
+    public ReflectionToStringBuilder(T object, ToStringStyle style, StringBuffer buffer, Class<? super T> reflectUpToClass,
             boolean outputTransients, boolean outputStatics) {
         super(object, style, buffer);
         this.setUpToClass(reflectUpToClass);
@@ -616,7 +616,7 @@
      *            the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder reflectionAppendArray(Object array) {
+    public ToStringBuilder<T> reflectionAppendArray(Object array) {
         this.getStyle().reflectionAppendArrayDetail(this.getStringBuffer(), null, array);
         return this;
     }
@@ -653,7 +653,7 @@
      *            The excludeFieldNames to excluding from toString or <code>null</code>.
      * @return <code>this</code>
      */
-    public ReflectionToStringBuilder setExcludeFieldNames(String[] excludeFieldNamesParam) {
+    public ReflectionToStringBuilder<T> setExcludeFieldNames(String[] excludeFieldNamesParam) {
         if (excludeFieldNamesParam == null) {
             this.excludeFieldNames = null;
         } else {
@@ -671,7 +671,7 @@
      * @param clazz
      *            The last super class to stop appending fields for.
      */
-    public void setUpToClass(Class<?> clazz) {
+    public void setUpToClass(Class<? super T> clazz) {
         this.upToClass = clazz;
     }
 

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringBuilder.java?rev=775045&r1=775044&r2=775045&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringBuilder.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/ToStringBuilder.java Fri May 15 07:33:02 2009
@@ -90,7 +90,7 @@
  * @since 1.0
  * @version $Id$
  */
-public class ToStringBuilder {
+public class ToStringBuilder<T> {
 
     /**
      * The default style of output to use.
@@ -162,11 +162,11 @@
      * @see ReflectionToStringBuilder#toString(Object,ToStringStyle,boolean,boolean,Class)
      * @since 2.0
      */
-    public static String reflectionToString(
-        Object object,
+    public static <T> String reflectionToString(
+        T object,
         ToStringStyle style,
         boolean outputTransients,
-        Class reflectUpToClass) {
+        Class<? super T> reflectUpToClass) {
         return ReflectionToStringBuilder.toString(object, style, outputTransients, false, reflectUpToClass);
     }
 
@@ -191,7 +191,7 @@
     /**
      * The object being output.
      */
-    private final Object object;
+    private final T object;
 
     /**
      * The style of output to use.
@@ -208,7 +208,7 @@
      * @throws IllegalArgumentException  if the Object passed in is
      *  <code>null</code>
      */
-    public ToStringBuilder(Object object) {
+    public ToStringBuilder(T object) {
         this(object, getDefaultStyle(), null);
     }
 
@@ -224,7 +224,7 @@
      * @throws IllegalArgumentException  if the Object passed in is
      *  <code>null</code>
      */
-    public ToStringBuilder(Object object, ToStringStyle style) {
+    public ToStringBuilder(T object, ToStringStyle style) {
         this(object, style, null);
     }
 
@@ -241,7 +241,7 @@
      * @param buffer  the <code>StringBuffer</code> to populate, may be
      *  <code>null</code>
      */
-    public ToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer) {
+    public ToStringBuilder(T object, ToStringStyle style, StringBuffer buffer) {
         if (style == null) {
             style = getDefaultStyle();
         }
@@ -264,7 +264,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(boolean value) {
+    public ToStringBuilder<T> append(boolean value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -278,7 +278,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(boolean[] array) {
+    public ToStringBuilder<T> append(boolean[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -292,7 +292,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(byte value) {
+    public ToStringBuilder<T> append(byte value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -306,7 +306,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(byte[] array) {
+    public ToStringBuilder<T> append(byte[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -320,7 +320,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(char value) {
+    public ToStringBuilder<T> append(char value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -334,7 +334,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(char[] array) {
+    public ToStringBuilder<T> append(char[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -348,7 +348,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(double value) {
+    public ToStringBuilder<T> append(double value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -362,7 +362,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(double[] array) {
+    public ToStringBuilder<T> append(double[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -376,7 +376,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(float value) {
+    public ToStringBuilder<T> append(float value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -390,7 +390,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(float[] array) {
+    public ToStringBuilder<T> append(float[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -404,7 +404,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(int value) {
+    public ToStringBuilder<T> append(int value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -418,7 +418,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(int[] array) {
+    public ToStringBuilder<T> append(int[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -432,7 +432,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(long value) {
+    public ToStringBuilder<T> append(long value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -446,7 +446,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(long[] array) {
+    public ToStringBuilder<T> append(long[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -460,7 +460,7 @@
      * @param obj  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(Object obj) {
+    public ToStringBuilder<T> append(Object obj) {
         style.append(buffer, null, obj, null);
         return this;
     }
@@ -474,7 +474,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(Object[] array) {
+    public ToStringBuilder<T> append(Object[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -488,7 +488,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(short value) {
+    public ToStringBuilder<T> append(short value) {
         style.append(buffer, null, value);
         return this;
     }
@@ -502,7 +502,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(short[] array) {
+    public ToStringBuilder<T> append(short[] array) {
         style.append(buffer, null, array, null);
         return this;
     }
@@ -515,7 +515,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, boolean value) {
+    public ToStringBuilder<T> append(String fieldName, boolean value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -528,7 +528,7 @@
      * @param array  the array to add to the <code>hashCode</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, boolean[] array) {
+    public ToStringBuilder<T> append(String fieldName, boolean[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -548,7 +548,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, boolean[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, boolean[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -561,7 +561,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, byte value) {
+    public ToStringBuilder<T> append(String fieldName, byte value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -573,7 +573,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, byte[] array) {
+    public ToStringBuilder<T> append(String fieldName, byte[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -593,7 +593,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, byte[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, byte[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -606,7 +606,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, char value) {
+    public ToStringBuilder<T> append(String fieldName, char value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -619,7 +619,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, char[] array) {
+    public ToStringBuilder<T> append(String fieldName, char[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -639,7 +639,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, char[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, char[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -652,7 +652,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, double value) {
+    public ToStringBuilder<T> append(String fieldName, double value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -665,7 +665,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, double[] array) {
+    public ToStringBuilder<T> append(String fieldName, double[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -685,7 +685,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, double[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, double[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -698,7 +698,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, float value) {
+    public ToStringBuilder<T> append(String fieldName, float value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -711,7 +711,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, float[] array) {
+    public ToStringBuilder<T> append(String fieldName, float[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -731,7 +731,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, float[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, float[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -744,7 +744,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, int value) {
+    public ToStringBuilder<T> append(String fieldName, int value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -757,7 +757,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, int[] array) {
+    public ToStringBuilder<T> append(String fieldName, int[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -777,7 +777,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, int[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, int[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -790,7 +790,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, long value) {
+    public ToStringBuilder<T> append(String fieldName, long value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -803,7 +803,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, long[] array) {
+    public ToStringBuilder<T> append(String fieldName, long[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -823,7 +823,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, long[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, long[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -836,7 +836,7 @@
      * @param obj  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, Object obj) {
+    public ToStringBuilder<T> append(String fieldName, Object obj) {
         style.append(buffer, fieldName, obj, null);
         return this;
     }
@@ -851,7 +851,7 @@
      *  <code>false</code> for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, Object obj, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, Object obj, boolean fullDetail) {
         style.append(buffer, fieldName, obj, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -864,7 +864,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, Object[] array) {
+    public ToStringBuilder<T> append(String fieldName, Object[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -884,7 +884,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, Object[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, Object[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -897,7 +897,7 @@
      * @param value  the value to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, short value) {
+    public ToStringBuilder<T> append(String fieldName, short value) {
         style.append(buffer, fieldName, value);
         return this;
     }
@@ -910,7 +910,7 @@
      * @param array  the array to add to the <code>toString</code>
      * @return this
      */
-    public ToStringBuilder append(String fieldName, short[] array) {
+    public ToStringBuilder<T> append(String fieldName, short[] array) {
         style.append(buffer, fieldName, array, null);
         return this;
     }
@@ -930,7 +930,7 @@
      *  for summary info
      * @return this
      */
-    public ToStringBuilder append(String fieldName, short[] array, boolean fullDetail) {
+    public ToStringBuilder<T> append(String fieldName, short[] array, boolean fullDetail) {
         style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
         return this;
     }
@@ -944,7 +944,7 @@
      * @return this
      * @since 2.0
      */
-    public ToStringBuilder appendAsObjectToString(Object object) {
+    public ToStringBuilder<T> appendAsObjectToString(Object object) {
         ObjectUtils.identityToString(this.getStringBuffer(), object);
         return this;
     }
@@ -963,7 +963,7 @@
      * @return this
      * @since 2.0
      */
-    public ToStringBuilder appendSuper(String superToString) {
+    public ToStringBuilder<T> appendSuper(String superToString) {
         if (superToString != null) {
             style.appendSuper(buffer, superToString);
         }
@@ -997,7 +997,7 @@
      * @return this
      * @since 2.0
      */
-    public ToStringBuilder appendToString(String toString) {
+    public ToStringBuilder<T> appendToString(String toString) {
         if (toString != null) {
             style.appendToString(buffer, toString);
         }
@@ -1010,7 +1010,7 @@
      * @return The object being output.
      * @since 2.0
      */
-    public Object getObject() {
+    public T getObject() {
         return object;
     }
 

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java?rev=775045&r1=775044&r2=775045&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java Fri May 15 07:33:02 2009
@@ -340,7 +340,6 @@
         assertEquals(baseStr + "[a=a,transientA=t]", ToStringBuilder.reflectionToString(baseA, null, true));
         assertEquals(baseStr + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, null));
         assertEquals(baseStr + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, Object.class));
-        assertEquals(baseStr + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, List.class));
         assertEquals(baseStr + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, ReflectionTestFixtureA.class));
         
         ReflectionTestFixtureB baseB = new ReflectionTestFixtureB();
@@ -352,7 +351,6 @@
         assertEquals(baseStr + "[b=b,transientB=t,a=a,transientA=t]", ToStringBuilder.reflectionToString(baseB, null, true));
         assertEquals(baseStr + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, null));
         assertEquals(baseStr + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, Object.class));
-        assertEquals(baseStr + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, List.class));
         assertEquals(baseStr + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureA.class));
         assertEquals(baseStr + "[b=b]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureB.class));
         this.validateEmptyToStringStyleRegistry();



Re: svn commit: r775045 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/builder/ test/org/apache/commons/lang/builder/

Posted by sebb <se...@gmail.com>.
On 24/10/2009, Stephen Colebourne <sc...@btopenworld.com> wrote:
> bayard@apache.org wrote:
>
> > URL: http://svn.apache.org/viewvc?rev=775045&view=rev
> > Log:
> > Genericizing per LANG-336. Removed two lines in the test that were trying
> to build a to string up to a class that was not in the hierarchy. The
> compiler now protects against this.
> >
>  >
>
> > -public class ReflectionToStringBuilder extends ToStringBuilder {
> > +public class ReflectionToStringBuilder<T> extends ToStringBuilder<T> {
> >
>  >
>
> > -public class ToStringBuilder {
> > +public class ToStringBuilder<T> {
> >
> >
>
>  I think these gnerics are unecessary and provide insufficient benefit.

I'm inclined to agree.

The same applies even more to StrLookup, whose Javadoc says:

"Lookup a String key to a String value."

Why does that need generification?

>  The use case for ToStringBuilder is a quick and easy way to produce a
> toString. Users shouldn't have to manually specify the class that they are
> building the toString for. Compare today vs generics:
>
>  new ToStringBuilder()
>   .append(.......)
>   .toString();
>
>  new ToStringBuilder<Person>()
>   .append(.......)
>   .toString();
>
>  The issue of blocking the input specifying an invalid super class can be
> handled by method level generics on the static factory and constructor, plus
> a safety runtime check in setUpToClass().
>
>  Stephen
>
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Re: svn commit: r775045 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/builder/ test/org/apache/commons/lang/builder/

Posted by Stephen Colebourne <sc...@btopenworld.com>.
bayard@apache.org wrote:
> URL: http://svn.apache.org/viewvc?rev=775045&view=rev
> Log:
> Genericizing per LANG-336. Removed two lines in the test that were trying to build a to string up to a class that was not in the hierarchy. The compiler now protects against this. 
 >
> -public class ReflectionToStringBuilder extends ToStringBuilder {
> +public class ReflectionToStringBuilder<T> extends ToStringBuilder<T> {
 >
> -public class ToStringBuilder {
> +public class ToStringBuilder<T> {
>  

I think these gnerics are unecessary and provide insufficient benefit.

The use case for ToStringBuilder is a quick and easy way to produce a 
toString. Users shouldn't have to manually specify the class that they 
are building the toString for. Compare today vs generics:

new ToStringBuilder()
   .append(.......)
   .toString();

new ToStringBuilder<Person>()
   .append(.......)
   .toString();

The issue of blocking the input specifying an invalid super class can be 
  handled by method level generics on the static factory and 
constructor, plus a safety runtime check in setUpToClass().

Stephen


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