Skip to content

Commit 5936f74

Browse files
committed
The Spotless Gradle plugin has been added
1 parent 29f7c04 commit 5936f74

File tree

2,160 files changed

+20880
-19338
lines changed

Some content is hidden

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

2,160 files changed

+20880
-19338
lines changed

.github/workflows/gradle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
java-version: '17'
2525
cache: 'gradle'
2626
- name: Build with Gradle
27-
run: chmod +x gradlew && ./gradlew build
27+
run: chmod +x gradlew && ./gradlew spotlessCheck build

build.gradle

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'java'
3+
id 'com.diffplug.spotless' version '6.25.0'
34
id 'checkstyle'
45
}
56

@@ -54,3 +55,18 @@ checkstyle {
5455
toolVersion = '6.17'
5556
config = rootProject.resources.text.fromFile('fishercoder_checkstyle.xml')
5657
}
58+
59+
spotless {
60+
java {
61+
encoding 'UTF-8'
62+
target fileTree(projectDir) {
63+
include '**/src/**/*.java'
64+
exclude '**/build/**'
65+
}
66+
importOrder '\\#', '', '*'
67+
removeUnusedImports()
68+
googleJavaFormat('1.22.0').aosp()
69+
toggleOffOn()
70+
endWithNewline()
71+
}
72+
}

src/main/java/com/fishercoder/common/classes/Employee.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
import java.util.List;
44

