/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
 *    Foundation" must not be used to endorse or promote products derived
 *    from this software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
package org.apache.commons.lang.builder;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
 * <code>ToString</code> を生成する処理です。
 * {@primary <code>ToString</code> generation routine.}
 * <p>
 * このクラスはより良い toString メソッドをクラスに実装する事を可能にします。
 * このクラスは以下の処理を単純化することを目的とします:
 * <ul>
 * <li>フィールド名の使用を可能とする
 * <li>一貫したすべての型のハンドリング
 * <li>一貫した null のハンドリング
 * <li>配列と多次元配列の出力
 * <li>オブジェクトとコレクションに対する詳細出力の程度をコントロールする
 * </ul>
 * {@primary This class enables a good toString to be built for any class. This class aims 
 * to simplify the process by:
 * <ul>
 * <li>allowing field names
 * <li>handling all types consistently
 * <li>handling nulls consistently
 * <li>outputting arrays and multi-dimensional arrays
 * <li>enabling the detail level to be controlled for objects and collections
 * </ul>}
 * <p>
 * 一般的な使用方法を以下に示します:
 * {@primary To use this class write code as follows:}
 * <pre>
 * public class Person {
 *   String name;
 *   int age;
 *   boolean isSmoker;
 * 
 *   ...
 * 
 *   public String toString() {
 *     return new ToStringBuilder(this).
 *       append(name, "name").
 *       append(age, "age").
 *       append(smoker, "smoker").
 *       toString();
 *   }
 * }
 * </pre>
 * これは以下のフォーマットの toString 生成します:
 * {@primary This will produce a toString of the format:<br/>}
 * <code>Person@7f54[name=Stephen,age=29,smoker=false]</code>
 * <p>
 * もう一つの方法として、対象とするフィールドを決定する際にリフレクションを使用するメソッドがあります。
 * 普通、対象となるフィールドは private であるため、この <code>reflectionToString</code>
 * メソッドは フィールドのアクセス制限を変更するために  <code>Field.setAccessible</code> 
 * を使用します。
 * これは適切なパーミッションが設定されていない限り、セキュリティマネージャが稼動している状態では行うことができません。
 * また、この方法は明らかに低速です。
 * {@primary Alternatively, there is a method that uses reflection to determine
 * the fields to test. Because these fields are usually private, the method, 
 * <code>reflectionToString</code>, uses <code>Field.setAccessible</code> to change
 * the visibility of the fields. This will fail under a security manager, 
 * unless the appropriate permissions are set. It is also slower than testing 
 * explicitly.}
 * <p>
 * このメソッドの一般的な使用方法は以下の様になります:
 * {@primary A typical invocation for this method would look like:}
 * <pre>
 * public String toString() {
 *   return ToStringBuilder.reflectionToString(this);
 * }
 * </pre>
 * <p>
 * toString で使用される詳細なフォーマットはコンストラクタに渡される
 * {@link ToStringStyle} によって決定されます。
 * {@primary The exact format of the toString is determined by the {@link ToStringStyle}
 * passed into the constructor.}
 *
 * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
 * @translator 日置 聡
 * @status firstdraft
 * @update 2003/08/19
 * @version $Id: ToStringBuilder.java,v 1.1.1.1 2004/02/13 10:02:05 hioki Exp $
 */
public class ToStringBuilder {
    
    /**
     * 出力の際に使用されるデフォルトのスタイル。
     * {@primary The default style of output to use}
     */
    private static ToStringStyle defaultStyle = ToStringStyle.DEFAULT_STYLE;
    /**
     * 現在の toString バッファ。
     * {@primary Current toString buffer}
     */
    private final StringBuffer buffer;
    /**
     * 出力の際に使用されるスタイル。
     * {@primary The style of output to use}
     */
    private final ToStringStyle style;
    /**
     * 出力を行う対象となるオブジェクト。
     * {@primary The object being output}
     */
    private final Object object;
    
    /**
     * ToStringBuilder のコンストラクタです。
     * このコンストラクタは出力の際に <code>setDefaultStyle</code> 
     * で設定されたデフォルトのスタイルを使用します。
     * {@primary Constructor for ToStringBuilder.
     * This constructor outputs using the default style set with 
     * <code>setDefaultStyle</code>.}
     * 
     * @param object  toString を生成する対象となるオブジェクト、null でない必要があります
     * {@primary the object to build a toString for, must not be null}
     * @throws IllegalArgumentException 渡されたオブジェクトが null だった場合
     * {@primary if the object passed in is null}
     */
    public ToStringBuilder(Object object) {
        this(object, getDefaultStyle(), null);
    }
    
