Skip to content

Commit d2ddec5

Browse files
authored
style: include NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION (#5149)
* style: use `assertFalse` and `assertTrue` * style: include `NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION`
1 parent d3bb691 commit d2ddec5

File tree

11 files changed

+47
-43
lines changed

11 files changed

+47
-43
lines changed

spotbugs-exclude.xml

-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@
126126
<Match>
127127
<Bug pattern="OCP_OVERLY_CONCRETE_PARAMETER" />
128128
</Match>
129-
<Match>
130-
<Bug pattern="NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION" />
131-
</Match>
132129
<Match>
133130
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
134131
</Match>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public boolean clock() {
2626

2727
private boolean getMajorityBit() {
2828
Map<Boolean, Integer> bitCount = new TreeMap<>();
29-
bitCount.put(false, 0);
30-
bitCount.put(true, 0);
29+
bitCount.put(Boolean.FALSE, 0);
30+
bitCount.put(Boolean.TRUE, 0);
3131

3232
registers.forEach(lfsr -> bitCount.put(lfsr.getClockBit(), bitCount.get(lfsr.getClockBit()) + 1));
33-
return bitCount.get(false) <= bitCount.get(true);
33+
return bitCount.get(Boolean.FALSE) <= bitCount.get(Boolean.TRUE);
3434
}
3535
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ void dijkstra(int[][] graph, int src) {
3434

3535
for (int i = 0; i < k; i++) {
3636
dist[i] = Integer.MAX_VALUE;
37-
Set[i] = false;
37+
Set[i] = Boolean.FALSE;
3838
}
3939

4040
dist[src] = 0;
4141

4242
for (int c = 0; c < k - 1; c++) {
4343
int u = minDist(dist, Set);
4444

45-
Set[u] = true;
45+
Set[u] = Boolean.TRUE;
4646

4747
for (int v = 0; v < k; v++) {
4848
if (!Set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void primMST(int[][] graph) {
5050
// Initialize all keys as INFINITE
5151
for (int i = 0; i < V; i++) {
5252
key[i] = Integer.MAX_VALUE;
53-
mstSet[i] = false;
53+
mstSet[i] = Boolean.FALSE;
5454
}
5555

5656
// Always include first 1st vertex in MST.
@@ -65,7 +65,7 @@ void primMST(int[][] graph) {
6565
int u = minKey(key, mstSet);
6666

6767
// Add the picked vertex to the MST Set
68-
mstSet[u] = true;
68+
mstSet[u] = Boolean.TRUE;
6969

7070
// Update key value and parent index of the adjacent
7171
// vertices of the picked vertex. Consider only those

src/main/java/com/thealgorithms/greedyalgorithms/JobSequencing.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public int compareTo(Job otherJob) {
3131
// Function to print the job sequence
3232
public static String findJobSequence(ArrayList<Job> jobs, int size) {
3333
Boolean[] slots = new Boolean[size];
34-
Arrays.fill(slots, false);
34+
Arrays.fill(slots, Boolean.FALSE);
3535

3636
int[] result = new int[size];
3737

@@ -40,7 +40,7 @@ public static String findJobSequence(ArrayList<Job> jobs, int size) {
4040
for (int j = jobs.get(i).deadline - 1; j >= 0; j--) {
4141
if (!slots[j]) {
4242
result[j] = i;
43-
slots[j] = true;
43+
slots[j] = Boolean.TRUE;
4444
break;
4545
}
4646
}

src/main/java/com/thealgorithms/sorts/CircleSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private <T extends Comparable<T>> Boolean doSort(T[] array, int left, int right)
2525
boolean swapped = false;
2626

2727
if (left == right) {
28-
return false;
28+
return Boolean.FALSE;
2929
}
3030

3131
int low = left;
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.thealgorithms.bitmanipulation;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import org.junit.jupiter.api.Test;
67

78
class IsEvenTest {
89
@Test
910
void testIsEven() {
10-
assertEquals(true, IsEven.isEven(2));
11-
assertEquals(true, IsEven.isEven(-12));
12-
assertEquals(false, IsEven.isEven(21));
11+
assertTrue(IsEven.isEven(0));
12+
assertTrue(IsEven.isEven(2));
13+
assertTrue(IsEven.isEven(-12));
14+
assertFalse(IsEven.isEven(21));
15+
assertFalse(IsEven.isEven(-1));
1316
}
1417
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package com.thealgorithms.dynamicprogramming;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import org.junit.jupiter.api.Test;
67

78
class SumOfSubsetTest {
89

910
@Test
1011
void basicCheck() {
11-
assertEquals(false, SumOfSubset.subsetSum(new int[] {1, 2, 7, 10, 9}, 4, 14));
12-
assertEquals(false, SumOfSubset.subsetSum(new int[] {2, 15, 1, 6, 7}, 4, 4));
13-
assertEquals(true, SumOfSubset.subsetSum(new int[] {7, 3, 2, 5, 8}, 4, 14));
14-
assertEquals(true, SumOfSubset.subsetSum(new int[] {4, 3, 2, 1}, 3, 5));
15-
assertEquals(true, SumOfSubset.subsetSum(new int[] {1, 7, 2, 9, 10}, 4, 13));
12+
assertFalse(SumOfSubset.subsetSum(new int[] {1, 2, 7, 10, 9}, 4, 14));
13+
assertFalse(SumOfSubset.subsetSum(new int[] {2, 15, 1, 6, 7}, 4, 4));
14+
assertTrue(SumOfSubset.subsetSum(new int[] {7, 3, 2, 5, 8}, 4, 14));
15+
assertTrue(SumOfSubset.subsetSum(new int[] {4, 3, 2, 1}, 3, 5));
16+
assertTrue(SumOfSubset.subsetSum(new int[] {1, 7, 2, 9, 10}, 4, 13));
1617
}
1718
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package com.thealgorithms.maths;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import org.junit.jupiter.api.Test;
67

78
public class PythagoreanTripleTest {
89

910
@Test
1011
public void Testpythagoreantriple() {
11-
assertEquals(true, PythagoreanTriple.isPythagTriple(3, 4, 5));
12-
assertEquals(true, PythagoreanTriple.isPythagTriple(6, 8, 10));
13-
assertEquals(true, PythagoreanTriple.isPythagTriple(9, 12, 15));
14-
assertEquals(true, PythagoreanTriple.isPythagTriple(12, 16, 20));
15-
assertEquals(true, PythagoreanTriple.isPythagTriple(15, 20, 25));
16-
assertEquals(true, PythagoreanTriple.isPythagTriple(18, 24, 30));
17-
assertEquals(false, PythagoreanTriple.isPythagTriple(5, 20, 30));
18-
assertEquals(false, PythagoreanTriple.isPythagTriple(6, 8, 100));
19-
assertEquals(false, PythagoreanTriple.isPythagTriple(-2, -2, 2));
12+
assertTrue(PythagoreanTriple.isPythagTriple(3, 4, 5));
13+
assertTrue(PythagoreanTriple.isPythagTriple(6, 8, 10));
14+
assertTrue(PythagoreanTriple.isPythagTriple(9, 12, 15));
15+
assertTrue(PythagoreanTriple.isPythagTriple(12, 16, 20));
16+
assertTrue(PythagoreanTriple.isPythagTriple(15, 20, 25));
17+
assertTrue(PythagoreanTriple.isPythagTriple(18, 24, 30));
18+
assertFalse(PythagoreanTriple.isPythagTriple(5, 20, 30));
19+
assertFalse(PythagoreanTriple.isPythagTriple(6, 8, 100));
20+
assertFalse(PythagoreanTriple.isPythagTriple(-2, -2, 2));
2021
}
2122
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thealgorithms.others;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import org.junit.jupiter.api.Test;
67

@@ -10,34 +11,34 @@ public class TwoPointersTest {
1011
void twoPointersFirstTestCase() {
1112
int[] arr = {2, 6, 9, 22, 121};
1213
int key = 28;
13-
assertEquals(true, TwoPointers.isPairedSum(arr, key));
14+
assertTrue(TwoPointers.isPairedSum(arr, key));
1415
}
1516

1617
@Test
1718
void twoPointersSecondTestCase() {
1819
int[] arr = {-1, -12, 12, 0, 8};
1920
int key = 0;
20-
assertEquals(true, TwoPointers.isPairedSum(arr, key));
21+
assertTrue(TwoPointers.isPairedSum(arr, key));
2122
}
2223

2324
@Test
2425
void twoPointersThirdTestCase() {
2526
int[] arr = {12, 35, 12, 152, 0};
2627
int key = 13;
27-
assertEquals(false, TwoPointers.isPairedSum(arr, key));
28+
assertFalse(TwoPointers.isPairedSum(arr, key));
2829
}
2930

3031
@Test
3132
void twoPointersFourthTestCase() {
3233
int[] arr = {-2, 5, -1, 52, 31};
3334
int key = -3;
34-
assertEquals(true, TwoPointers.isPairedSum(arr, key));
35+
assertTrue(TwoPointers.isPairedSum(arr, key));
3536
}
3637

3738
@Test
3839
void twoPointersFiftiethTestCase() {
3940
int[] arr = {25, 1, 0, 61, 21};
4041
int key = 12;
41-
assertEquals(false, TwoPointers.isPairedSum(arr, key));
42+
assertFalse(TwoPointers.isPairedSum(arr, key));
4243
}
4344
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
package com.thealgorithms.strings;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import org.junit.jupiter.api.Test;
67

78
public class ValidParenthesesTest {
89

910
@Test
1011
void testOne() {
11-
assertEquals(true, ValidParentheses.isValid("()"));
12+
assertTrue(ValidParentheses.isValid("()"));
1213
}
1314

1415
@Test
1516
void testTwo() {
16-
assertEquals(true, ValidParentheses.isValid("()[]{}"));
17+
assertTrue(ValidParentheses.isValid("()[]{}"));
1718
}
1819

1920
@Test
2021
void testThree() {
21-
assertEquals(false, ValidParentheses.isValid("(]"));
22+
assertFalse(ValidParentheses.isValid("(]"));
2223
}
2324
}

0 commit comments

Comments
 (0)