Skip to content

Commit 22eacb8

Browse files
fix: adds checkstyle corrections
1 parent 386f436 commit 22eacb8

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public java.util.List<Edge> computeMST(Graph graph) {
5454
mst.add(e);
5555
ds.union(rootA, rootB);
5656

57-
if (mst.size() == graph.numberOfVertices - 1) break;
57+
if (mst.size() == graph.numberOfVertices - 1) {
58+
break;
59+
}
5860
}
5961
}
6062

@@ -78,9 +80,15 @@ public Edge(int source, int target, int weight) {
7880
this.weight = weight;
7981
}
8082

81-
public int getSource() { return source; }
82-
public int getTarget() { return target; }
83-
public int getWeight() { return weight; }
83+
public int getSource() {
84+
return source;
85+
}
86+
public int getTarget() {
87+
return target;
88+
}
89+
public int getWeight() {
90+
return weight;
91+
}
8492

8593
@Override
8694
public int compareTo(Edge o) {
@@ -107,8 +115,7 @@ public Graph(int numberOfVertices) {
107115
* Adds an undirected edge to the graph.
108116
*/
109117
public void addEdge(int source, int target, int weight) {
110-
if (source < 0 || source >= numberOfVertices ||
111-
target < 0 || target >= numberOfVertices) {
118+
if (source < 0 || source >= numberOfVertices || target < 0 || target >= numberOfVertices) {
112119
throw new IndexOutOfBoundsException("Vertex index out of range.");
113120
}
114121

@@ -127,7 +134,9 @@ private static final class DisjointSet {
127134
public DisjointSet(int size) {
128135
parent = new int[size];
129136
rank = new int[size];
130-
for (int i = 0; i < size; i++) parent[i] = i;
137+
for (int i = 0; i < size; i++) {
138+
parent[i] = i;
139+
}
131140
}
132141

133142
public int find(int x) {
@@ -140,8 +149,9 @@ public int find(int x) {
140149
public void union(int a, int b) {
141150
int ra = find(a);
142151
int rb = find(b);
143-
if (ra == rb) return;
144-
152+
if (ra == rb) {
153+
return;
154+
}
145155
if (rank[ra] < rank[rb]) {
146156
parent[ra] = rb;
147157
} else if (rank[ra] > rank[rb]) {
@@ -152,5 +162,4 @@ public void union(int a, int b) {
152162
}
153163
}
154164
}
155-
}
156-
165+
}

src/test/java/com/thealgorithms/greedyalgorithms/KruskalAlgorithmTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import org.junit.jupiter.api.Test;
44
import org.junit.jupiter.api.DisplayName;
5-
65
import java.util.List;
7-
8-
import static org.junit.jupiter.api.Assertions.*;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
9+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
910

1011
/**
1112
* Unit tests for the KruskalAlgorithm implementation.
@@ -70,7 +71,7 @@ void testParallelEdges() {
7071
KruskalAlgorithm.Graph graph = new KruskalAlgorithm.Graph(3);
7172

7273
graph.addEdge(0, 1, 10);
73-
graph.addEdge(0, 1, 3); // cheaper parallel edge
74+
graph.addEdge(0, 1, 3); // cheaper parallel edge
7475
graph.addEdge(1, 2, 4);
7576

7677
KruskalAlgorithm algo = new KruskalAlgorithm();

0 commit comments

Comments
 (0)