Java Array Copy copyArray(int[][][] data)

Here you can find the source of copyArray(int[][][] data)

Description

Copies the given array to a new one that it returns

License

Open Source License

Parameter

Parameter Description
data The data to duplicate

Return

an copy of the array

Declaration

public static int[][][] copyArray(int[][][] data) 

Method Source Code

//package com.java2s;
/*//from   www .  j a v a2  s  .c o m
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Ziver Koc
 *
 * 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 {
    /**
     * Copies the given array to a new one that it returns
     *
     * @param   data    The data to duplicate
     * @return an copy of the array
     */
    public static int[][][] copyArray(int[][][] data) {
        return copyArray(data, 0, 0, data[0].length, data.length);
    }

    /**
     * Copies the given array to a new one that it returns
     *
     * @param   data    The data to duplicate
     * @param   startX  is the x pixel of the image to start from
     * @param   startY  is the y pixel of the image to start from
     * @param   stopX   is the x pixel of the image to stop
     * @param   stopY   is the y pixel of the image to stop
     * @return The array copy
     */
    public static int[][][] copyArray(int[][][] data, int startX, int startY, int stopX, int stopY) {
        int[][][] copy = new int[data.length][data[0].length][4];
        return copyArray(data, copy, startX, startY, stopX, stopY);
    }

    /**
     * Copies the given array to a new one that it returns
     *
     * @param   data    The data to duplicate
     * @param   dest    is the array to copy the data to
     * @param   startX  is the x pixel of the image to start from
     * @param   startY  is the y pixel of the image to start from
     * @param   stopX   is the x pixel of the image to stop
     * @param   stopY   is the y pixel of the image to stop
     * @return the dest array
     */
    public static int[][][] copyArray(int[][][] data, int[][][] dest, int startX, int startY, int stopX,
            int stopY) {
        for (int y = startY; y < stopY; y++) {
            for (int x = startX; x < stopX; x++) {
                dest[y][x][0] = data[y][x][0];
                dest[y][x][1] = data[y][x][1];
                dest[y][x][2] = data[y][x][2];
                dest[y][x][3] = data[y][x][3];
            }
        }
        return dest;
    }
}

Related

  1. copyArray(int[] ar)
  2. copyArray(int[] inArr, int[] outArr)
  3. copyArray(int[][] arr)
  4. copyArray(int[][] links, int rowNum, int columnNum)
  5. copyArray(int[][] src)
  6. copyArray(long[] array)
  7. copyArray(Object source, Object dest, int count)
  8. copyArray(Object[] array)
  9. copyArray(Object[] array, int from, int to)