/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2002-2003 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 acknowledgement:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgement may appear in the software itself,
 *    if and wherever such third-party acknowledgements 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;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * <p>配列、 (<code>int[]</code> のような)プリミティブ型の配列、
 * (<code>Integer[]</code> のような)プリミティブ型のラッパーの配列に対する処理です。
 * {@primary Operations on arrays, primitive arrays (like <code>int[]</code>) and primitive wrapper arrays 
 * (like <code>Integer[]</code>).}</p>
 * 
 * <p>このクラスは <code>null</code> の入力を問題なく扱えるよう試みます。
 * <code>null</code> の配列が入力されれも冷害は発生しません。
 * しかし、<code>null</code> の要素をもつ Object の配列が渡された場合には例外を投げます。
 * 各メソッドのドキュメントに各動作が記載されています。
 * {@primary This class tries to handle <code>null</code> input gracefully.
 * An exception will not be thrown for a <code>null</code>
 * array input. However, an Object array that contains a <code>null</code>
 * element may throw an exception. Each method documents its behaviour.}</p>
 *
 * @author Stephen Colebourne
 * @author Moritz Petersen
 * @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
 * @author Nikolay Metchev
 * @author Matthew Hawthorne
 * @author Tim O'Brien
 * @author Pete Gieser
 * @author Gary Gregory
 * @translator 日置 聡
 * @status firstdraft
 * @memo  2.0新規
 * @update 2003/09/23
 * @since 2.0
 * @version $Id: ArrayUtils.java,v 1.1.1.1 2004/02/13 10:02:05 hioki Exp $
 */
public class ArrayUtils {

