Java Double Array Create toDoubleArray(boolean[] array)

Here you can find the source of toDoubleArray(boolean[] array)

Description

Coverts given booleans array to array of doubles.

License

Open Source License

Parameter

Parameter Description
array booleans array to convert.

Return

converted array of doubles.

Declaration

public static double[] toDoubleArray(boolean[] array) 

Method Source Code

//package com.java2s;
/*/*from ww  w. ja  v a2  s . c  om*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2016. Diorite (by Bart?omiej Mazur (aka GotoFinal))
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

public class Main {
    /**
     * Coverts given booleans array to array of doubles.
     *
     * @param array
     *         booleans array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(boolean[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i] ? 1 : 0;
        }
        return result;
    }

    /**
     * Coverts given shorts array to array of doubles.
     *
     * @param array
     *         shorts array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(short[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (double) array[i];
        }
        return result;
    }

    /**
     * Coverts given chars array to array of doubles.
     *
     * @param array
     *         chars array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(char[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (double) array[i];
        }
        return result;
    }

    /**
     * Coverts given ints array to array of doubles.
     *
     * @param array
     *         ints array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(int[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (double) array[i];
        }
        return result;
    }

    /**
     * Coverts given longs array to array of doubles.
     *
     * @param array
     *         longs array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(long[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (double) array[i];
        }
        return result;
    }

    /**
     * Coverts given floats array to array of doubles.
     *
     * @param array
     *         floats array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(float[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (double) array[i];
        }
        return result;
    }

    /**
     * Coverts given bytes array to array of doubles.
     *
     * @param array
     *         bytes array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(byte[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (double) array[i];
        }
        return result;
    }

    /**
     * Coverts given doubles array to array of doubles.
     *
     * @param array
     *         doubles array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Double[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }

    /**
     * Coverts given numbers array to array of bytes.
     *
     * @param array
     *         numbers array to convert.
     *
     * @return converted array of bytes.
     */
    public static double[] toDoubleArray(Number[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }

    /**
     * Coverts given booleans array to array of doubles.
     *
     * @param array
     *         booleans array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Boolean[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i] ? 1 : 0;
        }
        return result;
    }

    /**
     * Coverts given shorts array to array of doubles.
     *
     * @param array
     *         shorts array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Short[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }

    /**
     * Coverts given chars array to array of doubles.
     *
     * @param array
     *         chars array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Character[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            //noinspection UnnecessaryUnboxing
            result[i] = ((double) array[i].charValue());
        }
        return result;
    }

    /**
     * Coverts given ints array to array of doubles.
     *
     * @param array
     *         ints array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Integer[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }

    /**
     * Coverts given longs array to array of doubles.
     *
     * @param array
     *         longs array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Long[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }

    /**
     * Coverts given floats array to array of doubles.
     *
     * @param array
     *         floats array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Float[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }

    /**
     * Coverts given bytes array to array of doubles.
     *
     * @param array
     *         bytes array to convert.
     *
     * @return converted array of doubles.
     */
    public static double[] toDoubleArray(Byte[] array) {
        double[] result = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].doubleValue();
        }
        return result;
    }
}

Related

  1. doubleArrayFromString(final String data)
  2. doubleArrayFromString(String record)
  3. doubleArraySize(byte[] array)
  4. toDoubleA(byte[] data)
  5. toDoubleArr(short[] arr)
  6. toDoubleArray(byte[] byteArray)
  7. toDoubleArray(byte[] data)
  8. toDoubleArray(Double[] data)
  9. toDoubleArray(final byte[] array)