    /**
     * 出力の際のスタイルを指定する ToStringBuilder のコンストラクタです。
     * {@primary Constructor for ToStringBuilder specifying the output style.}
     * <p>
     * style が null だった場合にはデフォルトのスタイルが使用されます。
     * {@primary If the style is null, the default style is used.}
     * 
     * @param object  toString を生成する対象となるオブジェクト、null でない必要があります
     * {@primary the object to build a toString for, must not be null}
     * @param style  toString を生成する際のスタイル、 null を許容します
     * {@primary the style of the toString to create, may be null}
     * @throws IllegalArgumentException 渡されたオブジェクトが null だった場合
     * {@primary if the object passed in is null}
     */
    public ToStringBuilder(Object object, ToStringStyle style) {
        this(object, style, null);
    }
    
    /**
     * ToStringBuilder のコンストラクタです。
     * {@primary Constructor for ToStringBuilder.}
     * <p>
     * style が null だった場合にはデフォルトのスタイルが使用されます。
     * buffer が null だった場合には新たなバッファを生成します。
     * {@primary If the style is null, the default style is used.
     * If the buffer is null, a new one is created.}
     * 
     * @param object  toString を生成する対象となるオブジェクト、null でない必要があります
     * {@primary the object to build a toString for, must not be null}
     * @param style  toString を生成する際のスタイル、 null を許容します
     * {@primary the style of the toString to create, may be null}
     * @param buffer  処理に使用される文字列バッファ、 null を許容します
     * {@primary the string buffer to populate, may be null}
     * @throws IllegalArgumentException 渡されたオブジェクトが null だった場合
     * {@primary 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);
    }
    
    //----------------------------------------------------------------------------
    
    /**
     * デフォルトのスタイルを取得します。
     * {@primary Gets the default style to use.}
     * <p>
     * このメソッドはアプリケーション全体の toString スタイルを1度の呼び出しでコントロールすることを可能とします。
     * これによって開発中には詳細な toString の出力を行い、運用時には簡潔な出力を行うといった使用法が可能です。
     * {@primary This could allow the toString style to be controlled for an entire
     * application with one call. This might be used to have a verbose toString
     * during development and a compact toString in production.}
     * 
     * @return デフォルトの toString スタイル
     * {@primary the default toString style}
     */
    public static ToStringStyle getDefaultStyle() {
        return defaultStyle;
    }
    
    /**
     * 使用するデフォルトのスタイルを設定します。
     * {@primary Sets the default style to use.}
     * 
     * @param style  デフォルトの toString スタイル
     * {@primary the default toString style}
     * @throws IllegalArgumentException スタイルが null だった場合
     * {@primary 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;
    }
    
    //-------------------------------------------------------------------------
    
    /**
     * このメソッドは一連の toString の生成にリフレクションを使用し、出力にデフォルトのスタイルを使用します。
     * {@primary This method uses reflection to build a suitable toString using the default style.}
     * <p>
     * このメソッドは private フィールドの値を取得するために Field.setAccessible を使用します。
     * これはセキュリティマネージャが稼動していて、適切なパーミッションが設定されていない場合、
     * セキュリティ例外が投げられることを意味します。
     * このメソッドは明らかに非効率です。
     * transient メンバーは、おそらくフィールドの値から取得されたものでオブジェクトの値とはならないと考え、
     * 処理の対象としません。
     * static フィールドは処理の対象にはなりません。
     * {@primary It uses Field.setAccessible to gain access to private fields. This means
     * that it will throw a security exception if run under a security manger, if
     * the permissions are not set up.
     * It is also not as efficient as testing explicitly. 
     * Transient members will be not be included, as they are likely derived
     * fields, and not part of the value of the object.
     * Static fields will be not be included.}
     * 
     * @param object  出力対象となるオブジェクト
     * {@primary the object to be output}
     * @return 処理結果の文字列
     * {@primary the String result}
     * @throws IllegalArgumentException object が null だった場合
     * {@primary if the object is null}
     */
    public static String reflectionToString(Object object) {
        return reflectionToString(object, null, false);
    }

