Skip to content

Commit ef0c8eb

Browse files
committed
style: Apply Java code style guidelines
1 parent 6010566 commit ef0c8eb

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

src/main/java/com/thealgorithms/graph/DisjointSet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ public class DisjointSet {
6060
* @throws IllegalArgumentException if size is negative
6161
*/
6262
public DisjointSet(int size) {
63-
if (size < 0)
63+
if (size < 0) {
6464
throw new IllegalArgumentException("Size must be non-negative");
65+
}
6566
this.size = size;
6667
this.numSets = size;
6768
parent = new int[size];
@@ -181,4 +182,4 @@ public List<Integer> getSetMembers(int x) {
181182
}
182183
return members;
183184
}
184-
}
185+
}

src/main/java/com/thealgorithms/graph/TopologicalSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ public static List<Integer> sortAndDetectCycle(int numVertices, List<int[]> edge
124124
}
125125
return sorted;
126126
}
127-
}
127+
}

src/test/java/com/thealgorithms/graph/DisjointSetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ void connectedComponents() {
121121
assertFalse(ds.connected(0, 3));
122122
assertFalse(ds.connected(2, 4));
123123
}
124-
}
124+
}

src/test/java/com/thealgorithms/graph/TopologicalSortTest.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ class TopologicalSortTest {
1616
@Test
1717
@DisplayName("Simple DAG returns correct ordering")
1818
void simpleDAG() {
19-
List<int[]> edges = Arrays.asList(
20-
new int[] { 0, 1 },
21-
new int[] { 0, 2 },
22-
new int[] { 1, 3 },
19+
List<int[]> edges = Arrays.asList(new int[] { 0, 1 }, new int[] { 0, 2 }, new int[] { 1, 3 },
2320
new int[] { 2, 3 });
2421
int[] result = TopologicalSort.sort(4, edges);
2522
assertArrayEquals(new int[] { 0, 1, 2, 3 }, result);
@@ -38,10 +35,7 @@ void emptyGraph() {
3835
@Test
3936
@DisplayName("Graph with cycle returns null")
4037
void graphWithCycle() {
41-
List<int[]> edges = Arrays.asList(
42-
new int[] { 0, 1 },
43-
new int[] { 1, 2 },
44-
new int[] { 2, 0 });
38+
List<int[]> edges = Arrays.asList(new int[] { 0, 1 }, new int[] { 1, 2 }, new int[] { 2, 0 });
4539
assertNull(TopologicalSort.sort(3, edges));
4640
}
4741

@@ -50,8 +44,7 @@ void graphWithCycle() {
5044
void coursePrerequisites() {
5145
// Example: Course prerequisites where edge [a,b] means course a must be taken
5246
// before b
53-
List<int[]> edges = Arrays.asList(
54-
new int[] { 1, 0 }, // Calculus I -> Calculus II
47+
List<int[]> edges = Arrays.asList(new int[] { 1, 0 }, // Calculus I -> Calculus II
5548
new int[] { 2, 0 }, // Linear Algebra -> Calculus II
5649
new int[] { 1, 3 }, // Calculus I -> Differential Equations
5750
new int[] { 2, 3 } // Linear Algebra -> Differential Equations
@@ -69,8 +62,7 @@ void coursePrerequisites() {
6962
@Test
7063
@DisplayName("Invalid vertex throws exception")
7164
void invalidVertex() {
72-
List<int[]> edges = Arrays.asList(
73-
new int[] { 0, 5 } // Vertex 5 is invalid for a graph with 3 vertices
65+
List<int[]> edges = Arrays.asList(new int[] { 0, 5 } // Vertex 5 is invalid for a graph with 3 vertices
7466
);
7567
assertThrows(IllegalArgumentException.class, () -> TopologicalSort.sort(3, edges));
7668
}
@@ -84,11 +76,7 @@ void nullEdgeList() {
8476
@Test
8577
@DisplayName("sortAndDetectCycle throws exception for cyclic graph")
8678
void detectCycleThrowsException() {
87-
List<int[]> edges = Arrays.asList(
88-
new int[] { 0, 1 },
89-
new int[] { 1, 2 },
90-
new int[] { 2, 0 });
91-
assertThrows(IllegalArgumentException.class,
92-
() -> TopologicalSort.sortAndDetectCycle(3, edges));
79+
List<int[]> edges = Arrays.asList(new int[] { 0, 1 }, new int[] { 1, 2 }, new int[] { 2, 0 });
80+
assertThrows(IllegalArgumentException.class, () -> TopologicalSort.sortAndDetectCycle(3, edges));
9381
}
94-
}
82+
}

0 commit comments

Comments
 (0)