    /**
     * 不変(immutable)な <code>Object</code> の空の配列です。
     * {@primary  An empty immutable <code>Object</code> array.}
     */
    public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
    /**
     * 不変(immutable)な <code>Class</code> の空の配列です。
     * {@primary An empty immutable <code>Class</code> array.}
     */
    public static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
    /**
     * 不変(immutable)な <code>String</code> の空の配列です。
     * {@primary An empty immutable <code>String</code> array.}
     */
    public static final String[] EMPTY_STRING_ARRAY = new String[0];
    /**
     * 不変(immutable)な <code>long</code> の空の配列です。
     * {@primary An empty immutable <code>long</code> array.}
     */
    public static final long[] EMPTY_LONG_ARRAY = new long[0];
    /**
     * 不変(immutable)な <code>Long</code> の空の配列です。
     * {@primary An empty immutable <code>Long</code> array.}
     */
    public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0];
    /**
     * 不変(immutable)な <code>int</code> の空の配列です。
     * {@primary An empty immutable <code>int</code> array.}
     */
    public static final int[] EMPTY_INT_ARRAY = new int[0];
    /**
     * 不変(immutable)な <code>Integer</code> の空の配列です。
     * {@primary An empty immutable <code>Integer</code> array.}
     */
    public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0];
    /**
     * 不変(immutable)な <code>short</code> の空の配列です。
     * {@primary An empty immutable <code>short</code> array.}
     */
    public static final short[] EMPTY_SHORT_ARRAY = new short[0];
    /**
     * 不変(immutable)な <code>Short</code> の空の配列です。
     * {@primary An empty immutable <code>Short</code> array.}
     */
    public static final Short[] EMPTY_SHORT_OBJECT_ARRAY = new Short[0];
    /**
     * 不変(immutable)な <code>byte</code> の空の配列です。
     * {@primary An empty immutable <code>byte</code> array.}
     */
    public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
    /**
     * 不変(immutable)な <code>Byte</code> の空の配列です。
     * {@primary An empty immutable <code>Byte</code> array.}
     */
    public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY = new Byte[0];
    /**
     * 不変(immutable)な <code>double</code> の空の配列です。
     * {@primary An empty immutable <code>double</code> array.}
     */
    public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
    /**
     * 不変(immutable)な <code>Double</code> の空の配列です。
     * {@primary An empty immutable <code>Double</code> array.}
     */
    public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0];
    /**
     * 不変(immutable)な <code>float</code> の空の配列です。
     * {@primary An empty immutable <code>float</code> array.}
     */
    public static final float[] EMPTY_FLOAT_ARRAY = new float[0];
    /**
     * 不変(immutable)な <code>Float</code> の空の配列です。
     * {@primary An empty immutable <code>Float</code> array.}
     */
    public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY = new Float[0];
    /**
     * 不変(immutable)な <code>boolean</code> の空の配列です。
     * {@primary An empty immutable <code>boolean</code> array.}
     */
    public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0];
    /**
     * 不変(immutable)な <code>Boolean</code> の空の配列です。
     * {@primary An empty immutable <code>Boolean</code> array.}
     */
    public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY = new Boolean[0];
    /**
     * 不変(immutable)な <code>char</code> の空の配列です。
     * {@primary An empty immutable <code>char</code> array.}
     */
    public static final char[] EMPTY_CHAR_ARRAY = new char[0];
    /**
     * 不変(immutable)な <code>Character</code> の空の配列です。
     * {@primary An empty immutable <code>Character</code> array.}
     */
    public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0];

    /**
     * <p>ArrayUtils のインスタンスは一般的なプログラムからは生成すべきではありません。 
     * 代わりに <code>ArrayUtils.clone(new int[] {2})</code> というように使用すべきです。 
     * {@primary ArrayUtils instances should NOT be constructed in standard programming.
     * Instead, the class should be used as <code>ArrayUtils.clone(new int[] {2})</code>.}</p>
     *
     * <p>このコンストラクタは、処理のために JavaBean インスタンスを必要とするツールのために
     * public になっています。 
     * {@primary This constructor is public to permit tools that require a JavaBean instance
     * to operate.}</p>
     */
    public ArrayUtils() {
    }
    
    // Basic methods handling multi-dimensional arrays
    //-----------------------------------------------------------------------
    /**
     * <p>配列の文字列表現を返します。<code>null</code> が指定された場合には空の配列として扱います。
     * {@primary Outputs an array as a String, treating <code>null</code> as an empty array.}</p>
     *
     * <p>多次元配列も正しく処理されます(プリミティブ型の多次元配列も)。
     * {@primary Multi-dimensional arrays are handled correctly, including
     * multi-dimensional primitive arrays.}</p>
     *
     * <p>出力フォーマットは (<code>{a,b}</code> のような)Java のソースコードに近い形になります。
     * {@primary The format is that of Java source code, for example <code>{a,b}</code>.}</p>
     * 
     * @param array  文字列表現を取得する配列、<code>null</code> を許容します
     * {@primary  the array to get a toString for, may be <code>null</code>}
     * @return 配列の文字列表現、null の配列が指定された場合 '{}'
     * {@primary a String representation of the array, '{}' if null array input}
     */
    public static String toString(final Object array) {
        return toString(array, "{}");
    }

    /**
     * <p><code>null</code> が指定された場合にも正常に動作し、配列の文字列表現を返します。
     * {@primary Outputs an array as a String handling <code>null</code>s.}</p>
     *
     * <p>多次元配列も正しく処理されます(プリミティブ型の多次元配列も)。
     * {@primary Multi-dimensional arrays are handled correctly, including
     * multi-dimensional primitive arrays.}</p>
     *
     * <p>出力フォーマットは (<code>{a,b}</code> のような)Java のソースコードに近い形になります。
     * {@primary The format is that of Java source code, for example <code>{a,b}</code>.}</p>
     * 
     * @param array  文字列表現を取得する配列、<code>null</code> を許容します
     * {@primary  the array to get a toString for, may be <code>null</code>}
     * @param stringIfNull  配列が <code>null</code> だった場合に返される文字列
     * {@primary  the String to return if the array is <code>null</code>}
     * @return 配列の文字列表現
     * {@primary a String representation of the array}
     */    
    public static String toString(final Object array, final String stringIfNull) {
        if (array == null) {
            return stringIfNull;
        }
        return new ToStringBuilder(array, ToStringStyle.SIMPLE_STYLE).append(array).toString();
    }

    /**
     * <p>配列のハッシュコードを取得します。多次元配列も正しく処理されます。
     * {@primary Get a hashCode for an array handling multi-dimensional arrays correctly.}</p>
     * 
     * <p>このメソッドはプリミティブ型の多次元配列も正しく処理します。
     * {@primary Multi-dimensional primitive arrays are also handled correctly by this method.}</p>
     * 
     * @param array  ハッシュコードをを取得する配列、<code>null</code> を許容します
     * {@primary  the array to get a hashCode for, may be <code>null</code>}
     * @return 配列のハッシュコード、null の場合には0
     * {@primary a hashCode for the array, zero if null array input}
     */
    public static int hashCode(final Object array) {
        return new HashCodeBuilder().append(array).toHashCode();
    }

    /**
     * <p>equals() を使用して配列を比較します。多次元配列も正しく処理されます。
     * {@primary Compares two arrays, using equals(), handling multi-dimensional arrays
     * correctly.}</p>
     * 
     * <p>このメソッドはプリミティブ型の多次元配列も正しく処理します。
     * {@primary Multi-dimensional primitive arrays are also handled correctly by this method.}</p>
     * 
     * @param array1  ハッシュコードをを取得する配列、<code>null</code> を許容します
     * {@primary  the array to get a hashCode for, may be <code>null</code>}
     * @param array2  ハッシュコードをを取得する配列、<code>null</code> を許容します
     * {@primary  the array to get a hashCode for, may be <code>null</code>}
     * @return 配列が等しい場合、<code>true</code>
     * {@primary <code>true</code> if the arrays are equal}
     */
    public static boolean isEquals(final Object array1, final Object array2) {
        return new EqualsBuilder().append(array1, array2).isEquals();
    }

    // To map
    //-----------------------------------------------------------------------
    /**
     * <p>配列を {@link java.util.Map} に変換します。配列の各要素は {@link java.util.Map.Entry} 
     * または2つ以上の要素を持つ配列(1つ目の要素がキー、2つ目の要素が値になります)でなくてはなりません。
     * {@primary Converts the given array into a {@link java.util.Map}. Each element of the array
     * must be either a {@link java.util.Map.Entry} or an Array, containing at least two
     * elements, where the first element is used as key and the second as
     * value.</p>
     *
     * <p>このメソッドは以下のような初期化処理に使用することが出来ます:
     * {@primary This method can be used to initialize:}</p>
     * <pre>
     * // Create a Map mapping colors.
     * Map colorMap = MapUtils.toMap(new String[][] {{
     *     {"RED", "#FF0000"},
     *     {"GREEN", "#00FF00"},
     *     {"BLUE", "#0000FF"}});
     * </pre>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合には <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     *
     * @param array  {@link java.util.Map.Entry} または2つ以上の要素をもつ配列を要素に持つ配列、
     * <code>null</code> を許容します
     * {@primary an array whose elements are either a {@link java.util.Map.Entry} or 
     *  an Array containing at least two elements, may be <code>null</code>}
     * @return 配列から生成された <code>Map</code>
     * {@primary a <code>Map</code> that was created from the array}
     * @throws IllegalArgumentException  配列の要素が配列だった場合に要素数が2よりも少なかった場合
     * {@primary if one element of this Array is
     *  itself an Array containing less then two elements}
     * @throws IllegalArgumentException  配列の要素が {@link java.util.Map.Entry} または配列以外だった場合
     * {@primary if the array contains elements other
     *  than {@link java.util.Map.Entry} and an Array}
     */
    public static Map toMap(final Object[] array) {
        if (array == null) {
            return null;
        }
        final Map map = new HashMap((int) (array.length * 1.5));
        for (int i = 0; i < array.length; i++) {
            Object object = array[i];
            if (object instanceof Map.Entry) {
                Map.Entry entry = (Map.Entry) object;
                map.put(entry.getKey(), entry.getValue());
            } else if (object instanceof Object[]) {
                Object[] entry = (Object[]) object;
                if (entry.length < 2) {
                    throw new IllegalArgumentException("Array element " + i + ", '" 
                        + object
                        + "', has a length less than 2");
                }
                map.put(entry[0], entry[1]);
            } else {
                throw new IllegalArgumentException("Array element " + i + ", '" 
                        + object
                        + "', is neither of type Map.Entry nor an Array");
            }
        }
        return map;
    }

    // Clone
    //-----------------------------------------------------------------------
    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static Object[] clone(final Object[] array) {
        if (array == null) {
            return null;
        }
        return (Object[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static long[] clone(final long[] array) {
        if (array == null) {
            return null;
        }
        return (long[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static int[] clone(int[] array) {
        if (array == null) {
            return null;
        }
        return (int[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static short[] clone(final short[] array) {
        if (array == null) {
            return null;
        }
        return (short[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static char[] clone(final char[] array) {
        if (array == null) {
            return null;
        }
        return (char[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static byte[] clone(final byte[] array) {
        if (array == null) {
            return null;
        }
        return (byte[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static double[] clone(final double[] array) {
        if (array == null) {
            return null;
        }
        return (double[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static float[] clone(final float[] array) {
        if (array == null) {
            return null;
        }
        return (float[]) array.clone();
    }

    /**
     * <p>配列のクローンを生成して返します(<code>null</code> も処理します)。
     * {@primary Clones an array returning a typecast result and handling
     * <code>null</code>.}</p>
     *
     * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
     * 
     * @param array  <code>null</code> を許容する配列
     * {@primary the array to clone, may be <code>null</code>}
     * @return クローンされた配列、<code>null</code> が指定された場合には <code>null</code>
     * {@primary the cloned array, <code>null</code> if <code>null</code> input}
     */
    public static boolean[] clone(final boolean[] array) {
        if (array == null) {
            return null;
        }
        return (boolean[]) array.clone();
    }

    // Is same length
    //-----------------------------------------------------------------------
    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */    
    public static boolean isSameLength(final Object[] array1, final Object[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final long[] array1, final long[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final int[] array1, final int[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final short[] array1, final short[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final char[] array1, final char[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final byte[] array1, final byte[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final double[] array1, final double[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final float[] array1, final float[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の長さが同じであるかどうかをチェックします。
     * <code>null</code> の配列の長さは0とみなされます。
     * {@primary Checks whether two arrays are the same length, treating
     * <code>null</code> arrays as length <code>0</code>.}
     *
     * <p>配列の多次元要素は無視されます。
     * {@primary Any multi-dimensional aspects of the arrays are ignored.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容します
     * {@primary the first array, may be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容します
     * {@primary the second array, may be <code>null</code>}
     * @return 配列の長さが等しい場合 <code>true</code>、 <code>null</code> は空の配列とみなされます
     * {@primary <code>true</code> if length of arrays matches, treating
     *  <code>null</code> as an empty array}
     */
    public static boolean isSameLength(final boolean[] array1, final boolean[] array2) {
        if ((array1 == null && array2 != null && array2.length > 0) ||
            (array2 == null && array1 != null && array1.length > 0) ||
            (array1 != null && array2 != null && array1.length != array2.length)) {
                return false;
        }
        return true;
    }

    /**
     * <p>2つの配列の型と次元宣言が等しいかどうかをチェックします。
     * {@primary Checks whether two arrays are the same type taking into account
     * multi-dimensional arrays.}</p>
     * 
     * @param array1 1つ目の配列、<code>null</code> を許容しません
     * {@primary the first array, must not be <code>null</code>}
     * @param array2 2つ目の配列、<code>null</code> を許容しません
     * {@primary the second array, must not be <code>null</code>}
     * @return 2つの配列が同じ宣言の場合 <code>true</code>
     * {@primary <code>true</code> if type of arrays matches}
     * @throws IllegalArgumentException どちらかの配列が <code>null</code> の場合
     * {@primary if either array is <code>null</code>}
     */    
    public static boolean isSameType(final Object array1, final Object array2) {
        if (array1 == null || array2 == null) {
            throw new IllegalArgumentException("The Array must not be null");
        }
        return array1.getClass().getName().equals(array2.getClass().getName());
    }

    // Reverse
    //-----------------------------------------------------------------------
    /** 
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     *
     * <p>多次元配列を考慮した処理は行われません。
     * {@primary There is no special handling for multi-dimensional arrays.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final Object[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        Object tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final long[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        long tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final int[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        int tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final short[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        short tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final char[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        char tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final byte[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        byte tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final double[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        double tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final float[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        float tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    /**
     * <p>渡された配列の並び順を逆にします。
     * {@primary Reverses the order of the given array.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が渡された場合、何もしません。
     * {@primary This method does nothing if <code>null</code> array input.}</p>
     * 
     * @param array  配列の並び順を逆にする配列、<code>null</code> を許容します
     * {@primary the array to reverse, may be <code>null</code>}
     */
    public static void reverse(final boolean[] array) {
        if (array == null) {
            return;
        }
        int i = 0;
        int j = array.length - 1;
        boolean tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }

    // IndexOf search
    // ----------------------------------------------------------------------
    
    // Object IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定されたオブジェクトを探し、そのインデックスを返します。
     * {@primary Find the index of the given object in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  オブジェクトを検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param objectToFind  検索するオブジェクト、<code>null</code> を許容します
     * {@primary the object to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the object within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final Object[] array, final Object objectToFind) {
        return indexOf(array, objectToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定されたオブジェクトを探し、そのインデックスを返します。
     * {@primary Find the index of the given object in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  オブジェクトを検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param objectToFind  検索するオブジェクト、<code>null</code> を許容します
     * {@primary the object to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the object within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final Object[] array, final Object objectToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        if (objectToFind == null) {
            for (int i = startIndex; i < array.length; i++) {
                if (array[i] == null) {
                    return i;
                }
            }
        } else {
            for (int i = startIndex; i < array.length; i++) {
                if (objectToFind.equals(array[i])) {
                    return i;
                }
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定されたオブジェクトを探し、そのインデックスを返します。
     * {@primary Find the last index of the given object within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  オブジェクトを後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param objectToFind  検索するオブジェクト、<code>null</code> を許容します
     * {@primary the object to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final Object[] array, final Object objectToFind) {
        return lastIndexOf(array, objectToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定されたオブジェクトを探し、そのインデックスを返します。
     * {@primary Find the last index of the given object in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  オブジェクトを後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param objectToFind  検索するオブジェクト、<code>null</code> を許容します
     * {@primary the object to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final Object[] array, final Object objectToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        if (objectToFind == null) {
            for (int i = startIndex; i >= 0; i--) {
                if (array[i] == null) {
                    return i;
                }
            }
        } else {
            for (int i = startIndex; i >= 0; i--) {
                if (objectToFind.equals(array[i])) {
                    return i;
                }
            }
        }
        return -1;
    }

    /**
     * <p>指定されたオブジェクトがこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the object is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param objectToFind  検索対象となるオブジェクト
     * {@primary the object to find}
     * @return 配列が指定されたオブジェクトを含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final Object[] array, final Object objectToFind) {
        return (indexOf(array, objectToFind) != -1);
    }

    // long IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final long[] array, final long valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final long[] array, final long valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final long[] array, final long valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final long[] array, final long valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final long[] array, final long valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    // int IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final int[] array, final int valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final int[] array, final int valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final int[] array, final int valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final int[] array, final int valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final int[] array, final int valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    // short IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final short[] array, final short valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final short[] array, final short valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final short[] array, final short valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final short[] array, final short valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final short[] array, final short valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    // byte IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final byte[] array, final byte valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final byte[] array, final byte valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final byte[] array, final byte valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final byte[] array, final byte valueToFind, int startIndex) {
        if (array == null) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final byte[] array, final byte valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    // double IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final double[] array, final double valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中から指定された値と指定された誤差に該当するものを探し、そのインデックスを返します。
     * このメソッドは最初に見つかった valueToFind - tolerance と valueToFind + tolerance
     * の範囲に該当する値のインデックスを返します。
     * {@primary Find the index of the given value within a given tolerance in the array.
     * This method will return the index of the first value which falls between the region
     * defined by valueToFind - tolerance and valueToFind + tolerance.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値
     * {@primary the value to find}
     * @param tolerance 検索時の誤差
     * {@primary tolerance of the search}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final double[] array, final double valueToFind, final double tolerance) {
        return indexOf(array, valueToFind, 0, tolerance);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final double[] array, final double valueToFind, int startIndex) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値と指定された誤差に該当するものを探し、そのインデックスを返します。
     * このメソッドは最初に見つかった valueToFind - tolerance と valueToFind + tolerance
     * の範囲に該当する値のインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.
     * This method will return the index of the first value which falls between the region
     * defined by valueToFind - tolerance and valueToFind + tolerance.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値
     * {@primary the value to find}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @param tolerance 検索時の誤差
     * {@primary tolerance of the search}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final double[] array, final double valueToFind, int startIndex, double tolerance) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        double min = valueToFind - tolerance;
        double max = valueToFind + tolerance;
        for (int i = startIndex; i < array.length; i++) {
            if (array[i] >= min && array[i] <= max) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final double[] array, final double valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の後ろから順に指定された値と指定された誤差に該当するものを探し、そのインデックスを返します。
     * このメソッドは最後に見つかった valueToFind - tolerance と valueToFind + tolerance
     * の範囲に該当する値のインデックスを返します。
     * {@primary Find the last index of the given value within a given tolerance in the array.
     * This method will return the index of the last value which falls between the region
     * defined by valueToFind - tolerance and valueToFind + tolerance.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値
     * {@primary the value to find}
     * @param tolerance 検索時の誤差
     * {@primary tolerance of the search}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final double[] array, final double valueToFind, final double tolerance) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE, tolerance);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値と指定された誤差に該当するものを探し、そのインデックスを返します。
     * このメソッドは最後に見つかった valueToFind - tolerance と valueToFind + tolerance
     * の範囲に該当する値のインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.
     * This method will return the index of the last value which falls between the region
     * defined by valueToFind - tolerance and valueToFind + tolerance.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値
     * {@primary the value to find}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @param tolerance  検索対象の+/-の誤差の値
     * {@primary search for value within plus/minus this amount}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex, double tolerance) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        double min = valueToFind - tolerance;
        double max = valueToFind + tolerance;
        for (int i = startIndex; i >= 0; i--) {
            if (array[i] >= min && array[i] <= max) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final double[] array, final double valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    /**
     * <p>指定された値と指定された誤差に該当する値がこの配列内に含まれているかどうかチェックします。
     * 配列が (value - tolerance) から (value + tolerance) の範囲に該当する値を含んでいた場合
     * <code>true</code> を返します。
     * {@primary Checks if a value falling within the given tolerance is in the
     * given array.  If the array contains a value within the inclusive range 
     * defined by (value - tolerance) to (value + tolerance).}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     *
     * @param array  検索先となる配列
     * {@primary the array to search}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @param tolerance  配列を検索する際の誤差
     * {@primary the array contains the tolerance of the search}
     * @return 配列が指定された誤差範囲の値を含む場合、<code>true</code>
     * {@primary true if value falling within tolerance is in array}
     */
    public static boolean contains(final double[] array, final double valueToFind, final double tolerance) {
        return (indexOf(array, valueToFind, 0, tolerance) != -1);
    }

    // float IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final float[] array, final float valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final float[] array, final float valueToFind, int startIndex) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final float[] array, final float valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final float[] array, final float valueToFind, int startIndex) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final float[] array, final float valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    // boolean IndexOf
    //-----------------------------------------------------------------------
    /**
     * <p>配列の中から指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given valie in the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final boolean[] array, final boolean valueToFind) {
        return indexOf(array, valueToFind, 0);
    }

    /**
     * <p>配列の中の指定されたインデックスより後ろから指定された値を探し、そのインデックスを返します。
     * {@primary Find the index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex の値は0とみなされます。
     * startIndex が配列の長さより大きい場合には <code>-1</code> が返されます。
     * {@primary A negative startIndex is treated as zero. A startIndex larger than the array
     * length will return <code>-1</code>.}</p>
     * 
     * @param array  値を検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to search through for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  検索を開始するインデックス
     * {@primary the index to start searching at}
     * @return 配列中の値のインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the index of the valie within the array, 
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            startIndex = 0;
        }
        for (int i = startIndex; i < array.length; i++) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>配列の後ろから順に指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value within the array.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the valie within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final boolean[] array, final boolean valueToFind) {
        return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
    }

    /**
     * <p>配列の中の指定されたインデックスから前方に向かって指定された値を探し、そのインデックスを返します。
     * {@primary Find the last index of the given value in the array starting at the given index.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>-1</code> を返します。
     * {@primary This method returns <code>-1</code> if <code>null</code> array input.}</p>
     *
     * <p>マイナスの startIndex が指定された場合には -1 を返します。
     * startIndex が配列の長さより大きい場合には配列の一番後ろからの検索を行います。
     * {@primary A negative startIndex will return -1. A startIndex larger than the array
     * length will search from the end of the array.}</p>
     * 
     * @param array  値を後ろから順に検索する対象となる配列、<code>null</code> を許容します
     * {@primary the array to travers backwords looking for the object, may be <code>null</code>}
     * @param valueToFind  検索する値、<code>null</code> を許容します
     * {@primary the valie to find, may be <code>null</code>}
     * @param startIndex  後ろから前への検索を開始するインデックス
     * {@primary the start index to travers backwards from}
     * @return 配列中のオブジェクトのインデックス、見つからなかった場合、配列が
     * <code>null</code> だった場合には <code>-1</code>
     * {@primary the last index of the object within the array,
     *  <code>-1</code> if not found or <code>null</code> array input}
     */
    public static int lastIndexOf(final boolean[] array, final boolean valueToFind, int startIndex) {
        if (array == null || array.length == 0) {
            return -1;
        }
        if (startIndex < 0) {
            return -1;
        } else if (startIndex >= array.length) {
            startIndex = array.length - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return -1;
    }

    /**
     * <p>指定された値がこの配列内に含まれているかどうかチェックします。
     * {@primary Checks if the value is in the given array.}</p>
     *
     * <p><code>null</code> の配列が指定された場合、このメソッドは <code>false</code> を返します。
     * {@primary The method returns <code>false</code> if a <code>null</code> array is passed in.}</p>
     * 
     * @param array  検索先となる配列
     * {@primary the array to search through}
     * @param valueToFind  検索対象となる値
     * {@primary the value to find}
     * @return 配列が指定された値を含む場合、<code>true</code>
     * {@primary <code>true</code> if the array contains the object}
     */
    public static boolean contains(final boolean[] array, final boolean valueToFind) {
        return (indexOf(array, valueToFind) != -1);
    }

    // Primitive/Object array converters
    // ----------------------------------------------------------------------
    
    // Long array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Long オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Longs to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Long</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Long</code> array, may be <code>null</code>}
     * @return <code>long</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>long</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static long[] toPrimitive(final Long[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_LONG_ARRAY;
        }
        final long[] result = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].longValue();
        }
        return result;
    }
    
    /**
     * <p>Long オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Long to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Long</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Long</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>long</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>long</code> array, <code>null</code> if null array input}
     */
    public static long[] toPrimitive(final Long[] array, final long valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_LONG_ARRAY;
        }
        final long[] result = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            Long b = array[i];
            result[i] = (b == null ? valueForNull : b.longValue());
        }
        return result;
    }
    
    /**
     * <p>ling プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive longs to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>long</code> の配列
     * {@primary a <code>long</code> array}
     * @return <code>Long</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Long</code> array, <code>null</code> if null array input}
     */
    public static Long[] toObject(final long[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_LONG_OBJECT_ARRAY;
        }
        final Long[] result = new Long[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = new Long(array[i]);
        }
        return result;
    }

    // Int array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Integer オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Integers to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Integer</code> の配列、<code>null</code> を許容します
     * {@primary an <code>Integer</code> array, may be <code>null</code>}
     * @return <code>int</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary an <code>int</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static int[] toPrimitive(final Integer[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_INT_ARRAY;
        }
        final int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }

    /**
     * <p>Integer オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Integer to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Integer</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Integer</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>int</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary an <code>int</code> array, <code>null</code> if null array input}
     */
    public static int[] toPrimitive(final Integer[] array, final int valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_INT_ARRAY;
        }
        final int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            Integer b = array[i];
            result[i] = (b == null ? valueForNull : b.intValue());
        }
        return result;
    }

    /**
     * <p>int プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive ints to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>int</code> の配列
     * {@primary a <code>int</code> array}
     * @return <code>Integer</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Integer</code> array, <code>null</code> if null array input}
     */
    public static Integer[] toObject(final int[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_INTEGER_OBJECT_ARRAY;
        }
        final Integer[] result = new Integer[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = new Integer(array[i]);
        }
        return result;
    }
    
    // Short array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Short オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Shorts to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Short</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Short</code> array, may be <code>null</code>}
     * @return <code>short</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>short</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static short[] toPrimitive(final Short[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_SHORT_ARRAY;
        }
        final short[] result = new short[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].shortValue();
        }
        return result;
    }

    /**
     * <p>Short オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Short to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Short</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Short</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>short</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>short</code> array, <code>null</code> if null array input}
     */
    public static short[] toPrimitive(final Short[] array, final short valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_SHORT_ARRAY;
        }
        final short[] result = new short[array.length];
        for (int i = 0; i < array.length; i++) {
            Short b = array[i];
            result[i] = (b == null ? valueForNull : b.shortValue());
        }
        return result;
    }

    /**
     * <p>short プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive shorts to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>short</code> の配列
     * {@primary a <code>short</code> array}
     * @return <code>Short</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Short</code> array, <code>null</code> if null array input}
     */
    public static Short[] toObject(final short[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_SHORT_OBJECT_ARRAY;
        }
        final Short[] result = new Short[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = new Short(array[i]);
        }
        return result;
    }    

    // Byte array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Byte オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Bytes to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Byte</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Byte</code> array, may be <code>null</code>}
     * @return <code>byte</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>byte</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static byte[] toPrimitive(final Byte[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_BYTE_ARRAY;
        }
        final byte[] result = new byte[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].byteValue();
        }
        return result;
    }

    /**
     * <p>Byte オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Byte to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Byte</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Byte</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>byte</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>byte</code> array, <code>null</code> if null array input}
     */
    public static byte[] toPrimitive(final Byte[] array, final byte valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_BYTE_ARRAY;
        }
        final byte[] result = new byte[array.length];
        for (int i = 0; i < array.length; i++) {
            Byte b = array[i];
            result[i] = (b == null ? valueForNull : b.byteValue());
        }
        return result;
    }

    /**
     * <p>byte プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive bytes to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>byte</code> の配列
     * {@primary a <code>byte</code> array}
     * @return <code>Byte</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Byte</code> array, <code>null</code> if null array input}
     */
    public static Byte[] toObject(final byte[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_BYTE_OBJECT_ARRAY;
        }
        final Byte[] result = new Byte[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = new Byte(array[i]);
        }
        return result;
    }  
    
    // Double array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Double オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Doubles to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Double</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Double</code> array, may be <code>null</code>}
     * @return <code>double</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>double</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static double[] toPrimitive(final Double[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_DOUBLE_ARRAY;
        }
        final double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }

    /**
     * <p>Double オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Doubles to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Double</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Double</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>double</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>double</code> array, <code>null</code> if null array input}
     */
    public static double[] toPrimitive(final Double[] array, final double valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_DOUBLE_ARRAY;
        }
        final double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            Double b = array[i];
            result[i] = (b == null ? valueForNull : b.doubleValue());
        }
        return result;
    }

    /**
     * <p>double プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive doubles to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>double</code> の配列
     * {@primary a <code>double</code> array}
     * @return <code>Double</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Double</code> array, <code>null</code> if null array input}
     */
    public static Double[] toObject(final double[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_DOUBLE_OBJECT_ARRAY;
        }
        final Double[] result = new Double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = new Double(array[i]);
        }
        return result;
    }

    //   Float array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Float オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Floats to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Float</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Float</code> array, may be <code>null</code>}
     * @return <code>float</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>float</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static float[] toPrimitive(final Float[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_FLOAT_ARRAY;
        }
        final float[] result = new float[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].floatValue();
        }
        return result;
    }

    /**
     * <p>Float オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Floats to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Float</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Float</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>float</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>float</code> array, <code>null</code> if null array input}
     */
    public static float[] toPrimitive(final Float[] array, final float valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_FLOAT_ARRAY;
        }
        final float[] result = new float[array.length];
        for (int i = 0; i < array.length; i++) {
            Float b = array[i];
            result[i] = (b == null ? valueForNull : b.floatValue());
        }
        return result;
    }

    /**
     * <p>float プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive floats to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>float</code> の配列
     * {@primary a <code>float</code> array}
     * @return <code>Float</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Float</code> array, <code>null</code> if null array input}
     */
    public static Float[] toObject(final float[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_FLOAT_OBJECT_ARRAY;
        }
        final Float[] result = new Float[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = new Float(array[i]);
        }
        return result;
    }

    // Boolean array converters
    // ----------------------------------------------------------------------
    /**
     * <p>Boolean オブジェクトの配列をプリミティブ型の配列に変換します。
     * {@primary Converts an array of object Booleans to primitives.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Boolean</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Boolean</code> array, may be <code>null</code>}
     * @return <code>boolean</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>boolean</code> array, <code>null</code> if null array input}
     * @throws NullPointerException 配列が <code>null</code>の要素をもっていた場合
     * {@primary if array content is <code>null</code>}
     */
    public static boolean[] toPrimitive(final Boolean[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_BOOLEAN_ARRAY;
        }
        final boolean[] result = new boolean[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].booleanValue();
        }
        return result;
    }

    /**
     * <p>Boolean オブジェクトの配列をプリミティブ型の配列に変換します(<code>null</code> の要素を処理します)。
     * {@primary Converts an array of object Booleans to primitives handling <code>null</code>.}</p>
     * 
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>Boolean</code> の配列、<code>null</code> を許容します
     * {@primary a <code>Boolean</code> array, may be <code>null</code>}
     * @param valueForNull  <code>null</code> が見つかった場合に適用する値
     * {@primary the value to insert if <code>null</code> found}
     * @return <code>boolean</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>boolean</code> array, <code>null</code> if null array input}
     */
    public static boolean[] toPrimitive(final Boolean[] array, final boolean valueForNull) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_BOOLEAN_ARRAY;
        }
        final boolean[] result = new boolean[array.length];
        for (int i = 0; i < array.length; i++) {
            Boolean b = array[i];
            result[i] = (b == null ? valueForNull : b.booleanValue());
        }
        return result;
    }

    /**
     * <p>boolean プリミティブ型の配列をオブジェクトの配列に変換します。
     * {@primary Converts an array of primitive booleans to objects.}</p>
     *
     * <p>このメソッドは <code>null</code> の配列が指定された場合 <code>null</code> を返します。
     * {@primary This method returns <code>null</code> if <code>null</code> array input.}</p>
     * 
     * @param array  <code>boolean</code> の配列
     * {@primary a <code>boolean</code> array}
     * @return <code>Boolean</code> の配列、<code>null</code> の配列が指定された場合 <code>null</code>
     * {@primary a <code>Boolean</code> array, <code>null</code> if null array input}
     */
    public static Boolean[] toObject(final boolean[] array) {
        if (array == null) {
            return null;
        } else if (array.length == 0) {
            return EMPTY_BOOLEAN_OBJECT_ARRAY;
        }
        final Boolean[] result = new Boolean[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (array[i] ? Boolean.TRUE : Boolean.FALSE);
        }
        return result;
    }

}