    /**
     * このメソッドは一連の toString の生成にリフレクションを使用します。
     * {@primary This method uses reflection to build a suitable toString.}
     * <p>
     * このメソッドは private フィールドの値を取得するために Field.setAccessible を使用します。
     * これはセキュリティマネージャが稼動していて、適切なパーミッションが設定されていない場合、
     * セキュリティ例外が投げられることを意味します。
     * このメソッドは明らかに非効率です。
     * transient メンバーは、おそらくフィールドの値から取得されたものでオブジェクトの値とはならないと考え、
     * 処理の対象としません。
     * static フィールドは処理の対象にはなりません。
     * {@primary It uses Field.setAccessible to gain access to private fields. This means
     * that it will throw a security exception if run under a security manger, if
     * the permissions are not set up.
     * It is also not as efficient as testing explicitly. 
     * Transient members will be not be included, as they are likely derived
     * fields, and not part of the value of the object.
     * Static fields will be not be included.}
     * <p>
     * style が null だった場合にはデフォルトのスタイルが使用されます。
     * {@primary If the style is null, the default style is used.}
     * 
     * @param object  出力対象となるオブジェクト
     * {@primary the object to be output}
     * @param style  toString を生成する際のスタイル、 null を許容します
     * {@primary the style of the toString to create, may be null}
     * @return 処理結果の文字列
     * {@primary the String result}
     * @throws IllegalArgumentException objectが null だった場合
     * {@primary if the object or style is null}
     */
    public static String reflectionToString(Object object, ToStringStyle style) {
        return reflectionToString(object, style, false);
    }

