Skip to content

The Spotless Gradle plugin has been added #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id 'checkstyle'
id 'com.diffplug.spotless' version '6.25.0'
}

group = 'com.fishercoder'
Expand Down Expand Up @@ -54,3 +55,18 @@ checkstyle {
toolVersion = '6.17'
config = rootProject.resources.text.fromFile('fishercoder_checkstyle.xml')
}

spotless {
java {
encoding 'UTF-8'
target fileTree(projectDir) {
include '**/src/**/*.java'
exclude '**/build/**'
}
importOrder '\\#', '', '*'
removeUnusedImports()
googleJavaFormat('1.22.0').aosp()
toggleOffOn()
endWithNewline()
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/fishercoder/common/classes/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import java.util.List;

public class Employee {
/**
/*
* It's the unique id of each node;
* unique id of this employee
*/
public int id;
/**
/*
* the importance value of this employee
*/
public int importance;
/**
/*
* the id of direct subordinates
*/
public List<Integer> subordinates;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fishercoder/common/classes/Interval.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fishercoder.common.classes;

/**
/*
* This is a class used by one OJ problem: MeetingRooms
*/
public class Interval implements Comparable<Interval> {
Expand Down Expand Up @@ -45,7 +45,7 @@ public Interval(int s, int e) {
@Override
public int compareTo(Interval o) {
int compareStart = o.start;
//ascending order
// ascending order
return this.start - compareStart;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/fishercoder/common/classes/ListNode.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.fishercoder.common.classes;

import com.fishercoder.common.utils.CommonUtils;

import java.util.List;

/**
/*
* Normally, both val and next should be private attributes and generate getter and setter for them,
* but for the convenience of leetcode solutions, I set them as public.
*/
Expand Down Expand Up @@ -86,5 +85,4 @@ public int hashCode() {
public String toString() {
return "ListNode{" + "val=" + val + ", next=" + next + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ public static String printNi(NestedInteger thisNi, StringBuilder sb) {
sb.append("]");
return sb.toString();
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/fishercoder/common/classes/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public Node(int val, List<Node> children) {
this.children = children;
}

//todo: implement this method
// todo: implement this method

/**
/*
* return a N-ary tree based on the preorder values
*/
public static Node createNaryTree(List<Integer> preorderValues) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fishercoder/common/classes/Point.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fishercoder.common.classes;

/**
/*
* Created by fishercoder on 12/31/16.
*/
public class Point {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

/**
/*
* Created by fishercoder1534 on 9/30/16.
*/
public class UndirectedGraphNode {
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/fishercoder/common/utils/BTreePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Collections;
import java.util.List;

/**
/*
* Copied this class from
* http://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram
* This is an awesome one! It prints out the tree in a very nice fashion.
Expand Down Expand Up @@ -55,8 +55,7 @@ private static <T extends Comparable<?>> void printNodeInternal(
for (int j = 0; j < nodes.size(); j++) {
BTreePrinter.printWhitespaces(firstSpaces - i);
if (nodes.get(j) == null) {
BTreePrinter.printWhitespaces(endgeLines + endgeLines + i
+ 1);
BTreePrinter.printWhitespaces(endgeLines + endgeLines + i + 1);
continue;
}

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

return Math.max(BTreePrinter.maxLevel(node.left),
BTreePrinter.maxLevel(node.right)) + 1;
return Math.max(BTreePrinter.maxLevel(node.left), BTreePrinter.maxLevel(node.right)) + 1;
}

private static <T> boolean isAllElementsNull(List<T> list) {
Expand Down Expand Up @@ -171,7 +169,6 @@ private static Node<Integer> test2() {
return root;
}


public static class Node<T extends Comparable<?>> {
Node<T> left;
Node<T> right;
Expand All @@ -181,5 +178,4 @@ public Node(T data) {
this.data = data;
}
}

}
}
46 changes: 25 additions & 21 deletions src/main/java/com/fishercoder/common/utils/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fishercoder.common.classes.Interval;
import com.fishercoder.common.classes.ListNode;

import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
Expand All @@ -13,7 +12,7 @@ public class CommonUtils {
private static final int DEFAULT_TREE_SIZE = 10;
private static final int DEFAULT_UPPER_BOUND = 100;

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

public static void main(String... strings) {
Integer[] nums = new Integer[]{1, 2, 3, 4, 5};
Integer[] nums = new Integer[] {1, 2, 3, 4, 5};
printArray_generic_type(nums);
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\"]";
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\"]";
String input2 = "[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]";
CommonUtils.printListList(convertLeetCode2DStringArrayInputIntoJavaArray(input1));
CommonUtils.printListList(convertLeetCode2DStringArrayInputIntoJavaArray(input2));
CommonUtils.print(convertLeetCode1DStringArrayInputIntoJavaArray("[\"abcsi\",\"abyzjgj\",\"advz\",\"ag\",\"agkgdkob\",\"agpr\",\"ail\"]"));
CommonUtils.print2DIntArray(convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[448,931,123,345],[889],[214,962],[576,746,897]"));
CommonUtils.print(
convertLeetCode1DStringArrayInputIntoJavaArray(
"[\"abcsi\",\"abyzjgj\",\"advz\",\"ag\",\"agkgdkob\",\"agpr\",\"ail\"]"));
CommonUtils.print2DIntArray(
convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
"[448,931,123,345],[889],[214,962],[576,746,897]"));
}

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

// overloaded method to take no argument
public static List<Integer> randomIntArrayGenerator() {
return CommonUtils.randomIntArrayGenerator(CommonUtils.DEFAULT_TREE_SIZE,
DEFAULT_UPPER_BOUND);
return CommonUtils.randomIntArrayGenerator(
CommonUtils.DEFAULT_TREE_SIZE, DEFAULT_UPPER_BOUND);
}

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

// @Notes(context =
// "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.")
// "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.")
public static void printWhitespaces(int count) {
for (int i = 0; i < count; i++) {
System.out.print(" ");
Expand All @@ -143,7 +148,7 @@ public static <T> boolean isAllElementsNull(List<T> list) {
return true;
}

/**
/*
* If you want to print the reversed list out, you need to return the reversed list's head,
* which was the end node of the original node. using the following function.
*/
Expand Down Expand Up @@ -228,7 +233,6 @@ public static void printMatrixGeneric(boolean[][] matrix) {
System.out.println();
}
System.out.println("----------------------------------------------------");

}

public static <T> void printListList(List<List<T>> res) {
Expand Down Expand Up @@ -268,11 +272,11 @@ public static void print2DCharArray(char[][] arrayArrays) {
}

public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(String input) {
/**LeetCode 2-d char array usually comes in like this:
* ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
* This method helps with the conversion.*/
/*LeetCode 2-d char array usually comes in like this:
* ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
* This method helps with the conversion.*/
String[] arrays = input.split("],\\[");
// CommonUtils.printArray_generic_type(arrays);
// CommonUtils.printArray_generic_type(arrays);
int m = arrays.length;
int n = arrays[1].split(",").length;
char[][] ans = new char[m][n];
Expand Down Expand Up @@ -300,15 +304,15 @@ public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(Strin
}

public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(String input) {
/**
/*
* LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
* [[448,931],[234,889],[214,962],[576,746]]
* The expected input for this method is: "[448,931],[234,889],[214,962],[576,746]"
* i.e. strip off the beginning and ending square brackets, that's it.
* The output of this method will be a standard Java 2-d array.
* */
String[] arrays = input.split("],\\[");
// CommonUtils.printArray_generic_type(arrays);
// CommonUtils.printArray_generic_type(arrays);
int size = arrays[1].split(",").length;
int[][] output = new int[arrays.length][size];
for (int i = 0; i < arrays.length; i++) {
Expand All @@ -331,12 +335,12 @@ public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(Str
}
}
}
// CommonUtils.print2DIntArray(output);
// CommonUtils.print2DIntArray(output);
return output;
}

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

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

public static List<String> convertLeetCode1DStringArrayInputIntoJavaArray(String input) {
/**
/*
* LeetCode 2-d array input usually comes like this: each row could have different length
* ["A","B","C"]
* The expected input for this method is: "[\"A\",\"B\",\"C\"]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fishercoder.common.utils;

import com.fishercoder.common.classes.ListNode;

import java.util.List;

public class LinkedListUtils {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fishercoder/common/utils/Notes.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
String issue() default "";

String context() default ""; // this variable is used to state how I solved

// this problem, whether completely made it
// myself, or copied it from online, or a
// combination of both approaches.

boolean needsReview() default true;

}
Loading