1 package com
.github
.puzzles
.util
;
3 import java
.util
.Arrays
;
5 public class Matrices
{
7 //Don't let anyone instance this class.
12 * Copy 2 dimensions array.
14 * @param original the matrix which you want make a copy of it.
15 * @return the new copy.
17 public static <T
> T
[][] copyOf(T
[][] original
, int colsLength
, int rowsLength
){
18 T
[][] returnedPuzzle
= Arrays
.copyOf(original
, colsLength
);
19 for(int i
= 0; i
< colsLength
; i
++)
20 returnedPuzzle
[i
] = Arrays
.copyOf(original
[i
], rowsLength
);
22 return returnedPuzzle
;
25 public static <T
> T
[][] copyOf(T
[][] original
){
26 if (original
.length
< 0) {
29 return copyOf(original
, original
.length
, original
[0].length
);
34 * Fill a value in a matrix.
36 * @param matrix the matrix which you want to fill in it.
37 * @param val the value which you want fill it in the matrix.
39 public static <T
> void fill(T
[][] matrix
, T val
){
40 for(int i
= 0; i
< matrix
.length
; i
++)
41 Arrays
.fill(matrix
[i
], val
);