Java Long Number Array Create toLongArray(boolean[] array)

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

Description

Coverts given booleans array to array of longs.

License

Open Source License

Parameter

Parameter Description
array booleans array to convert.

Return

converted array of longs.

Declaration

public static long[] toLongArray(boolean[] array) 

Method Source Code

//package com.java2s;
/*/* w w  w  . ja va 2s .  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 longs.
     *
     * @param array
     *         booleans array to convert.
     *
     * @return converted array of longs.
     */
    public static long[] toLongArray(boolean[] array) {
        long[] result = new long[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 longs.
     *
     * @param array
     *         shorts array to convert.
     *
     * @return converted array of longs.
     */
    public static long[] toLongArray(short[] array) {
        long[] result = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (long) array[i];
        }
        return result;
    }

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

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

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

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

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

    /**
     * Coverts given longs array to array of longs.
     *
     * @param array
     *         longs array to convert.
     *
     * @return converted array of longs.
     */
    public static long[] toLongArray(Long[] array) {
        long[] result = new long[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 long[] toLongArray(Number[] array) {
        long[] result = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].longValue();
        }
        return result;
    }

    /**
     * Coverts given booleans array to array of longs.
     *
     * @param array
     *         booleans array to convert.
     *
     * @return converted array of longs.
     */
    public static long[] toLongArray(Boolean[] array) {
        long[] result = new long[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 longs.
     *
     * @param array
     *         shorts array to convert.
     *
     * @return converted array of longs.
     */
    public static long[] toLongArray(Short[] array) {
        long[] result = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].longValue();
        }
        return result;
    }

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

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

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

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

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

Related

  1. longArray(int len)
  2. LongArrayFrom(long[] array)
  3. LongArrayFrom(long[] array)
  4. toLongA(byte[] data)
  5. toLongArray(byte[] array)
  6. toLongArray(byte[] byteArray)
  7. toLongArray(byte[] byteArray)
  8. toLongArray(byte[] data)