Skip to content

Commit 6d19b7e

Browse files
authored
Restore Code Formatting Checks (williamfiset#383)
* Replace Sherter with Spotless * Update CI settings to use Spotless * Move test runner to JDK 11 * Apply Google Java format to all existing files
1 parent 04d5d2f commit 6d19b7e

File tree

70 files changed

+260
-246
lines changed

Some content is hidden

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

70 files changed

+260
-246
lines changed

.github/workflows/gradle.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v3
22-
- name: Set up JDK 1.8
22+
- name: Set up JDK 11
2323
uses: actions/setup-java@v3
2424
with:
25-
java-version: 8
25+
java-version: 11
2626
distribution: 'temurin'
2727
cache: 'gradle'
2828
- name: Validate Gradle Wrapper
@@ -46,25 +46,21 @@ jobs:
4646

4747
steps:
4848
- uses: actions/checkout@v3
49-
- name: Set up JDK 1.8
49+
- name: Set up JDK 11
5050
uses: actions/setup-java@v3
5151
with:
52-
java-version: 8
52+
java-version: 11
5353
distribution: 'temurin'
5454
cache: 'gradle'
5555
- name: Validate Gradle Wrapper
5656
uses: gradle/wrapper-validation-action@v1
57-
# The google formatter is broken atm. Disabling for now.
5857
- name: Verify all Java files are formatted correctly according to the Google Java Style Guide using Gradle
5958
uses: gradle/gradle-build-action@v2
60-
if: ${{ false }}
6159
id: verifygooglejavaformat
6260
with:
6361
gradle-version: wrapper
64-
arguments: verifyGoogleJavaFormat
62+
arguments: spotlessJavaCheck
6563
- name: Create summary if format check failed
66-
if: ${{ false }}
67-
# Enable this when Google Java formatter is enabled
68-
# if: ${{ steps.verifygooglejavaformat.outcome == 'failure' }}
64+
if: ${{ steps.verifygooglejavaformat.outcome == 'failure' }}
6965
run: |
70-
echo "Run the command `./gradlew goJF` to fix Java formatting." >> $GITHUB_STEP_SUMMARY
66+
echo "Run the command `./gradlew spotlessApply` to fix Java formatting." >> $GITHUB_STEP_SUMMARY

build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ buildscript {
77
}
88

99
plugins {
10-
// https://github.com/sherter/google-java-format-gradle-plugin
11-
// id "com.github.sherter.google-java-format" version "0.9"
10+
// https://github.com/diffplug/spotless
11+
id("com.diffplug.spotless") version "6.18.0"
1212
}
1313

1414
apply plugin: 'java'
1515
apply plugin: 'application'
16-
// Formatting tool doesn't support Java 17+
17-
// apply plugin: "com.github.sherter.google-java-format"
1816

1917
mainClassName = findProperty("main") ?: "com.williamfiset.algorithms.${findProperty("algorithm") ?: 'missingPackage.missingClass'}"
2018

@@ -44,6 +42,12 @@ dependencies {
4442
testImplementation "org.mockito:mockito-core:5.+"
4543
}
4644

45+
spotless {
46+
java {
47+
googleJavaFormat()
48+
}
49+
}
50+
4751
test {
4852
dependsOn cleanTest
4953
testLogging.showStandardStreams = true

src/main/java/com/williamfiset/algorithms/datastructures/stack/ArrayStack.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.Arrays;
44
import java.util.EmptyStackException;
55

6-
/** @author liujingkun */
6+
/**
7+
* @author liujingkun
8+
*/
79
public class ArrayStack<T> implements Stack<T> {
810
private int size;
911
private int capacity;

src/main/java/com/williamfiset/algorithms/datastructures/stack/Stack.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.williamfiset.algorithms.datastructures.stack;
22

3-
/** @author liujingkun */
3+
/**
4+
* @author liujingkun
5+
*/
46
public interface Stack<T> {
57
// return the number of elements in the stack
68
public int size();

src/main/java/com/williamfiset/algorithms/graphtheory/ConnectedComponentsDfsSolverAdjacencyList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public class ConnectedComponentsDfsSolverAdjacencyList {
1919
private boolean[] visited;
2020
private List<List<Integer>> graph;
2121

22-
/** @param graph - An undirected graph as an adjacency list. */
22+
/**
23+
* @param graph - An undirected graph as an adjacency list.
24+
*/
2325
public ConnectedComponentsDfsSolverAdjacencyList(List<List<Integer>> graph) {
2426
if (graph == null) throw new NullPointerException();
2527
this.n = graph.size();

src/main/java/com/williamfiset/algorithms/graphtheory/networkflow/NetworkFlowSolverBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/** @author William Fiset, william.alexandre.fiset@gmail.com */
1+
/**
2+
* @author William Fiset, william.alexandre.fiset@gmail.com
3+
*/
24
package com.williamfiset.algorithms.graphtheory.networkflow;
35

46
import java.util.ArrayList;

src/main/java/com/williamfiset/algorithms/graphtheory/treealgorithms/LowestCommonAncestor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class TreeNode {
1414

1515
// Useful constructor for root node.
1616
public TreeNode(int id) {
17-
this(id, /*parent=*/ null);
17+
this(id, /* parent= */ null);
1818
}
1919

2020
public TreeNode(int id, TreeNode parent) {

src/main/java/com/williamfiset/algorithms/graphtheory/treealgorithms/LowestCommonAncestorEulerTour.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static class TreeNode {
9494

9595
// Useful constructor for root node.
9696
public TreeNode(int index) {
97-
this(index, /*parent=*/ null);
97+
this(index, /* parent= */ null);
9898
}
9999

100100
public TreeNode(int index, TreeNode parent) {
@@ -192,7 +192,7 @@ private void setup(TreeNode root) {
192192
last = new int[n];
193193

194194
// Do depth first search to construct Euler tour.
195-
dfs(root, /*depth=*/ 0);
195+
dfs(root, /* depth= */ 0);
196196

197197
// Initialize and build sparse table on the `nodeDepth` array which will
198198
// allow us to index into the `nodeOrder` array and return the LCA.

src/main/java/com/williamfiset/algorithms/graphtheory/treealgorithms/RootingTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class TreeNode {
1919

2020
// Useful constructor for root node.
2121
public TreeNode(int id) {
22-
this(id, /*parent=*/ null);
22+
this(id, /* parent= */ null);
2323
}
2424

2525
public TreeNode(int id, TreeNode parent) {

src/main/java/com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphism.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class TreeNode {
1919

2020
// Useful constructor for root node.
2121
public TreeNode(int id) {
22-
this(id, /*parent=*/ null);
22+
this(id, /* parent= */ null);
2323
}
2424

2525
public TreeNode(int id, TreeNode parent) {

src/main/java/com/williamfiset/algorithms/math/NChooseRModPrime.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/** @author Rohit Mazumder, mazumder.rohit7@gmai.com */
1+
/**
2+
* @author Rohit Mazumder, mazumder.rohit7@gmai.com
3+
*/
24
package com.williamfiset.algorithms.math;
35

46
import java.math.BigInteger;

src/test/java/com/williamfiset/algorithms/datastructures/balancedtree/AVLTreeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Collections;
77
import java.util.List;
88
import java.util.TreeSet;
9-
109
import org.junit.jupiter.api.*;
1110

1211
public class AVLTreeTest {

src/test/java/com/williamfiset/algorithms/datastructures/balancedtree/RedBlackTreeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import java.util.*;
7-
87
import org.junit.jupiter.api.*;
98

109
public class RedBlackTreeTest {

src/test/java/com/williamfiset/algorithms/datastructures/balancedtree/TreapTreeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Collections;
88
import java.util.List;
99
import java.util.TreeSet;
10-
1110
import org.junit.jupiter.api.*;
1211

1312
public class TreapTreeTest {

src/test/java/com/williamfiset/algorithms/datastructures/binarysearchtree/BinarySearchTreeTest.java

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Deque;
1111
import java.util.Iterator;
1212
import java.util.List;
13-
1413
import org.junit.jupiter.api.*;
1514

1615
class TestTreeNode {
@@ -214,12 +213,14 @@ public void concurrentModificationErrorPreOrder() {
214213

215214
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.PRE_ORDER);
216215

217-
assertThrows(ConcurrentModificationException.class, () -> {
218-
while (iter.hasNext()) {
219-
bst.add(0);
220-
iter.next();
221-
}
222-
});
216+
assertThrows(
217+
ConcurrentModificationException.class,
218+
() -> {
219+
while (iter.hasNext()) {
220+
bst.add(0);
221+
iter.next();
222+
}
223+
});
223224
}
224225

225226
@Test
@@ -233,12 +234,14 @@ public void concurrentModificationErrorInOrderOrder() {
233234

234235
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.IN_ORDER);
235236

236-
assertThrows(ConcurrentModificationException.class, () -> {
237-
while (iter.hasNext()) {
238-
bst.add(0);
239-
iter.next();
240-
}
241-
});
237+
assertThrows(
238+
ConcurrentModificationException.class,
239+
() -> {
240+
while (iter.hasNext()) {
241+
bst.add(0);
242+
iter.next();
243+
}
244+
});
242245
}
243246

244247
@Test
@@ -252,12 +255,14 @@ public void concurrentModificationErrorPostOrder() {
252255

253256
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.POST_ORDER);
254257

255-
assertThrows(ConcurrentModificationException.class, () -> {
256-
while (iter.hasNext()) {
257-
bst.add(0);
258-
iter.next();
259-
}
260-
});
258+
assertThrows(
259+
ConcurrentModificationException.class,
260+
() -> {
261+
while (iter.hasNext()) {
262+
bst.add(0);
263+
iter.next();
264+
}
265+
});
261266
}
262267

263268
@Test
@@ -271,12 +276,14 @@ public void concurrentModificationErrorLevelOrder() {
271276

272277
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.LEVEL_ORDER);
273278

274-
assertThrows(ConcurrentModificationException.class, () -> {
275-
while (iter.hasNext()) {
276-
bst.add(0);
277-
iter.next();
278-
}
279-
});
279+
assertThrows(
280+
ConcurrentModificationException.class,
281+
() -> {
282+
while (iter.hasNext()) {
283+
bst.add(0);
284+
iter.next();
285+
}
286+
});
280287
}
281288

282289
@Test
@@ -290,12 +297,14 @@ public void concurrentModificationErrorRemovingPreOrder() {
290297

291298
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.PRE_ORDER);
292299

293-
assertThrows(ConcurrentModificationException.class, () -> {
294-
while (iter.hasNext()) {
295-
bst.remove(2);
296-
iter.next();
297-
}
298-
});
300+
assertThrows(
301+
ConcurrentModificationException.class,
302+
() -> {
303+
while (iter.hasNext()) {
304+
bst.remove(2);
305+
iter.next();
306+
}
307+
});
299308
}
300309

301310
@Test
@@ -309,12 +318,14 @@ public void concurrentModificationErrorRemovingInOrderOrder() {
309318

310319
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.IN_ORDER);
311320

312-
assertThrows(ConcurrentModificationException.class, () -> {
313-
while (iter.hasNext()) {
314-
bst.remove(2);
315-
iter.next();
316-
}
317-
});
321+
assertThrows(
322+
ConcurrentModificationException.class,
323+
() -> {
324+
while (iter.hasNext()) {
325+
bst.remove(2);
326+
iter.next();
327+
}
328+
});
318329
}
319330

320331
@Test
@@ -328,12 +339,14 @@ public void concurrentModificationErrorRemovingPostOrder() {
328339

329340
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.POST_ORDER);
330341

331-
assertThrows(ConcurrentModificationException.class, () -> {
332-
while (iter.hasNext()) {
333-
bst.remove(2);
334-
iter.next();
335-
}
336-
});
342+
assertThrows(
343+
ConcurrentModificationException.class,
344+
() -> {
345+
while (iter.hasNext()) {
346+
bst.remove(2);
347+
iter.next();
348+
}
349+
});
337350
}
338351

339352
@Test
@@ -347,12 +360,14 @@ public void concurrentModificationErrorRemovingLevelOrder() {
347360

348361
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.LEVEL_ORDER);
349362

350-
assertThrows(ConcurrentModificationException.class, () -> {
351-
while (iter.hasNext()) {
352-
bst.remove(2);
353-
iter.next();
354-
}
355-
});
363+
assertThrows(
364+
ConcurrentModificationException.class,
365+
() -> {
366+
while (iter.hasNext()) {
367+
bst.remove(2);
368+
iter.next();
369+
}
370+
});
356371
}
357372

358373
@Test

src/test/java/com/williamfiset/algorithms/datastructures/binarysearchtree/SplayTreeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import com.williamfiset.algorithms.datastructures.utils.TestUtils;
66
import java.util.*;
7-
87
import org.junit.jupiter.api.Test;
98

109
public class SplayTreeTest {

src/test/java/com/williamfiset/algorithms/datastructures/bloomfilter/BloomFilterTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.HashSet;
77
import java.util.Random;
88
import java.util.Set;
9-
109
import org.junit.jupiter.api.*;
1110

1211
public class BloomFilterTest {

src/test/java/com/williamfiset/algorithms/datastructures/fibonacciheap/FibonacciHeapTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.NoSuchElementException;
1111
import java.util.Queue;
1212
import java.util.Random;
13-
1413
import org.junit.jupiter.api.*;
1514

1615
// Disclaimer: Based by help of

0 commit comments

Comments
 (0)