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.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@775045 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-05-15 07:33:02 +00:00
parent 7a75f11d58
commit ed49378250
4 changed files with 76 additions and 78 deletions

View File

@ -303,8 +303,8 @@ public class HashCodeBuilder {
* the superclass to reflect up to (inclusive), may be <code>null</code> * the superclass to reflect up to (inclusive), may be <code>null</code>
* @return int hash code * @return int hash code
*/ */
public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object object, public static <T> int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object,
boolean testTransients, Class<?> reflectUpToClass) { boolean testTransients, Class<? super T> reflectUpToClass) {
return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients,
reflectUpToClass, null); reflectUpToClass, null);
} }
@ -354,8 +354,8 @@ public class HashCodeBuilder {
* if the number is zero or even * if the number is zero or even
* @since 2.0 * @since 2.0
*/ */
public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object object, public static <T> int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object,
boolean testTransients, Class<?> reflectUpToClass, String[] excludeFields) { boolean testTransients, Class<? super T> reflectUpToClass, String[] excludeFields) {
if (object == null) { if (object == null) {
throw new IllegalArgumentException("The object to build a hash code for must not be null"); throw new IllegalArgumentException("The object to build a hash code for must not be null");

View File

@ -95,7 +95,7 @@ import org.apache.commons.lang.ClassUtils;
* @since 2.0 * @since 2.0
* @version $Id$ * @version $Id$
*/ */
public class ReflectionToStringBuilder extends ToStringBuilder { public class ReflectionToStringBuilder<T> extends ToStringBuilder<T> {
/** /**
* <p> * <p>
@ -284,9 +284,9 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* if the Object is <code>null</code> * if the Object is <code>null</code>
* @since 2.1 * @since 2.1
*/ */
public static String toString(Object object, ToStringStyle style, boolean outputTransients, boolean outputStatics, public static <T> String toString(T object, ToStringStyle style, boolean outputTransients, boolean outputStatics,
Class<?> reflectUpToClass) { Class<? super T> reflectUpToClass) {
return new ReflectionToStringBuilder(object, style, null, reflectUpToClass, outputTransients, outputStatics) return new ReflectionToStringBuilder<T>(object, style, null, reflectUpToClass, outputTransients, outputStatics)
.toString(); .toString();
} }
@ -361,8 +361,8 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* The field names to exclude * The field names to exclude
* @return The toString value. * @return The toString value.
*/ */
public static String toStringExclude(Object object, String[] excludeFieldNames) { public static <T> String toStringExclude(T object, String[] excludeFieldNames) {
return new ReflectionToStringBuilder(object).setExcludeFieldNames(excludeFieldNames).toString(); return new ReflectionToStringBuilder<T>(object).setExcludeFieldNames(excludeFieldNames).toString();
} }
/** /**
@ -383,7 +383,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
/** /**
* The last super class to stop appending fields for. * The last super class to stop appending fields for.
*/ */
private Class<?> upToClass = null; private Class<? super T> upToClass = null;
/** /**
* <p> * <p>
@ -399,7 +399,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* @throws IllegalArgumentException * @throws IllegalArgumentException
* if the Object passed in is <code>null</code> * if the Object passed in is <code>null</code>
*/ */
public ReflectionToStringBuilder(Object object) { public ReflectionToStringBuilder(T object) {
super(object); super(object);
} }
@ -419,7 +419,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* @throws IllegalArgumentException * @throws IllegalArgumentException
* if the Object passed in is <code>null</code> * if the Object passed in is <code>null</code>
*/ */
public ReflectionToStringBuilder(Object object, ToStringStyle style) { public ReflectionToStringBuilder(T object, ToStringStyle style) {
super(object, style); super(object, style);
} }
@ -445,7 +445,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* @throws IllegalArgumentException * @throws IllegalArgumentException
* if the Object passed in is <code>null</code> * 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); super(object, style, buffer);
} }
@ -466,7 +466,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* whether to include static fields * whether to include static fields
* @since 2.1 * @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) { boolean outputTransients, boolean outputStatics) {
super(object, style, buffer); super(object, style, buffer);
this.setUpToClass(reflectUpToClass); this.setUpToClass(reflectUpToClass);
@ -616,7 +616,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* the array to add to the <code>toString</code> * the array to add to the <code>toString</code>
* @return this * @return this
*/ */
public ToStringBuilder reflectionAppendArray(Object array) { public ToStringBuilder<T> reflectionAppendArray(Object array) {
this.getStyle().reflectionAppendArrayDetail(this.getStringBuffer(), null, array); this.getStyle().reflectionAppendArrayDetail(this.getStringBuffer(), null, array);
return this; return this;
} }
@ -653,7 +653,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* The excludeFieldNames to excluding from toString or <code>null</code>. * The excludeFieldNames to excluding from toString or <code>null</code>.
* @return <code>this</code> * @return <code>this</code>
*/ */
public ReflectionToStringBuilder setExcludeFieldNames(String[] excludeFieldNamesParam) { public ReflectionToStringBuilder<T> setExcludeFieldNames(String[] excludeFieldNamesParam) {
if (excludeFieldNamesParam == null) { if (excludeFieldNamesParam == null) {
this.excludeFieldNames = null; this.excludeFieldNames = null;
} else { } else {
@ -671,7 +671,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* @param clazz * @param clazz
* The last super class to stop appending fields for. * The last super class to stop appending fields for.
*/ */
public void setUpToClass(Class<?> clazz) { public void setUpToClass(Class<? super T> clazz) {
this.upToClass = clazz; this.upToClass = clazz;
} }

View File

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

View File

@ -340,7 +340,6 @@ public class ToStringBuilderTest extends TestCase {
assertEquals(baseStr + "[a=a,transientA=t]", ToStringBuilder.reflectionToString(baseA, null, true)); 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, null));
assertEquals(baseStr + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, Object.class)); 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)); assertEquals(baseStr + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, ReflectionTestFixtureA.class));
ReflectionTestFixtureB baseB = new ReflectionTestFixtureB(); ReflectionTestFixtureB baseB = new ReflectionTestFixtureB();
@ -352,7 +351,6 @@ public class ToStringBuilderTest extends TestCase {
assertEquals(baseStr + "[b=b,transientB=t,a=a,transientA=t]", ToStringBuilder.reflectionToString(baseB, null, true)); 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, 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, 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,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureA.class));
assertEquals(baseStr + "[b=b]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureB.class)); assertEquals(baseStr + "[b=b]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureB.class));
this.validateEmptyToStringStyleRegistry(); this.validateEmptyToStringStyleRegistry();