Remove generics as they provide little value and get in the way

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@829635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2009-10-25 19:59:31 +00:00
parent b1cf6305e5
commit 93a3b6b251
3 changed files with 101 additions and 70 deletions

View File

@ -95,7 +95,7 @@
* @since 2.0
* @version $Id$
*/
public class ReflectionToStringBuilder<T> extends ToStringBuilder<T> {
public class ReflectionToStringBuilder extends ToStringBuilder {
/**
* <p>
@ -284,9 +284,10 @@ public static String toString(Object object, ToStringStyle style, boolean output
* if the Object is <code>null</code>
* @since 2.1
*/
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)
public static <T> String toString(
T object, ToStringStyle style, boolean outputTransients,
boolean outputStatics, Class<? super T> reflectUpToClass) {
return new ReflectionToStringBuilder(object, style, null, reflectUpToClass, outputTransients, outputStatics)
.toString();
}
@ -361,8 +362,8 @@ static String[] toNoNullStringArray(Object[] array) {
* The field names to exclude
* @return The toString value.
*/
public static <T> String toStringExclude(T object, String[] excludeFieldNames) {
return new ReflectionToStringBuilder<T>(object).setExcludeFieldNames(excludeFieldNames).toString();
public static String toStringExclude(Object object, String[] excludeFieldNames) {
return new ReflectionToStringBuilder(object).setExcludeFieldNames(excludeFieldNames).toString();
}
/**
@ -383,7 +384,7 @@ public static <T> String toStringExclude(T object, String[] excludeFieldNames) {
/**
* The last super class to stop appending fields for.
*/
private Class<? super T> upToClass = null;
private Class<?> upToClass = null;
/**
* <p>
@ -399,7 +400,7 @@ public static <T> String toStringExclude(T object, String[] excludeFieldNames) {
* @throws IllegalArgumentException
* if the Object passed in is <code>null</code>
*/
public ReflectionToStringBuilder(T object) {
public ReflectionToStringBuilder(Object object) {
super(object);
}
@ -419,7 +420,7 @@ public ReflectionToStringBuilder(T object) {
* @throws IllegalArgumentException
* if the Object passed in is <code>null</code>
*/
public ReflectionToStringBuilder(T object, ToStringStyle style) {
public ReflectionToStringBuilder(Object object, ToStringStyle style) {
super(object, style);
}
@ -445,7 +446,7 @@ public ReflectionToStringBuilder(T object, ToStringStyle style) {
* @throws IllegalArgumentException
* if the Object passed in is <code>null</code>
*/
public ReflectionToStringBuilder(T object, ToStringStyle style, StringBuffer buffer) {
public ReflectionToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer) {
super(object, style, buffer);
}
@ -466,8 +467,9 @@ public ReflectionToStringBuilder(T object, ToStringStyle style, StringBuffer buf
* whether to include static fields
* @since 2.1
*/
public ReflectionToStringBuilder(T object, ToStringStyle style, StringBuffer buffer, Class<? super T> reflectUpToClass,
boolean outputTransients, boolean outputStatics) {
public <T> ReflectionToStringBuilder(
T object, ToStringStyle style, StringBuffer buffer,
Class<? super T> reflectUpToClass, boolean outputTransients, boolean outputStatics) {
super(object, style, buffer);
this.setUpToClass(reflectUpToClass);
this.setAppendTransients(outputTransients);
@ -616,7 +618,7 @@ public boolean isAppendTransients() {
* the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> reflectionAppendArray(Object array) {
public ReflectionToStringBuilder reflectionAppendArray(Object array) {
this.getStyle().reflectionAppendArrayDetail(this.getStringBuffer(), null, array);
return this;
}
@ -653,7 +655,7 @@ public void setAppendTransients(boolean appendTransients) {
* The excludeFieldNames to excluding from toString or <code>null</code>.
* @return <code>this</code>
*/
public ReflectionToStringBuilder<T> setExcludeFieldNames(String[] excludeFieldNamesParam) {
public ReflectionToStringBuilder setExcludeFieldNames(String[] excludeFieldNamesParam) {
if (excludeFieldNamesParam == null) {
this.excludeFieldNames = null;
} else {
@ -671,7 +673,13 @@ public ReflectionToStringBuilder<T> setExcludeFieldNames(String[] excludeFieldNa
* @param clazz
* The last super class to stop appending fields for.
*/
public void setUpToClass(Class<? super T> clazz) {
public void setUpToClass(Class<?> clazz) {
if (clazz != null) {
Object object = getObject();
if (object != null && clazz.isInstance(object) == false) {
throw new IllegalArgumentException("Specified class is not a superclass of the object");
}
}
this.upToClass = clazz;
}

View File

@ -89,7 +89,7 @@
* @since 1.0
* @version $Id$
*/
public class ToStringBuilder<T> {
public class ToStringBuilder {
/**
* The default style of output to use.
@ -190,7 +190,7 @@ public static void setDefaultStyle(ToStringStyle style) {
/**
* The object being output.
*/
private final T object;
private final Object object;
/**
* The style of output to use.
@ -207,7 +207,7 @@ public static void setDefaultStyle(ToStringStyle style) {
* @throws IllegalArgumentException if the Object passed in is
* <code>null</code>
*/
public ToStringBuilder(T object) {
public ToStringBuilder(Object object) {
this(object, getDefaultStyle(), null);
}
@ -223,7 +223,7 @@ public ToStringBuilder(T object) {
* @throws IllegalArgumentException if the Object passed in is
* <code>null</code>
*/
public ToStringBuilder(T object, ToStringStyle style) {
public ToStringBuilder(Object object, ToStringStyle style) {
this(object, style, null);
}
@ -240,7 +240,7 @@ public ToStringBuilder(T object, ToStringStyle style) {
* @param buffer the <code>StringBuffer</code> to populate, may be
* <code>null</code>
*/
public ToStringBuilder(T object, ToStringStyle style, StringBuffer buffer) {
public ToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer) {
if (style == null) {
style = getDefaultStyle();
}
@ -263,7 +263,7 @@ public ToStringBuilder(T object, ToStringStyle style, StringBuffer buffer) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(boolean value) {
public ToStringBuilder append(boolean value) {
style.append(buffer, null, value);
return this;
}
@ -277,7 +277,7 @@ public ToStringBuilder<T> append(boolean value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(boolean[] array) {
public ToStringBuilder append(boolean[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -291,7 +291,7 @@ public ToStringBuilder<T> append(boolean[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(byte value) {
public ToStringBuilder append(byte value) {
style.append(buffer, null, value);
return this;
}
@ -305,7 +305,7 @@ public ToStringBuilder<T> append(byte value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(byte[] array) {
public ToStringBuilder append(byte[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -319,7 +319,7 @@ public ToStringBuilder<T> append(byte[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(char value) {
public ToStringBuilder append(char value) {
style.append(buffer, null, value);
return this;
}
@ -333,7 +333,7 @@ public ToStringBuilder<T> append(char value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(char[] array) {
public ToStringBuilder append(char[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -347,7 +347,7 @@ public ToStringBuilder<T> append(char[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(double value) {
public ToStringBuilder append(double value) {
style.append(buffer, null, value);
return this;
}
@ -361,7 +361,7 @@ public ToStringBuilder<T> append(double value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(double[] array) {
public ToStringBuilder append(double[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -375,7 +375,7 @@ public ToStringBuilder<T> append(double[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(float value) {
public ToStringBuilder append(float value) {
style.append(buffer, null, value);
return this;
}
@ -389,7 +389,7 @@ public ToStringBuilder<T> append(float value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(float[] array) {
public ToStringBuilder append(float[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -403,7 +403,7 @@ public ToStringBuilder<T> append(float[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(int value) {
public ToStringBuilder append(int value) {
style.append(buffer, null, value);
return this;
}
@ -417,7 +417,7 @@ public ToStringBuilder<T> append(int value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(int[] array) {
public ToStringBuilder append(int[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -431,7 +431,7 @@ public ToStringBuilder<T> append(int[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(long value) {
public ToStringBuilder append(long value) {
style.append(buffer, null, value);
return this;
}
@ -445,7 +445,7 @@ public ToStringBuilder<T> append(long value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(long[] array) {
public ToStringBuilder append(long[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -459,7 +459,7 @@ public ToStringBuilder<T> append(long[] array) {
* @param obj the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(Object obj) {
public ToStringBuilder append(Object obj) {
style.append(buffer, null, obj, null);
return this;
}
@ -473,7 +473,7 @@ public ToStringBuilder<T> append(Object obj) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(Object[] array) {
public ToStringBuilder append(Object[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -487,7 +487,7 @@ public ToStringBuilder<T> append(Object[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(short value) {
public ToStringBuilder append(short value) {
style.append(buffer, null, value);
return this;
}
@ -501,7 +501,7 @@ public ToStringBuilder<T> append(short value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(short[] array) {
public ToStringBuilder append(short[] array) {
style.append(buffer, null, array, null);
return this;
}
@ -514,7 +514,7 @@ public ToStringBuilder<T> append(short[] array) {
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, boolean value) {
public ToStringBuilder append(String fieldName, boolean value) {
style.append(buffer, fieldName, value);
return this;
}
@ -527,7 +527,7 @@ public ToStringBuilder<T> append(String fieldName, boolean value) {
* @param array the array to add to the <code>hashCode</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, boolean[] array) {
public ToStringBuilder append(String fieldName, boolean[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -547,7 +547,7 @@ public ToStringBuilder<T> append(String fieldName, boolean[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, boolean[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, boolean[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -560,7 +560,7 @@ public ToStringBuilder<T> append(String fieldName, boolean[] array, boolean full
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, byte value) {
public ToStringBuilder append(String fieldName, byte value) {
style.append(buffer, fieldName, value);
return this;
}
@ -572,7 +572,7 @@ public ToStringBuilder<T> append(String fieldName, byte value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, byte[] array) {
public ToStringBuilder append(String fieldName, byte[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -592,7 +592,7 @@ public ToStringBuilder<T> append(String fieldName, byte[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, byte[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, byte[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -605,7 +605,7 @@ public ToStringBuilder<T> append(String fieldName, byte[] array, boolean fullDet
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, char value) {
public ToStringBuilder append(String fieldName, char value) {
style.append(buffer, fieldName, value);
return this;
}
@ -618,7 +618,7 @@ public ToStringBuilder<T> append(String fieldName, char value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, char[] array) {
public ToStringBuilder append(String fieldName, char[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -638,7 +638,7 @@ public ToStringBuilder<T> append(String fieldName, char[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, char[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, char[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -651,7 +651,7 @@ public ToStringBuilder<T> append(String fieldName, char[] array, boolean fullDet
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, double value) {
public ToStringBuilder append(String fieldName, double value) {
style.append(buffer, fieldName, value);
return this;
}
@ -664,7 +664,7 @@ public ToStringBuilder<T> append(String fieldName, double value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, double[] array) {
public ToStringBuilder append(String fieldName, double[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -684,7 +684,7 @@ public ToStringBuilder<T> append(String fieldName, double[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, double[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, double[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -697,7 +697,7 @@ public ToStringBuilder<T> append(String fieldName, double[] array, boolean fullD
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, float value) {
public ToStringBuilder append(String fieldName, float value) {
style.append(buffer, fieldName, value);
return this;
}
@ -710,7 +710,7 @@ public ToStringBuilder<T> append(String fieldName, float value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, float[] array) {
public ToStringBuilder append(String fieldName, float[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -730,7 +730,7 @@ public ToStringBuilder<T> append(String fieldName, float[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, float[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, float[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -743,7 +743,7 @@ public ToStringBuilder<T> append(String fieldName, float[] array, boolean fullDe
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, int value) {
public ToStringBuilder append(String fieldName, int value) {
style.append(buffer, fieldName, value);
return this;
}
@ -756,7 +756,7 @@ public ToStringBuilder<T> append(String fieldName, int value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, int[] array) {
public ToStringBuilder append(String fieldName, int[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -776,7 +776,7 @@ public ToStringBuilder<T> append(String fieldName, int[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, int[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, int[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -789,7 +789,7 @@ public ToStringBuilder<T> append(String fieldName, int[] array, boolean fullDeta
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, long value) {
public ToStringBuilder append(String fieldName, long value) {
style.append(buffer, fieldName, value);
return this;
}
@ -802,7 +802,7 @@ public ToStringBuilder<T> append(String fieldName, long value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, long[] array) {
public ToStringBuilder append(String fieldName, long[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -822,7 +822,7 @@ public ToStringBuilder<T> append(String fieldName, long[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, long[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, long[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -835,7 +835,7 @@ public ToStringBuilder<T> append(String fieldName, long[] array, boolean fullDet
* @param obj the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, Object obj) {
public ToStringBuilder append(String fieldName, Object obj) {
style.append(buffer, fieldName, obj, null);
return this;
}
@ -850,7 +850,7 @@ public ToStringBuilder<T> append(String fieldName, Object obj) {
* <code>false</code> for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, Object obj, boolean fullDetail) {
public ToStringBuilder append(String fieldName, Object obj, boolean fullDetail) {
style.append(buffer, fieldName, obj, Boolean.valueOf(fullDetail));
return this;
}
@ -863,7 +863,7 @@ public ToStringBuilder<T> append(String fieldName, Object obj, boolean fullDetai
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, Object[] array) {
public ToStringBuilder append(String fieldName, Object[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -883,7 +883,7 @@ public ToStringBuilder<T> append(String fieldName, Object[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, Object[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, Object[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -896,7 +896,7 @@ public ToStringBuilder<T> append(String fieldName, Object[] array, boolean fullD
* @param value the value to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, short value) {
public ToStringBuilder append(String fieldName, short value) {
style.append(buffer, fieldName, value);
return this;
}
@ -909,7 +909,7 @@ public ToStringBuilder<T> append(String fieldName, short value) {
* @param array the array to add to the <code>toString</code>
* @return this
*/
public ToStringBuilder<T> append(String fieldName, short[] array) {
public ToStringBuilder append(String fieldName, short[] array) {
style.append(buffer, fieldName, array, null);
return this;
}
@ -929,7 +929,7 @@ public ToStringBuilder<T> append(String fieldName, short[] array) {
* for summary info
* @return this
*/
public ToStringBuilder<T> append(String fieldName, short[] array, boolean fullDetail) {
public ToStringBuilder append(String fieldName, short[] array, boolean fullDetail) {
style.append(buffer, fieldName, array, Boolean.valueOf(fullDetail));
return this;
}
@ -943,7 +943,7 @@ public ToStringBuilder<T> append(String fieldName, short[] array, boolean fullDe
* @return this
* @since 2.0
*/
public ToStringBuilder<T> appendAsObjectToString(Object object) {
public ToStringBuilder appendAsObjectToString(Object object) {
ObjectUtils.identityToString(this.getStringBuffer(), object);
return this;
}
@ -962,7 +962,7 @@ public ToStringBuilder<T> appendAsObjectToString(Object object) {
* @return this
* @since 2.0
*/
public ToStringBuilder<T> appendSuper(String superToString) {
public ToStringBuilder appendSuper(String superToString) {
if (superToString != null) {
style.appendSuper(buffer, superToString);
}
@ -996,7 +996,7 @@ public ToStringBuilder<T> appendSuper(String superToString) {
* @return this
* @since 2.0
*/
public ToStringBuilder<T> appendToString(String toString) {
public ToStringBuilder appendToString(String toString) {
if (toString != null) {
style.appendToString(buffer, toString);
}
@ -1009,7 +1009,7 @@ public ToStringBuilder<T> appendToString(String toString) {
* @return The object being output.
* @since 2.0
*/
public T getObject() {
public Object getObject() {
return object;
}

View File

@ -953,6 +953,29 @@ public Object toStringWithStatics(Object object, ToStringStyle style, Class refl
return ReflectionToStringBuilder.toString(object, style, false, true, reflectUpToClass);
}
/**
* Tests ReflectionToStringBuilder setUpToClass().
*/
public void test_setUpToClass_valid() {
Integer val = new Integer(5);
ReflectionToStringBuilder test = new ReflectionToStringBuilder(val);
test.setUpToClass(Number.class);
}
/**
* Tests ReflectionToStringBuilder setUpToClass().
*/
public void test_setUpToClass_invalid() {
Integer val = new Integer(5);
ReflectionToStringBuilder test = new ReflectionToStringBuilder(val);
try {
test.setUpToClass(String.class);
fail();
} catch (IllegalArgumentException ex) {
// expected
}
}
/**
* Tests ReflectionToStringBuilder.toString() for statics.
*/