    /**
     * このメソッドは一連の toString の生成にリフレクションを使用します。
     * {@primary This method uses reflection to build a suitable toString.}
     * <p>
     * このメソッドは private フィールドの値を取得するために Field.setAccessible を使用します。
     * これはセキュリティマネージャが稼動していて、適切なパーミッションが設定されていない場合、
     * セキュリティ例外が投げられることを意味します。
     * このメソッドは明らかに非効率です。
     * testTransients 引数に true が設定された場合 transient メンバーを処理の対象とし、
     * false が設定された場合にはフィールドの値から取得されたものでオブジェクトの値とはならないとみなし、
     * transient メンバーを無視します。
     * static フィールドは処理の対象にはなりません。
     * {@primary It uses Field.setAccessible to gain access to private fields. This means
     * that it will throw a security exception if run under a security manger, if
     * the permissions are not set up.
     * It is also not as efficient as testing explicitly. 
     * If the outputTransients parameter is set to true, transient members will be
     * output, otherwise they are ignored, as they are likely derived fields, and
     * not part of the value of the object. 
     * Static fields will not be tested.}
     * <p>
     * style が null だった場合にはデフォルトのスタイルが使用されます。
     * {@primary If the style is null, the default style is used.}
     * 
     * @param object  出力対象となるオブジェクト
     * {@primary the object to be output}
     * @param style  toString を生成する際のスタイル、 null を許容します
     * {@primary the style of the toString to create, may be null}
     * @param outputTransients transient フィールドを含めるかどうか
     * {@primary whether to include transient fields}
     * @return 処理結果の文字列
     * {@primary the String result}
     * @throws IllegalArgumentException object が null だった場合
     * {@primary if the object is null}
     */
    public static String reflectionToString(Object object, ToStringStyle style, 
            boolean outputTransients) {
        if (object == null) {
            throw new IllegalArgumentException("The object must not be null");
        }
        if (style == null) {
            style = getDefaultStyle();
        }
        Field[] fields = object.getClass().getDeclaredFields();
        Field.setAccessible(fields, true);
        ToStringBuilder builder = new ToStringBuilder(object, style);
        for (int i = 0; i < fields.length; ++i) {
            Field f = fields[i];
            if (outputTransients || !Modifier.isTransient(f.getModifiers())) {
                if (!Modifier.isStatic(f.getModifiers())) {
                    try {
                        builder.append(f.getName(), f.get(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");
                    }
                }
            }
        }
        return builder.toString();
    }

    //----------------------------------------------------------------------------
    
    /**
     * Object の値を toString に追加します。
     * {@primary Append to the toString an Object value.}
     *
     * @param object  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(Object object) {
        style.append(buffer, null, object, null);
        return this;
    }

    /**
     * Object の値を toString に追加します。
     * {@primary Append to the toString an Object value.}
     *
     * @param object  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, Object object) {
        style.append(buffer, fieldName, object, null);
        return this;
    }

    /**
     * Object の値を toString に追加します。
     * {@primary Append to the toString an Object value.}
     *
     * @param object  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * long の値を toString に追加します。
     * {@primary Append to the toString a long value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(long value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * long の値を toString に追加します。
     * {@primary Append to the toString a long value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, long value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * int の値を toString に追加します。
     * {@primary Append to the toString an int value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(int value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * int の値を toString に追加します。
     * {@primary Append to the toString an int value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, int value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * short の値を toString に追加します。
     * {@primary Append to the toString a short value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(short value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * short の値を toString に追加します。
     * {@primary Append to the toString a short value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, short value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * char の値を toString に追加します。
     * {@primary Append to the toString a char value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(char value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * char の値を toString に追加します。
     * {@primary Append to the toString a char value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, char value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * byte の値を toString に追加します。
     * {@primary Append to the toString a byte value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(byte value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * byte の値を toString に追加します。
     * {@primary Append to the toString a byte value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, byte value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * double の値を toString に追加します。
     * {@primary Append to the toString a double value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(double value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * double の値を toString に追加します。
     * {@primary Append to the toString a double value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, double value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * float の値を toString に追加します。
     * {@primary Append to the toString a float value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(float value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * float の値を toString に追加します。
     * {@primary Append to the toString a float value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, float value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * boolean の値を toString に追加します。
     * {@primary Append to the toString a boolean value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @return this
     */
    public ToStringBuilder append(boolean value) {
        style.append(buffer, null, value);
        return this;
    }

    /**
     * boolean の値を toString に追加します。
     * {@primary Append to the toString a boolean value.}
     *
     * @param value  toString に加える値
     * {@primary the value to add to the toString}
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @return this
     */
    public ToStringBuilder append(String fieldName, boolean value) {
        style.append(buffer, fieldName, value);
        return this;
    }

    //----------------------------------------------------------------------------
    
    /**
     * Object の配列を toString に追加します。
     * {@primary Append to the toString an Object array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(Object[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * Object の配列を toString に追加します。
     * {@primary Append to the toString an Object array.}
     *
     * @param fieldName  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(String fieldName, Object[] array) {
        style.append(buffer, fieldName, array, null);
        return this;
    }

    /**
     * Object の配列を toString に追加します。
     * {@primary Append to the toString an Object array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * long の配列を toString に追加します。
     * {@primary Append to the toString a long array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(long[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * long の配列を toString に追加します。
     * {@primary Append to the toString a long array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * long の配列を toString に追加します。
     * {@primary Append to the toString a long array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * int の配列を toString に追加します。
     * {@primary Append to the toString an int array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(int[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * int の配列を toString に追加します。
     * {@primary Append to the toString an int array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * int の配列を toString に追加します。
     * {@primary Append to the toString an int array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * short の配列を toString に追加します。
     * {@primary Append to the toString a short array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(short[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * short の配列を toString に追加します。
     * {@primary Append to the toString a short array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * short の配列を toString に追加します。
     * {@primary Append to the toString a short array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * char の配列を toString に追加します。
     * {@primary Append to the toString a char array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(char[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * char の配列を toString に追加します。
     * {@primary Append to the toString a char array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * char の配列を toString に追加します。
     * {@primary Append to the toString a char array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * byte の配列を toString に追加します。
     * {@primary Append to the toString a byte array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(byte[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * byte の配列を toString に追加します。
     * {@primary Append to the toString a byte array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * byte の配列を toString に追加します。
     * {@primary Append to the toString a byte array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * double の配列を toString に追加します。
     * {@primary Append to the toString a double array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(double[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * double の配列を toString に追加します。
     * {@primary Append to the toString a double array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * double の配列を toString に追加します。
     * {@primary Append to the toString a double array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * float の配列を toString に追加します。
     * {@primary Append to the toString a float array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(float[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * float の配列を toString に追加します。
     * {@primary Append to the toString a float array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * float の配列を toString に追加します。
     * {@primary Append to the toString a float array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * boolean の配列を toString に追加します。
     * {@primary Append to the toString a boolean array.}
     *
     * @param array  toString に加える配列
     * {@primary the array to add to the toString}
     * @return this
     */
    public ToStringBuilder append(boolean[] array) {
        style.append(buffer, null, array, null);
        return this;
    }

    /**
     * boolean の配列を toString に追加します。
     * {@primary Append to the toString a boolean array.}
     *
     * @param fieldName  フィールド名
     * {@primary 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;
    }

    /**
     * boolean の配列を toString に追加します。
     * {@primary Append to the toString a boolean array.}
     * <p>
     * boolean の引数は詳細情報の表示の程度をコントロールします。
     * true が設定された場合には配列内の全ての情報を出力し、
     * false が設定された場合には概要(一般的に配列のサイズ)を出力します。
     * {@primary 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  フィールド名
     * {@primary the field name}
     * @param array  toString に加える配列
     * {@primary 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;
    }

    //----------------------------------------------------------------------------
    
    /**
     * 内部で使用されているバッファを取得します。
     * {@primary Gets the buffer being populated}
     * 
     * @return 使用されている StringBuffer
     * {@primary the StringBuffer being populated}
     */    
    public StringBuffer getStringBuffer() {
        return buffer;
    }

    /**
     * 生成された toString の結果を返します。
     * {@primary Returns the built toString}
     * 
     * @return toString の文字列
     * {@primary the String toString}
     */    
    public String toString() {
        style.appendEnd(buffer, object);
        return buffer.toString();
    }

}
