Skip to content

Commit 87b17e0

Browse files
samuelfacSamuel Facchinello
andauthored
style: enable NeedBraces in checkstyle (#5227)
* enable style NeedBraces * style: enable NeedBraces in checkstyle --------- Co-authored-by: Samuel Facchinello <samuel.facchinello@piksel.com>
1 parent 51fcc66 commit 87b17e0

File tree

68 files changed

+627
-259
lines changed

Some content is hidden

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

68 files changed

+627
-259
lines changed

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<!-- TODO <module name="AvoidNestedBlocks"/> -->
156156
<!-- TODO <module name="EmptyBlock"/> -->
157157
<!-- TODO <module name="LeftCurly"/> -->
158-
<!-- TODO <module name="NeedBraces"/> -->
158+
<module name="NeedBraces"/>
159159
<!-- TODO <module name="RightCurly"/> -->
160160

161161
<!-- Checks for common coding problems -->

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public static <T> List<TreeSet<T>> combination(T[] arr, int n) {
4343
* @param <T> the type of elements in the array.
4444
*/
4545
private static <T> void backtracking(T[] arr, int index, TreeSet<T> currSet, List<TreeSet<T>> result) {
46-
if (index + length - currSet.size() > arr.length) return;
46+
if (index + length - currSet.size() > arr.length) {
47+
return;
48+
}
4749
if (length - 1 == currSet.size()) {
4850
for (int i = index; i < arr.length; i++) {
4951
currSet.add(arr[i]);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ static int possiblePaint(ArrayList<Node> nodes, int n, int m) {
5959
// If number of colors used exceeds m,
6060
// return 0
6161
maxColors = Math.max(maxColors, Math.max(nodes.get(top).color, nodes.get(it).color));
62-
if (maxColors > m) return 0;
62+
if (maxColors > m) {
63+
return 0;
64+
}
6365

6466
// If the adjacent node is not visited,
6567
// mark it visited and push it in queue

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ private boolean doDFS(int x, int y, int nextIdx) {
5151
int yi = y + dy[i];
5252
if (isValid(xi, yi) && board[xi][yi] == word.charAt(nextIdx) && !visited[xi][yi]) {
5353
boolean exists = doDFS(xi, yi, nextIdx + 1);
54-
if (exists) return true;
54+
if (exists) {
55+
return true;
56+
}
5557
}
5658
}
5759
visited[x][y] = false;
@@ -66,7 +68,9 @@ public boolean exist(char[][] board, String word) {
6668
if (board[i][j] == word.charAt(0)) {
6769
visited = new boolean[board.length][board[0].length];
6870
boolean exists = doDFS(i, j, 1);
69-
if (exists) return true;
71+
if (exists) {
72+
return true;
73+
}
7074
}
7175
}
7276
}

src/main/java/com/thealgorithms/ciphers/Blowfish.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,9 @@ private String hexToBin(String hex) {
11041104
private String binToHex(String binary) {
11051105
long num = Long.parseUnsignedLong(binary, 2);
11061106
String hex = Long.toHexString(num);
1107-
while (hex.length() < (binary.length() / 4)) hex = "0" + hex;
1107+
while (hex.length() < (binary.length() / 4)) {
1108+
hex = "0" + hex;
1109+
}
11081110

11091111
return hex;
11101112
}
@@ -1120,7 +1122,9 @@ private String xor(String a, String b) {
11201122
a = hexToBin(a);
11211123
b = hexToBin(b);
11221124
String ans = "";
1123-
for (int i = 0; i < a.length(); i++) ans += (char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0');
1125+
for (int i = 0; i < a.length(); i++) {
1126+
ans += (char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0');
1127+
}
11241128
ans = binToHex(ans);
11251129
return ans;
11261130
}
@@ -1202,7 +1206,9 @@ String encrypt(String plainText, String key) {
12021206
// generating key
12031207
keyGenerate(key);
12041208

1205-
for (int i = 0; i < 16; i++) plainText = round(i, plainText);
1209+
for (int i = 0; i < 16; i++) {
1210+
plainText = round(i, plainText);
1211+
}
12061212

12071213
// postprocessing
12081214
String right = plainText.substring(0, 8);
@@ -1224,7 +1230,9 @@ String decrypt(String cipherText, String key) {
12241230
// generating key
12251231
keyGenerate(key);
12261232

1227-
for (int i = 17; i > 1; i--) cipherText = round(i, cipherText);
1233+
for (int i = 17; i > 1; i--) {
1234+
cipherText = round(i, cipherText);
1235+
}
12281236

12291237
// postprocessing
12301238
String right = cipherText.substring(0, 8);

src/main/java/com/thealgorithms/ciphers/a5/A5KeyStreamGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public void reInitialize() {
3131
}
3232

3333
public BitSet getNextKeyStream() {
34-
for (int cycle = 1; cycle <= INITIAL_CLOCKING_CYCLES; ++cycle) this.clock();
34+
for (int cycle = 1; cycle <= INITIAL_CLOCKING_CYCLES; ++cycle) {
35+
this.clock();
36+
}
3537

3638
BitSet result = new BitSet(KEY_STREAM_LENGTH);
3739
for (int cycle = 1; cycle <= KEY_STREAM_LENGTH; ++cycle) {

src/main/java/com/thealgorithms/ciphers/a5/CompositeLFSR.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public boolean clock() {
1919
boolean result = false;
2020
for (var register : registers) {
2121
result ^= register.getLastBit();
22-
if (register.getClockBit() == majorityBit) register.clock();
22+
if (register.getClockBit() == majorityBit) {
23+
register.clock();
24+
}
2325
}
2426
return result;
2527
}

src/main/java/com/thealgorithms/datastructures/buffers/CircularBuffer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ public boolean isFull() {
2424
}
2525

2626
public Item get() {
27-
if (isEmpty()) return null;
27+
if (isEmpty()) {
28+
return null;
29+
}
2830

2931
Item item = buffer[getPointer.getAndIncrement()];
3032
size.decrementAndGet();
3133
return item;
3234
}
3335

3436
public boolean put(Item item) {
35-
if (isFull()) return false;
37+
if (isFull()) {
38+
return false;
39+
}
3640

3741
buffer[putPointer.getAndIncrement()] = item;
3842
size.incrementAndGet();
@@ -49,7 +53,9 @@ private static class CircularPointer {
4953
}
5054

5155
public int getAndIncrement() {
52-
if (pointer == max) pointer = 0;
56+
if (pointer == max) {
57+
pointer = 0;
58+
}
5359
int tmp = pointer;
5460
pointer++;
5561
return tmp;

src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public void findStronglyConnectedComponents(int v, List<List<Integer>> transpose
127127
private void dfs(int node, int[] vis, List<List<Integer>> list) {
128128
vis[node] = 1;
129129
for (Integer neighbour : list.get(node)) {
130-
if (vis[neighbour] == 0) dfs(neighbour, vis, list);
130+
if (vis[neighbour] == 0) {
131+
dfs(neighbour, vis, list);
132+
}
131133
}
132134
stack.push(node);
133135
}
@@ -136,7 +138,9 @@ private void dfs(int node, int[] vis, List<List<Integer>> list) {
136138
private void dfs2(int node, int[] vis, List<List<Integer>> list) {
137139
vis[node] = 1;
138140
for (Integer neighbour : list.get(node)) {
139-
if (vis[neighbour] == 0) dfs2(neighbour, vis, list);
141+
if (vis[neighbour] == 0) {
142+
dfs2(neighbour, vis, list);
143+
}
140144
}
141145
scc.add(node);
142146
}

src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>
8282
Stack<Integer> st = new Stack<Integer>();
8383

8484
for (int i = 0; i < v; i++) {
85-
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
85+
if (insertionTime[i] == -1) {
86+
stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
87+
}
8688
}
8789

8890
return sccList;

0 commit comments

Comments
 (0)