55
public class Employee {
6-
/**
7-
* It's the unique id of each node;
8-
* unique id of this employee
9-
*/
6+
/** It's the unique id of each node; unique id of this employee */
107
public int id;
11-
/**
12-
* the importance value of this employee
13-
*/
8+
9+
/** the importance value of this employee */
1410
public int importance;
15-
/**
16-
* the id of direct subordinates
17-
*/
11+
12+
/** the id of direct subordinates */
1813
public List<Integer> subordinates;
1914

2015
public Employee(int id, int importance, List<Integer> subordinates) {

src/main/java/com/fishercoder/common/classes/Interval.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.fishercoder.common.classes;
22

3-
/**
4-
* This is a class used by one OJ problem: MeetingRooms
5-
*/
3+
/** This is a class used by one OJ problem: MeetingRooms */
64
public class Interval implements Comparable<Interval> {
75
public int start;
86
public int end;
@@ -45,7 +43,7 @@ public Interval(int s, int e) {
4543
@Override
4644
public int compareTo(Interval o) {
4745
int compareStart = o.start;
48-
//ascending order
46+
// ascending order
4947
return this.start - compareStart;
5048
}
5149

src/main/java/com/fishercoder/common/classes/ListNode.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fishercoder.common.classes;
22

33
import com.fishercoder.common.utils.CommonUtils;
4-
54
import java.util.List;
65

76
/**
@@ -86,5 +85,4 @@ public int hashCode() {
8685
public String toString() {
8786
return "ListNode{" + "val=" + val + ", next=" + next + '}';
8887
}
89-
9088
}

src/main/java/com/fishercoder/common/classes/NestedInteger.java

-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,4 @@ public static String printNi(NestedInteger thisNi, StringBuilder sb) {
6262
sb.append("]");
6363
return sb.toString();
6464
}
65-
6665
}

src/main/java/com/fishercoder/common/classes/Node.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ public Node(int val, List<Node> children) {
2222
this.children = children;
2323
}
2424

25-
//todo: implement this method
25+
// todo: implement this method
2626

27-
/**
28-
* return a N-ary tree based on the preorder values
29-
*/
27+
/** return a N-ary tree based on the preorder values */
3028
public static Node createNaryTree(List<Integer> preorderValues) {
3129
return null;
3230
}

src/main/java/com/fishercoder/common/classes/Point.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.fishercoder.common.classes;
22

3-
/**
4-
* Created by fishercoder on 12/31/16.
5-
*/
3+
/** Created by fishercoder on 12/31/16. */
64
public class Point {
75
public int x;
86
public int y;

src/main/java/com/fishercoder/common/classes/UndirectedGraphNode.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
7-
* Created by fishercoder1534 on 9/30/16.
8-
*/
6+
/** Created by fishercoder1534 on 9/30/16. */
97
public class UndirectedGraphNode {
108
public int val;
119
public List<UndirectedGraphNode> neighbors;

src/main/java/com/fishercoder/common/utils/BTreePrinter.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
/**
88
* Copied this class from
9-
* http://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram
10-
* This is an awesome one! It prints out the tree in a very nice fashion.
9+
* http://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram This is an awesome
10+
* one! It prints out the tree in a very nice fashion.
1111
*/
1212
public class BTreePrinter {
1313

@@ -55,8 +55,7 @@ private static <T extends Comparable<?>> void printNodeInternal(
5555
for (int j = 0; j < nodes.size(); j++) {
5656
BTreePrinter.printWhitespaces(firstSpaces - i);
5757
if (nodes.get(j) == null) {
58-
BTreePrinter.printWhitespaces(endgeLines + endgeLines + i
59-
+ 1);
58+
BTreePrinter.printWhitespaces(endgeLines + endgeLines + i + 1);
6059
continue;
6160
}
6261

@@ -94,8 +93,7 @@ private static <T extends Comparable<?>> int maxLevel(Node<T> node) {
9493
return 0;
9594
}
9695

97-
return Math.max(BTreePrinter.maxLevel(node.left),
98-
BTreePrinter.maxLevel(node.right)) + 1;
96+
return Math.max(BTreePrinter.maxLevel(node.left), BTreePrinter.maxLevel(node.right)) + 1;
9997
}
10098

10199
private static <T> boolean isAllElementsNull(List<T> list) {
@@ -171,7 +169,6 @@ private static Node<Integer> test2() {
171169
return root;
172170
}
173171

174-
175172
public static class Node<T extends Comparable<?>> {
176173
Node<T> left;
177174
Node<T> right;
@@ -181,5 +178,4 @@ public Node(T data) {
181178
this.data = data;
182179
}
183180
}
184-
185-
}
181+
}

src/main/java/com/fishercoder/common/utils/CommonUtils.java

+44-44
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fishercoder.common.classes.Interval;
44
import com.fishercoder.common.classes.ListNode;
5-
65
import java.util.ArrayList;
76
import java.util.Deque;
87
import java.util.List;
@@ -13,7 +12,7 @@ public class CommonUtils {
1312
private static final int DEFAULT_TREE_SIZE = 10;
1413
private static final int DEFAULT_UPPER_BOUND = 100;
1514

16-
//How to make a method generic: declare <T> in its method signature
15+
// How to make a method generic: declare <T> in its method signature
1716
public static <T> void printArray_generic_type(T[] nums) {
1817
for (T i : nums) {
1918
System.out.print(i + ", ");
@@ -22,14 +21,19 @@ public static <T> void printArray_generic_type(T[] nums) {
2221
}
2322

2423
public static void main(String... strings) {
25-
Integer[] nums = new Integer[]{1, 2, 3, 4, 5};
24+
Integer[] nums = new Integer[] {1, 2, 3, 4, 5};
2625
printArray_generic_type(nums);
27-
String input1 = "[\"zDkA\",\"GfAj\",\"lt\"],[\"GfAj\",\"rtupD\",\"og\",\"l\"],[\"rtupD\",\"IT\",\"jGcew\",\"ZwFqF\"],[\"og\",\"yVobt\",\"EjA\",\"piUyQ\"],[\"IT\",\"XFlc\",\"W\",\"rB\"],[\"l\",\"GwQg\",\"shco\",\"Dub\",\"KwgZq\"],[\"oXMG\",\"uqe\"],[\"sNyV\",\"WbrP\"]";
26+
String input1 =
27+
"[\"zDkA\",\"GfAj\",\"lt\"],[\"GfAj\",\"rtupD\",\"og\",\"l\"],[\"rtupD\",\"IT\",\"jGcew\",\"ZwFqF\"],[\"og\",\"yVobt\",\"EjA\",\"piUyQ\"],[\"IT\",\"XFlc\",\"W\",\"rB\"],[\"l\",\"GwQg\",\"shco\",\"Dub\",\"KwgZq\"],[\"oXMG\",\"uqe\"],[\"sNyV\",\"WbrP\"]";
2828
String input2 = "[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]";
2929
CommonUtils.printListList(convertLeetCode2DStringArrayInputIntoJavaArray(input1));
3030
CommonUtils.printListList(convertLeetCode2DStringArrayInputIntoJavaArray(input2));
31-
CommonUtils.print(convertLeetCode1DStringArrayInputIntoJavaArray("[\"abcsi\",\"abyzjgj\",\"advz\",\"ag\",\"agkgdkob\",\"agpr\",\"ail\"]"));
32-
CommonUtils.print2DIntArray(convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[448,931,123,345],[889],[214,962],[576,746,897]"));
31+
CommonUtils.print(
32+
convertLeetCode1DStringArrayInputIntoJavaArray(
33+
"[\"abcsi\",\"abyzjgj\",\"advz\",\"ag\",\"agkgdkob\",\"agpr\",\"ail\"]"));
34+
CommonUtils.print2DIntArray(
35+
convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
36+
"[448,931,123,345],[889],[214,962],[576,746,897]"));
3337
}
3438

3539
public static void printArray(boolean[] booleans) {
@@ -98,8 +102,8 @@ public static List<Integer> randomIntArrayGenerator(int size) {
98102

99103
// overloaded method to take no argument
100104
public static List<Integer> randomIntArrayGenerator() {
101-
return CommonUtils.randomIntArrayGenerator(CommonUtils.DEFAULT_TREE_SIZE,
102-
DEFAULT_UPPER_BOUND);
105+
return CommonUtils.randomIntArrayGenerator(
106+
CommonUtils.DEFAULT_TREE_SIZE, DEFAULT_UPPER_BOUND);
103107
}
104108

105109
// this one has two other overloaded methods as above
@@ -126,7 +130,8 @@ public static List<Integer> uniqueIntArrayGenerator(int size) {
126130
}
127131

128132
// @Notes(context =
129-
// "I'm assuing only classes in this PACKAGE will call the following two methods, so just leave the modifier as default, i.e. no public, private, or protected.")
133+
// "I'm assuing only classes in this PACKAGE will call the following two methods, so just leave
134+
// the modifier as default, i.e. no public, private, or protected.")
130135
public static void printWhitespaces(int count) {
131136
for (int i = 0; i < count; i++) {
132137
System.out.print(" ");
@@ -228,7 +233,6 @@ public static void printMatrixGeneric(boolean[][] matrix) {
228233
System.out.println();
229234
}
230235
System.out.println("----------------------------------------------------");
231-
232236
}
233237

234238
public static <T> void printListList(List<List<T>> res) {
@@ -268,11 +272,13 @@ public static void print2DCharArray(char[][] arrayArrays) {
268272
}
269273

270274
public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(String input) {
271-
/**LeetCode 2-d char array usually comes in like this:
272-
* ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
273-
* This method helps with the conversion.*/
275+
/**
276+
* LeetCode 2-d char array usually comes in like this: ["#"," ","#"],[" ","
277+
* ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which
278+
* makes it not usable in Java code. This method helps with the conversion.
279+
*/
274280
String[] arrays = input.split("],\\[");
275-
// CommonUtils.printArray_generic_type(arrays);
281+
// CommonUtils.printArray_generic_type(arrays);
276282
int m = arrays.length;
277283
int n = arrays[1].split(",").length;
278284
char[][] ans = new char[m][n];
@@ -302,13 +308,12 @@ public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(Strin
302308
public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(String input) {
303309
/**
304310
* LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
305-
* [[448,931],[234,889],[214,962],[576,746]]
306-
* The expected input for this method is: "[448,931],[234,889],[214,962],[576,746]"
307-
* i.e. strip off the beginning and ending square brackets, that's it.
308-
* The output of this method will be a standard Java 2-d array.
309-
* */
311+
* [[448,931],[234,889],[214,962],[576,746]] The expected input for this method is:
312+
* "[448,931],[234,889],[214,962],[576,746]" i.e. strip off the beginning and ending square
313+
* brackets, that's it. The output of this method will be a standard Java 2-d array.
314+
*/
310315
String[] arrays = input.split("],\\[");
311-
// CommonUtils.printArray_generic_type(arrays);
316+
// CommonUtils.printArray_generic_type(arrays);
312317
int size = arrays[1].split(",").length;
313318
int[][] output = new int[arrays.length][size];
314319
for (int i = 0; i < arrays.length; i++) {
@@ -331,18 +336,17 @@ public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(Str
331336
}
332337
}
333338
}
334-
// CommonUtils.print2DIntArray(output);
339+
// CommonUtils.print2DIntArray(output);
335340
return output;
336341
}
337342

338343
public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(String input) {
339344
/**
340345
* LeetCode 2-d array input usually comes like this: each row could have different length
341-
* [[448,931,123,345],[889],[214,962],[576,746,897]]
342-
* The expected input for this method is: "[448,931,123,345],[889],[214,962],[576,746,897]"
343-
* i.e. strip off the beginning and ending square brackets, that's it.
344-
* The output of this method will be a standard Java 2-d array.
345-
* */
346+
* [[448,931,123,345],[889],[214,962],[576,746,897]] The expected input for this method is:
347+
* "[448,931,123,345],[889],[214,962],[576,746,897]" i.e. strip off the beginning and ending
348+
* square brackets, that's it. The output of this method will be a standard Java 2-d array.
349+
*/
346350
String[] arrays = input.split("],\\[");
347351
int maxLen = 0;
348352
int[] sizes = new int[arrays.length];
@@ -389,19 +393,17 @@ public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(S
389393

390394
public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(String input) {
391395
/**
392-
* How to copy LeetCode 2-d String array into this method:
393-
* 1. remove the beginning and ending quotes;
394-
* 2. put double quotes into this method parameter;
395-
* 3. copy the input into the double quotes.
396+
* How to copy LeetCode 2-d String array into this method: 1. remove the beginning and
397+
* ending quotes; 2. put double quotes into this method parameter; 3. copy the input into
398+
* the double quotes.
396399
*
397-
* LeetCode 2-d array input usually comes like this: each row could have different length
398-
* [["A","B"],["C"],["B","C"],["D"]]
399-
* The expected input for this method is: "[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]"
400-
* just copy the LeetCode input: ["A","B"],["C"],["B","C"],["D"] into double quotes in Java,
401-
* it'll auto escape the double quotes.
402-
* i.e. strip off the beginning and ending square brackets, that's it.
403-
* The output of this method will be a standard Java 2-d array.
404-
* */
400+
* <p>LeetCode 2-d array input usually comes like this: each row could have different length
401+
* [["A","B"],["C"],["B","C"],["D"]] The expected input for this method is:
402+
* "[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]" just copy the LeetCode input:
403+
* ["A","B"],["C"],["B","C"],["D"] into double quotes in Java, it'll auto escape the double
404+
* quotes. i.e. strip off the beginning and ending square brackets, that's it. The output of
405+
* this method will be a standard Java 2-d array.
406+
*/
405407
String[] arrays = input.split("],\\[");
406408
List<List<String>> result = new ArrayList<>();
407409
for (int i = 0; i < arrays.length; i++) {
@@ -425,12 +427,10 @@ public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(
425427
public static List<String> convertLeetCode1DStringArrayInputIntoJavaArray(String input) {
426428
/**
427429
* LeetCode 2-d array input usually comes like this: each row could have different length
428-
* ["A","B","C"]
429-
* The expected input for this method is: "[\"A\",\"B\",\"C\"]"
430-
* just copy the LeetCode input: ["A","B","C"] into double quotes in Java,
431-
* it'll auto escape the double quotes.
432-
* The output of this method will be a standard Java 1-d array.
433-
* */
430+
* ["A","B","C"] The expected input for this method is: "[\"A\",\"B\",\"C\"]" just copy the
431+
* LeetCode input: ["A","B","C"] into double quotes in Java, it'll auto escape the double
432+
* quotes. The output of this method will be a standard Java 1-d array.
433+
*/
434434
String[] arrays = input.split(",");
435435
List<String> result = new ArrayList<>();
436436
for (int i = 0; i < arrays.length; i++) {

src/main/java/com/fishercoder/common/utils/LinkedListUtils.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fishercoder.common.utils;
22

33
import com.fishercoder.common.classes.ListNode;
4-
54
import java.util.List;
65

76
public class LinkedListUtils {

src/main/java/com/fishercoder/common/utils/Notes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
String issue() default "";
1414

1515
String context() default ""; // this variable is used to state how I solved
16+
1617
// this problem, whether completely made it
1718
// myself, or copied it from online, or a
1819
// combination of both approaches.
1920

2021
boolean needsReview() default true;
21-
2222
}

0 commit comments

Comments
 (0)