From 3bcf7382205a164a2725688fbd505e7494205732 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Sat, 31 May 2003 22:22:49 +0000 Subject: [PATCH] Sort Members (Eclipse). git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137352 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang/builder/ToStringBuilder.java | 1784 ++++++++--------- 1 file changed, 892 insertions(+), 892 deletions(-) diff --git a/src/java/org/apache/commons/lang/builder/ToStringBuilder.java b/src/java/org/apache/commons/lang/builder/ToStringBuilder.java index ccc7d6f2b..6898d1a86 100644 --- a/src/java/org/apache/commons/lang/builder/ToStringBuilder.java +++ b/src/java/org/apache/commons/lang/builder/ToStringBuilder.java @@ -122,9 +122,14 @@ import java.util.Set; * @author Stephen Colebourne * @author Gary Gregory * @since 1.0 - * @version $Id: ToStringBuilder.java,v 1.20 2003/04/18 07:01:47 ggregory Exp $ + * @version $Id: ToStringBuilder.java,v 1.21 2003/05/31 22:22:49 ggregory Exp $ */ public class ToStringBuilder { + + /** + * The default style of output to use + */ + private static ToStringStyle defaultStyle = ToStringStyle.DEFAULT_STYLE; /** * A registry of objects used by reflectionToString methods to detect cyclical object references @@ -136,26 +141,24 @@ public class ToStringBuilder { return new HashSet(); } }; - + + //---------------------------------------------------------------------------- + /** - * The default style of output to use + *

Gets the default ToStringStyle to use.

+ * + *

This could allow the ToStringStyle to be + * controlled for an entire application with one call.

+ * + *

This might be used to have a verbose + * ToStringStyle during development and a compact + * ToStringStyle in production.

+ * + * @return the default ToStringStyle */ - private static ToStringStyle defaultStyle = ToStringStyle.DEFAULT_STYLE; - - /** - * Current toString buffer - */ - private final StringBuffer buffer; - - /** - * The style of output to use - */ - private final ToStringStyle style; - - /** - * The object being output - */ - private final Object object; + public static ToStringStyle getDefaultStyle() { + return defaultStyle; + } /** * Returns the registry of objects being traversed by the @@ -178,120 +181,68 @@ public class ToStringBuilder { } /** - * Registers the given object. - * Used by the reflection methods to avoid infinite loops. + * Appends the fields and values defined by the given object of the + * given Class. If a cycle is detected as an objects is "toString()'ed", + * such an object is rendered as if Object.toString() + * had been called and not implemented by the object. * - * @param value The object to register. + * @param object the object to append details of + * @param clazz the class of object parameter + * @param builder the builder to append to + * @param useTransients whether to output transient fields */ - static void register(Object value) { - getReflectionRegistry().add(value); - } - - /** - * Unregisters the given object. - * Used by the reflection methods to avoid infinite loops. - * - * @param value The object to unregister. - */ - static void unregister(Object value) { - getReflectionRegistry().remove(value); - } - - /** - *

Constructor for ToStringBuilder.

- * - *

This constructor outputs using the default style set with - * setDefaultStyle.

- * - * @param object the Object to build a toString for, - * must not be null - * @throws IllegalArgumentException if the Object passed in is - * null - */ - public ToStringBuilder(Object object) { - this(object, getDefaultStyle(), null); - } - - /** - *

Constructor for ToStringBuilder specifying the - * output style.

- * - *

If the style is null, the default style is used.

- * - * @param object the Object to build a toString for, - * must not be null - * @param style the style of the toString to create, - * may be null - * @throws IllegalArgumentException if the Object passed in is - * null - */ - public ToStringBuilder(Object object, ToStringStyle style) { - this(object, style, null); - } - - /** - *

Constructor for ToStringBuilder.

- * - *

If the style is null, the default style is used.

- * - *

If the buffer is null, a new one is created.

- * - * @param object the Object to build a toString for, - * must not be null - * @param style the style of the toString to create, - * may be null - * @param buffer the StringBuffer to populate, may be - * null - * @throws IllegalArgumentException if the Object passed in is - * null - */ - public ToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer) { - super(); - if (object == null) { - throw new IllegalArgumentException("The object to create a toString for must not be null"); + private static void reflectionAppend(Object object, Class clazz, ToStringBuilder builder, boolean useTransients) { + if (isRegistered(object)) { + // The object has already been appended, therefore we have an object cycle. + // Append a simple Object.toString style string. The field name is already appended at this point. + builder.appendAsObjectToString(object); + return; } - if (style == null) { - style = getDefaultStyle(); + try { + register(object); + if (clazz.isArray()) { + builder.reflectionAppendArray(object); + return; + } + Field[] fields = clazz.getDeclaredFields(); + Field.setAccessible(fields, true); + for (int i = 0; i < fields.length; i++) { + Field f = fields[i]; + String fieldName = f.getName(); + if ((fieldName.indexOf('$') == -1) + && (useTransients || !Modifier.isTransient(f.getModifiers())) + && (!Modifier.isStatic(f.getModifiers()))) { + try { + // Warning: Field.get(Object) creates wrappers objects for primitive types. + Object fieldValue = f.get(object); + if (isRegistered(fieldValue) + && !f.getType().isPrimitive()) { + // A known field value has already been appended, therefore we have an object cycle, + // append a simple Object.toString style string. + builder.getStyle().appendFieldStart(builder.getStringBuffer(), fieldName); + builder.appendAsObjectToString(fieldValue); + // The recursion out of + // builder.append(fieldName, fieldValue); + // below will append the field + // end marker. + } else { + try { + register(object); + builder.append(fieldName, fieldValue); + } finally { + unregister(object); + } + } + } catch (IllegalAccessException ex) { + //this can't happen. Would get a Security exception instead + //throw a runtime exception in case the impossible happens. + throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); + } + } + } + } finally { + unregister(object); } - if (buffer == null) { - buffer = new StringBuffer(512); - } - this.buffer = buffer; - this.style = style; - this.object = object; - - style.appendStart(buffer, object); - } - - //---------------------------------------------------------------------------- - - /** - *

Gets the default ToStringStyle to use.

- * - *

This could allow the ToStringStyle to be - * controlled for an entire application with one call.

- * - *

This might be used to have a verbose - * ToStringStyle during development and a compact - * ToStringStyle in production.

- * - * @return the default ToStringStyle - */ - public static ToStringStyle getDefaultStyle() { - return defaultStyle; - } - - /** - *

Sets the default ToStringStyle to use.

- * - * @param style the default ToStringStyle - * @throws IllegalArgumentException if the style is null - */ - public static void setDefaultStyle(ToStringStyle style) { - if (style == null) { - throw new IllegalArgumentException("The style must not be null"); - } - defaultStyle = style; } //------------------------------------------------------------------------- @@ -427,68 +378,810 @@ public class ToStringBuilder { } /** - * Appends the fields and values defined by the given object of the - * given Class. If a cycle is detected as an objects is "toString()'ed", - * such an object is rendered as if Object.toString() - * had been called and not implemented by the object. + * Registers the given object. + * Used by the reflection methods to avoid infinite loops. * - * @param object the object to append details of - * @param clazz the class of object parameter - * @param builder the builder to append to - * @param useTransients whether to output transient fields + * @param value The object to register. */ - private static void reflectionAppend(Object object, Class clazz, ToStringBuilder builder, boolean useTransients) { - if (isRegistered(object)) { - // The object has already been appended, therefore we have an object cycle. - // Append a simple Object.toString style string. The field name is already appended at this point. - builder.appendAsObjectToString(object); - return; + static void register(Object value) { + getReflectionRegistry().add(value); + } + + /** + *

Sets the default ToStringStyle to use.

+ * + * @param style the default ToStringStyle + * @throws IllegalArgumentException if the style is null + */ + public static void setDefaultStyle(ToStringStyle style) { + if (style == null) { + throw new IllegalArgumentException("The style must not be null"); } - try { - register(object); - if (clazz.isArray()) { - builder.reflectionAppendArray(object); - return; - } - Field[] fields = clazz.getDeclaredFields(); - Field.setAccessible(fields, true); - for (int i = 0; i < fields.length; i++) { - Field f = fields[i]; - String fieldName = f.getName(); - if ((fieldName.indexOf('$') == -1) - && (useTransients || !Modifier.isTransient(f.getModifiers())) - && (!Modifier.isStatic(f.getModifiers()))) { - try { - // Warning: Field.get(Object) creates wrappers objects for primitive types. - Object fieldValue = f.get(object); - if (isRegistered(fieldValue) - && !f.getType().isPrimitive()) { - // A known field value has already been appended, therefore we have an object cycle, - // append a simple Object.toString style string. - builder.getStyle().appendFieldStart(builder.getStringBuffer(), fieldName); - builder.appendAsObjectToString(fieldValue); - // The recursion out of - // builder.append(fieldName, fieldValue); - // below will append the field - // end marker. - } else { - try { - register(object); - builder.append(fieldName, fieldValue); - } finally { - unregister(object); - } - } - } catch (IllegalAccessException ex) { - //this can't happen. Would get a Security exception instead - //throw a runtime exception in case the impossible happens. - throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); - } - } - } - } finally { - unregister(object); + defaultStyle = style; + } + + /** + * Unregisters the given object. + * Used by the reflection methods to avoid infinite loops. + * + * @param value The object to unregister. + */ + static void unregister(Object value) { + getReflectionRegistry().remove(value); + } + + /** + * Current toString buffer + */ + private final StringBuffer buffer; + + /** + * The object being output + */ + private final Object object; + + /** + * The style of output to use + */ + private final ToStringStyle style; + + /** + *

Constructor for ToStringBuilder.

+ * + *

This constructor outputs using the default style set with + * setDefaultStyle.

+ * + * @param object the Object to build a toString for, + * must not be null + * @throws IllegalArgumentException if the Object passed in is + * null + */ + public ToStringBuilder(Object object) { + this(object, getDefaultStyle(), null); + } + + /** + *

Constructor for ToStringBuilder specifying the + * output style.

+ * + *

If the style is null, the default style is used.

+ * + * @param object the Object to build a toString for, + * must not be null + * @param style the style of the toString to create, + * may be null + * @throws IllegalArgumentException if the Object passed in is + * null + */ + public ToStringBuilder(Object object, ToStringStyle style) { + this(object, style, null); + } + + /** + *

Constructor for ToStringBuilder.

+ * + *

If the style is null, the default style is used.

+ * + *

If the buffer is null, a new one is created.

+ * + * @param object the Object to build a toString for, + * must not be null + * @param style the style of the toString to create, + * may be null + * @param buffer the StringBuffer to populate, may be + * null + * @throws IllegalArgumentException if the Object passed in is + * null + */ + public ToStringBuilder(Object object, ToStringStyle style, StringBuffer buffer) { + super(); + if (object == null) { + throw new IllegalArgumentException("The object to create a toString for must not be null"); } + if (style == null) { + style = getDefaultStyle(); + } + if (buffer == null) { + buffer = new StringBuffer(512); + } + this.buffer = buffer; + this.style = style; + this.object = object; + + style.appendStart(buffer, object); + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an boolean + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(boolean value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a boolean + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(boolean[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an byte + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(byte value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a byte + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(byte[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an char + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(char value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a char + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(char[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an double + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(double value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a double + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(double[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an float + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(float value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a float + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(float[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an int + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(int value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a int + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(int[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a long + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(long value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a long + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(long[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an Object + * value.

+ * + * @param object the value to add to the toString + * @return this + */ + public ToStringBuilder append(Object object) { + style.append(buffer, null, object, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an Object + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(Object[] array) { + style.append(buffer, null, array, null); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString an short + * value.

+ * + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(short value) { + style.append(buffer, null, value); + return this; + } + + //---------------------------------------------------------------------------- + + /** + *

Append to the toString a short + * array.

+ * + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(short[] array) { + style.append(buffer, null, array, null); + return this; + } + + /** + *

Append to the toString an boolean + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, boolean value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a boolean + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, boolean[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a boolean + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, boolean[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an byte + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, byte value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a byte + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, byte[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a byte + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array. + * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, byte[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an char + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, char value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a char + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, char[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a char + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, char[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an double + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, double value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a double + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, double[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a double + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, double[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an float + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, float value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a float + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, float[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a float + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, float[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an int + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, int value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for an int + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, int[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString an int + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, int[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString a long + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, long value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a long + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, long[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a long + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, long[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an Object + * value.

+ * + * @param fieldName the field name + * @param object the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, Object object) { + style.append(buffer, fieldName, object, null); + return this; + } + + /** + *

Append to the toString an Object + * value.

+ * + * @param fieldName the field name + * @param object the value to add to the toString + * @param fullDetail true for detail, + * false for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, Object object, boolean fullDetail) { + style.append(buffer, fieldName, object, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an Object + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, Object[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString an Object + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array.

+ * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, Object[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Append to the toString an short + * value.

+ * + * @param fieldName the field name + * @param value the value to add to the toString + * @return this + */ + public ToStringBuilder append(String fieldName, short value) { + style.append(buffer, fieldName, value); + return this; + } + + /** + *

Append a hashCode for a short + * array.

+ * + * @param fieldName the field name + * @param array the array to add to the hashCode + * @return this + */ + public ToStringBuilder append(String fieldName, short[] array) { + style.append(buffer, fieldName, array, null); + return this; + } + + /** + *

Append to the toString a short + * array.

+ * + *

A boolean parameter controls the level of detail to show. + * Setting true will output the array in full. Setting + * false will output a summary, typically the size of + * the array. + * + * @param fieldName the field name + * @param array the array to add to the toString + * @param fullDetail true for detail, false + * for summary info + * @return this + */ + public ToStringBuilder append(String fieldName, short[] array, boolean fullDetail) { + style.append(buffer, fieldName, array, new Boolean(fullDetail)); + return this; + } + + /** + *

Appends with the same format as the default Object toString() + * method. Appends the class name followed by + * {@link System#identityHashCode(java.lang.Object)}.

+ * + * @param object the Object whose class name and id to output + */ + public ToStringBuilder appendAsObjectToString(Object object) { + this.getStyle().appendAsObjectToString(this.getStringBuffer(), object); + return this; } //---------------------------------------------------------------------------- @@ -545,708 +1238,12 @@ public class ToStringBuilder { } /** - *

Appends with the same format as the default Object toString() - * method. Appends the class name followed by - * {@link System#identityHashCode(java.lang.Object)}.

+ *

Gets the StringBuffer being populated.

* - * @param object the Object whose class name and id to output + * @return the StringBuffer being populated */ - public ToStringBuilder appendAsObjectToString(Object object) { - this.getStyle().appendAsObjectToString(this.getStringBuffer(), object); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an Object - * value.

- * - * @param object the value to add to the toString - * @return this - */ - public ToStringBuilder append(Object object) { - style.append(buffer, null, object, null); - return this; - } - - /** - *

Append to the toString an Object - * value.

- * - * @param fieldName the field name - * @param object the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, Object object) { - style.append(buffer, fieldName, object, null); - return this; - } - - /** - *

Append to the toString an Object - * value.

- * - * @param fieldName the field name - * @param object the value to add to the toString - * @param fullDetail true for detail, - * false for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, Object object, boolean fullDetail) { - style.append(buffer, fieldName, object, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a long - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(long value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString a long - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, long value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an int - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(int value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an int - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, int value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an short - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(short value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an short - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, short value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an char - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(char value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an char - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, char value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an byte - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(byte value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an byte - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, byte value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an double - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(double value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an double - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, double value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an float - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(float value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an float - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, float value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an boolean - * value.

- * - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(boolean value) { - style.append(buffer, null, value); - return this; - } - - /** - *

Append to the toString an boolean - * value.

- * - * @param fieldName the field name - * @param value the value to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, boolean value) { - style.append(buffer, fieldName, value); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString an Object - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(Object[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append to the toString an Object - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder reflectionAppendArray(Object array) { - style.reflectionAppendArrayDetail(buffer, null, array); - return this; - } - - /** - *

Append to the toString an Object - * array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(String fieldName, Object[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString an Object - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, Object[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a long - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(long[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a long - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, long[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a long - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, long[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a int - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(int[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for an int - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, int[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString an int - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, int[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a short - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(short[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a short - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, short[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a short - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array. - * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, short[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a char - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(char[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a char - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, char[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a char - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, char[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a byte - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(byte[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a byte - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, byte[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a byte - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array. - * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, byte[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a double - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(double[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a double - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, double[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a double - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, double[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a float - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(float[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a float - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, float[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a float - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, float[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; - } - - //---------------------------------------------------------------------------- - - /** - *

Append to the toString a boolean - * array.

- * - * @param array the array to add to the toString - * @return this - */ - public ToStringBuilder append(boolean[] array) { - style.append(buffer, null, array, null); - return this; - } - - /** - *

Append a hashCode for a boolean - * array.

- * - * @param fieldName the field name - * @param array the array to add to the hashCode - * @return this - */ - public ToStringBuilder append(String fieldName, boolean[] array) { - style.append(buffer, fieldName, array, null); - return this; - } - - /** - *

Append to the toString a boolean - * array.

- * - *

A boolean parameter controls the level of detail to show. - * Setting true will output the array in full. Setting - * false will output a summary, typically the size of - * the array.

- * - * @param fieldName the field name - * @param array the array to add to the toString - * @param fullDetail true for detail, false - * for summary info - * @return this - */ - public ToStringBuilder append(String fieldName, boolean[] array, boolean fullDetail) { - style.append(buffer, fieldName, array, new Boolean(fullDetail)); - return this; + public StringBuffer getStringBuffer() { + return buffer; } //---------------------------------------------------------------------------- @@ -1261,12 +1258,15 @@ public class ToStringBuilder { } /** - *

Gets the StringBuffer being populated.

- * - * @return the StringBuffer being populated + *

Append to the toString an Object + * array.

+ * + * @param array the array to add to the toString + * @return this */ - public StringBuffer getStringBuffer() { - return buffer; + public ToStringBuilder reflectionAppendArray(Object array) { + style.reflectionAppendArrayDetail(buffer, null, array); + return this; } /**