Skip to content

Commit e96f567

Browse files
authored
Format code with prettier (#3375)
1 parent 32b9b11 commit e96f567

File tree

464 files changed

+11559
-6265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

464 files changed

+11559
-6265
lines changed

src/main/java/com/thealgorithms/audiofilters/IIRFilter.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public class IIRFilter {
2222
*/
2323
public IIRFilter(int order) throws IllegalArgumentException {
2424
if (order < 1) {
25-
throw new IllegalArgumentException("order must be greater than zero");
25+
throw new IllegalArgumentException(
26+
"order must be greater than zero"
27+
);
2628
}
2729

2830
this.order = order;
@@ -45,17 +47,24 @@ public IIRFilter(int order) throws IllegalArgumentException {
4547
* @throws IllegalArgumentException if {@code aCoeffs} or {@code bCoeffs} is
4648
* not of size {@code order}, or if {@code aCoeffs[0]} is 0.0
4749
*/
48-
public void setCoeffs(double[] aCoeffs, double[] bCoeffs) throws IllegalArgumentException {
50+
public void setCoeffs(double[] aCoeffs, double[] bCoeffs)
51+
throws IllegalArgumentException {
4952
if (aCoeffs.length != order) {
50-
throw new IllegalArgumentException("aCoeffs must be of size " + order + ", got " + aCoeffs.length);
53+
throw new IllegalArgumentException(
54+
"aCoeffs must be of size " + order + ", got " + aCoeffs.length
55+
);
5156
}
5257

5358
if (aCoeffs[0] == 0.0) {
54-
throw new IllegalArgumentException("aCoeffs.get(0) must not be zero");
59+
throw new IllegalArgumentException(
60+
"aCoeffs.get(0) must not be zero"
61+
);
5562
}
5663

5764
if (bCoeffs.length != order) {
58-
throw new IllegalArgumentException("bCoeffs must be of size " + order + ", got " + bCoeffs.length);
65+
throw new IllegalArgumentException(
66+
"bCoeffs must be of size " + order + ", got " + bCoeffs.length
67+
);
5968
}
6069

6170
for (int i = 0; i <= order; i++) {
@@ -75,7 +84,8 @@ public double process(double sample) {
7584

7685
// Process
7786
for (int i = 1; i <= order; i++) {
78-
result += (coeffsB[i] * historyX[i - 1] - coeffsA[i] * historyY[i - 1]);
87+
result +=
88+
(coeffsB[i] * historyX[i - 1] - coeffsA[i] * historyY[i - 1]);
7989
}
8090
result = (result + coeffsB[0] * sample) / coeffsA[0];
8191

src/main/java/com/thealgorithms/backtracking/Combination.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
* @author Alan Piao (https://github.com/cpiao3)
88
*/
99
public class Combination {
10+
1011
private static int length;
12+
1113
/**
1214
* Find all combinations of given array using backtracking
1315
* @param arr the array.
@@ -26,6 +28,7 @@ public static <T> List<TreeSet<T>> combination(T[] arr, int n) {
2628
backtracking(array, 0, new TreeSet<T>(), result);
2729
return result;
2830
}
31+
2932
/**
3033
* Backtrack all possible combinations of a given array
3134
* @param arr the array.
@@ -34,7 +37,12 @@ public static <T> List<TreeSet<T>> combination(T[] arr, int n) {
3437
* @param result the list contains all combination.
3538
* @param <T> the type of elements in the array.
3639
*/
37-
private static <T> void backtracking(T[] arr, int index, TreeSet<T> currSet, List<TreeSet<T>> result) {
40+
private static <T> void backtracking(
41+
T[] arr,
42+
int index,
43+
TreeSet<T> currSet,
44+
List<TreeSet<T>> result
45+
) {
3846
if (index + length - currSet.size() > arr.length) return;
3947
if (length - 1 == currSet.size()) {
4048
for (int i = index; i < arr.length; i++) {

src/main/java/com/thealgorithms/backtracking/FloodFill.java

+32-34
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,22 @@ public class FloodFill {
1313
* @param x The x co-ordinate of which color is to be obtained
1414
* @param y The y co-ordinate of which color is to be obtained
1515
*/
16-
17-
public static int getPixel(int[][] image, int x, int y) {
18-
19-
return image[x][y];
20-
21-
}
22-
16+
17+
public static int getPixel(int[][] image, int x, int y) {
18+
return image[x][y];
19+
}
20+
2321
/**
2422
* Put the color at the given co-odrinates of a 2D image
2523
*
2624
* @param image The image to be filed
2725
* @param x The x co-ordinate at which color is to be filled
2826
* @param y The y co-ordinate at which color is to be filled
2927
*/
30-
public static void putPixel(int[][] image, int x, int y, int newColor) {
31-
32-
image[x][y] = newColor;
33-
34-
}
35-
36-
28+
public static void putPixel(int[][] image, int x, int y, int newColor) {
29+
image[x][y] = newColor;
30+
}
31+
3732
/**
3833
* Fill the 2D image with new color
3934
*
@@ -44,26 +39,29 @@ public static void putPixel(int[][] image, int x, int y, int newColor) {
4439
* @param oldColor The old color which is to be replaced in the image
4540
* @return
4641
*/
47-
public static void floodFill(int[][] image, int x, int y, int newColor, int oldColor) {
48-
49-
if(x < 0 || x >= image.length) return;
50-
if(y < 0 || y >= image[x].length) return;
51-
if(getPixel(image, x, y) != oldColor) return;
52-
53-
putPixel(image, x, y, newColor);
54-
55-
/* Recursively check for horizontally & vertically adjacent coordinates */
56-
floodFill(image, x + 1, y, newColor, oldColor);
57-
floodFill(image, x - 1, y, newColor, oldColor);
58-
floodFill(image, x, y + 1, newColor, oldColor);
59-
floodFill(image, x, y - 1, newColor, oldColor);
42+
public static void floodFill(
43+
int[][] image,
44+
int x,
45+
int y,
46+
int newColor,
47+
int oldColor
48+
) {
49+
if (x < 0 || x >= image.length) return;
50+
if (y < 0 || y >= image[x].length) return;
51+
if (getPixel(image, x, y) != oldColor) return;
6052

61-
/* Recursively check for diagonally adjacent coordinates */
62-
floodFill(image, x + 1, y - 1, newColor, oldColor);
63-
floodFill(image, x - 1, y + 1, newColor, oldColor);
64-
floodFill(image, x + 1, y + 1, newColor, oldColor);
65-
floodFill(image, x - 1, y - 1, newColor, oldColor);
53+
putPixel(image, x, y, newColor);
6654

67-
}
55+
/* Recursively check for horizontally & vertically adjacent coordinates */
56+
floodFill(image, x + 1, y, newColor, oldColor);
57+
floodFill(image, x - 1, y, newColor, oldColor);
58+
floodFill(image, x, y + 1, newColor, oldColor);
59+
floodFill(image, x, y - 1, newColor, oldColor);
6860

69-
}
61+
/* Recursively check for diagonally adjacent coordinates */
62+
floodFill(image, x + 1, y - 1, newColor, oldColor);
63+
floodFill(image, x - 1, y + 1, newColor, oldColor);
64+
floodFill(image, x + 1, y + 1, newColor, oldColor);
65+
floodFill(image, x - 1, y - 1, newColor, oldColor);
66+
}
67+
}

src/main/java/com/thealgorithms/backtracking/KnightsTour.java

+25-11
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@
2525
*/
2626
public class KnightsTour {
2727

28-
private final static int base = 12;
29-
private final static int[][] moves = {{1, -2}, {2, -1}, {2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}}; // Possible moves by knight on chess
30-
private static int[][] grid; // chess grid
31-
private static int total; // total squares in chess
28+
private static final int base = 12;
29+
private static final int[][] moves = {
30+
{ 1, -2 },
31+
{ 2, -1 },
32+
{ 2, 1 },
33+
{ 1, 2 },
34+
{ -1, 2 },
35+
{ -2, 1 },
36+
{ -2, -1 },
37+
{ -1, -2 },
38+
}; // Possible moves by knight on chess
39+
private static int[][] grid; // chess grid
40+
private static int total; // total squares in chess
3241

3342
public static void main(String[] args) {
3443
grid = new int[base][base];
@@ -52,7 +61,6 @@ public static void main(String[] args) {
5261
} else {
5362
System.out.println("no result");
5463
}
55-
5664
}
5765

5866
// Return True when solvable
@@ -67,17 +75,23 @@ private static boolean solve(int row, int column, int count) {
6775
return false;
6876
}
6977

70-
Collections.sort(neighbor, new Comparator<int[]>() {
71-
public int compare(int[] a, int[] b) {
72-
return a[2] - b[2];
78+
Collections.sort(
79+
neighbor,
80+
new Comparator<int[]>() {
81+
public int compare(int[] a, int[] b) {
82+
return a[2] - b[2];
83+
}
7384
}
74-
});
85+
);
7586

7687
for (int[] nb : neighbor) {
7788
row = nb[0];
7889
column = nb[1];
7990
grid[row][column] = count;
80-
if (!orphanDetected(count, row, column) && solve(row, column, count + 1)) {
91+
if (
92+
!orphanDetected(count, row, column) &&
93+
solve(row, column, count + 1)
94+
) {
8195
return true;
8296
}
8397
grid[row][column] = 0;
@@ -95,7 +109,7 @@ private static List<int[]> neighbors(int row, int column) {
95109
int y = m[1];
96110
if (grid[row + y][column + x] == 0) {
97111
int num = countNeighbors(row + y, column + x);
98-
neighbour.add(new int[]{row + y, column + x, num});
112+
neighbour.add(new int[] { row + y, column + x, num });
99113
}
100114
}
101115
return neighbour;

0 commit comments

Comments
 (0)