Skip to content

Commit bde6a61

Browse files
authored
The Spotless Gradle plugin has been added (fishercoder1534#187)
* The Spotless Gradle plugin has been added * Corrected line endings from CRLF to LF
1 parent 4ab9fe5 commit bde6a61

File tree

2,171 files changed

+19348
-17082
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,171 files changed

+19348
-17082
lines changed

build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id 'checkstyle'
4+
id 'com.diffplug.spotless' version '6.25.0'
45
}
56

67
group = 'com.fishercoder'
@@ -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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import java.util.List;
44

55
public class Employee {
6-
/**
6+
/*
77
* It's the unique id of each node;
88
* unique id of this employee
99
*/
1010
public int id;
11-
/**
11+
/*
1212
* the importance value of this employee
1313
*/
1414
public int importance;
15-
/**
15+
/*
1616
* the id of direct subordinates
1717
*/
1818
public List<Integer> subordinates;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.fishercoder.common.classes;
22

3-
/**
3+
/*
44
* This is a class used by one OJ problem: MeetingRooms
55
*/
66
public class Interval implements Comparable<Interval> {
@@ -45,7 +45,7 @@ public Interval(int s, int e) {
4545
@Override
4646
public int compareTo(Interval o) {
4747
int compareStart = o.start;
48-
//ascending order
48+
// ascending order
4949
return this.start - compareStart;
5050
}
5151

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.fishercoder.common.classes;
22

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

7-
/**
6+
/*
87
* Normally, both val and next should be private attributes and generate getter and setter for them,
98
* but for the convenience of leetcode solutions, I set them as public.
109
*/
@@ -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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +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-
/**
27+
/*
2828
* return a N-ary tree based on the preorder values
2929
*/
3030
public static Node createNaryTree(List<Integer> preorderValues) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.fishercoder.common.classes;
22

3-
/**
3+
/*
44
* Created by fishercoder on 12/31/16.
55
*/
66
public class Point {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
6+
/*
77
* Created by fishercoder1534 on 9/30/16.
88
*/
99
public class UndirectedGraphNode {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.Collections;
55
import java.util.List;
66

7-
/**
7+
/*
88
* Copied this class from
99
* http://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram
1010
* This is an awesome one! It prints out the tree in a very nice fashion.
@@ -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

Lines changed: 25 additions & 21 deletions
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(" ");
@@ -143,7 +148,7 @@ public static <T> boolean isAllElementsNull(List<T> list) {
143148
return true;
144149
}
145150

146-
/**
151+
/*
147152
* If you want to print the reversed list out, you need to return the reversed list's head,
148153
* which was the end node of the original node. using the following function.
149154
*/
@@ -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,11 @@ 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+
/*LeetCode 2-d char array usually comes in like this:
276+
* ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
277+
* This method helps with the conversion.*/
274278
String[] arrays = input.split("],\\[");
275-
// CommonUtils.printArray_generic_type(arrays);
279+
// CommonUtils.printArray_generic_type(arrays);
276280
int m = arrays.length;
277281
int n = arrays[1].split(",").length;
278282
char[][] ans = new char[m][n];
@@ -300,15 +304,15 @@ public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(Strin
300304
}
301305

302306
public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(String input) {
303-
/**
307+
/*
304308
* LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
305309
* [[448,931],[234,889],[214,962],[576,746]]
306310
* The expected input for this method is: "[448,931],[234,889],[214,962],[576,746]"
307311
* i.e. strip off the beginning and ending square brackets, that's it.
308312
* The output of this method will be a standard Java 2-d array.
309313
* */
310314
String[] arrays = input.split("],\\[");
311-
// CommonUtils.printArray_generic_type(arrays);
315+
// CommonUtils.printArray_generic_type(arrays);
312316
int size = arrays[1].split(",").length;
313317
int[][] output = new int[arrays.length][size];
314318
for (int i = 0; i < arrays.length; i++) {
@@ -331,12 +335,12 @@ public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(Str
331335
}
332336
}
333337
}
334-
// CommonUtils.print2DIntArray(output);
338+
// CommonUtils.print2DIntArray(output);
335339
return output;
336340
}
337341

338342
public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(String input) {
339-
/**
343+
/*
340344
* LeetCode 2-d array input usually comes like this: each row could have different length
341345
* [[448,931,123,345],[889],[214,962],[576,746,897]]
342346
* The expected input for this method is: "[448,931,123,345],[889],[214,962],[576,746,897]"
@@ -388,7 +392,7 @@ public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(S
388392
}
389393

390394
public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(String input) {
391-
/**
395+
/*
392396
* How to copy LeetCode 2-d String array into this method:
393397
* 1. remove the beginning and ending quotes;
394398
* 2. put double quotes into this method parameter;
@@ -423,7 +427,7 @@ public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(
423427
}
424428

425429
public static List<String> convertLeetCode1DStringArrayInputIntoJavaArray(String input) {
426-
/**
430+
/*
427431
* LeetCode 2-d array input usually comes like this: each row could have different length
428432
* ["A","B","C"]
429433
* The expected input for this method is: "[\"A\",\"B\",\"C\"]"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy