-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.java
More file actions
82 lines (66 loc) · 2.11 KB
/
Copy pathUtility.java
File metadata and controls
82 lines (66 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package hus.TestZone.ChessGameTest.TheGame;
import hus.TestZone.ChessGameTest.TheGame.Board.Board;
import java.util.Arrays;
public class Utility {
public static void printIntArray(int[] arr) {
if (arr == null) {
System.out.println("Array is null");
return;
}
System.out.println(Arrays.toString(arr));
}
public static int[] mergeArrays(int[]... arrays) {
int totalLength = 0;
for (int[] array : arrays) {
if (array != null) {
totalLength += array.length;
}
}
int[] mergedArray = new int[totalLength];
int index = 0;
for (int[] array : arrays) {
if (array != null) {
for (int num : array) {
mergedArray[index++] = num;
}
}
}
return mergedArray;
}
public static boolean containsElement(int[] arr, int target) {
for (int element : arr) {
if (element == target) {
return true;
}
}
return false;
}
public static int rowColToId(int row, int col, int size) {
return row * size + col;
}
public static int coordinateToId(String coordinate) {
return Board.coordinateToId.getOrDefault(coordinate, -1);
}
public static int[] coordinatesArrayToIdsArray(String[] coordinates) {
int[] ids = new int[coordinates.length];
for (int i = 0; i < coordinates.length; i++) {
ids[i] = coordinateToId(coordinates[i]);
}
return ids;
}
public static String[] idsArrayToCoordinatesArray(int[] ids) {
String[] coordinates = new String[ids.length];
for (int i = 0; i < ids.length; i++) {
coordinates[i] = idToCoordinate(ids[i]);
}
return coordinates;
}
public static String idToCoordinate(int id) {
return Board.idToCoordinate.getOrDefault(id, "");
}
public static int[] idToRowCol(int id, int size) {
int row = id / size;
int col = id % size;
return new int[]{row, col};
}
}