Java Matrix Swap swapTwoBlocks(int[][] pattern, int block1, int block2)

Here you can find the source of swapTwoBlocks(int[][] pattern, int block1, int block2)

Description

swap Two Blocks

License

Open Source License

Declaration

public static int[][] swapTwoBlocks(int[][] pattern, int block1, int block2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int[][] swapTwoBlocks(int[][] pattern, int block1, int block2) {
        // TODO: Testing is key. Do I *have* to use Arrays.copy, or clone(), or something?
        int[] temp_row1 = pattern[0 + 3 * block1];
        int[] temp_row2 = pattern[1 + 3 * block1];
        int[] temp_row3 = pattern[2 + 3 * block1];

        pattern[0 + 3 * block1] = pattern[0 + 3 * block2];
        pattern[1 + 3 * block1] = pattern[1 + 3 * block2];
        pattern[2 + 3 * block1] = pattern[2 + 3 * block2];

        pattern[0 + 3 * block2] = temp_row1;
        pattern[1 + 3 * block2] = temp_row2;
        pattern[2 + 3 * block2] = temp_row3;

        return pattern;
    }//w  w  w  . j a va  2s .com

    public static <E> E[][] swapTwoBlocks(E[][] pattern, int block1, int block2) {
        // TODO: Testing is key. Do I *have* to use Arrays.copy, or clone(), or something?
        E[] temp_row1 = pattern[0 + 3 * block1];
        E[] temp_row2 = pattern[1 + 3 * block1];
        E[] temp_row3 = pattern[2 + 3 * block1];

        pattern[0 + 3 * block1] = pattern[0 + 3 * block2];
        pattern[1 + 3 * block1] = pattern[1 + 3 * block2];
        pattern[2 + 3 * block1] = pattern[2 + 3 * block2];

        pattern[0 + 3 * block2] = temp_row1;
        pattern[1 + 3 * block2] = temp_row2;
        pattern[2 + 3 * block2] = temp_row3;

        return pattern;
    }
}

Related

  1. swapColumns(int i, int j, boolean[][] matrix)
  2. swapRows(double[][] a, int i, int j)
  3. swapRows(double[][] Ab, int k, int i)
  4. swapRows(double[][] matrix, int i1, int i2)
  5. swapShorts(byte bs[][])
  6. swapTwoRows(byte[][] pattern, int row1, int row2)