🚀 A local debugging enhancer for Leetcode algorithm problems in Java 🚀
- Provide convenient and fast debugging functions.
- Support diverse input and output sources.
- Adapt to various input parameter types automatically.
- Provide easy to maintain and expand the APIs for adapting to more Leetcode algorithm debugging scenes.
<dependency>
<groupId>io.github.jidcoo</groupId>
<artifactId>leetcode-java-debug-enhancer</artifactId>
<version>1.0.2</version>
</dependency>implementation 'io.github.jidcoo:leetcode-java-debug-enhancer:1.0.2'| Resource | Index |
|---|---|
| Repository Hosting | Click here to browse the repository for this project |
| Standard-Jar | Click here to download directly(Standard-Jar) |
| Full-Jar | Click here to download directly(Full-Jar) |
Just import LeetcodeJavaDebugEnhancer as the project library.
- The minimum supported Java version is Java 8.
- LeetcodeJavaDebugEnhancer depends on Gson, version 2.10.1. For non Maven, non Gradle projects that do not include the Gson library, please use Full-Jar or manually import Gson library to your project.
Create a Java class called SimpleTest and ensure that SimpleTest is public:
//SimpleTest.java
public class SimpleTest {
}Import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer into SimpleTest, and then declare SimpleTest to inherit from the class LeetcodeJavaDebugEnhancer:
//SimpleTest.java
import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
public class SimpleTest extends LeetcodeJavaDebugEnhancer {
}Paste the Java code of the questions on the Leetcode into the SimpleTest and write the corresponding algorithm code to complete the requirements of the questions. Let's take the question Two Sum for example:
//SimpleTest.java
import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
public class SimpleTest extends LeetcodeJavaDebugEnhancer {
class Solution {
public int[] twoSum(int[] nums, int target) {
int n = nums.length;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}
}Click on the Run or Debug button of SimpleTest to run SimpleTest and start the debugging enhancer.
After the debugging enhancer starts, you will see the following output:
LeetcodeJavaDebugEnhancer[1.0.2] started.
Case input rule: One Case occupies one line, and the next Case needs to be input on the next line. The completion flag for a Case is encountering a new-line break or the EOF.
Then enter the following debugging parameter Case in the console:
[2,7,11,15] 9
[3,2,4] 6
[3,3] 6
Next, the enhancer will run the algorithm code based on the input Case and output the algorithm results to the console:
[0,1]
[1,2]
[0,1]
public InputProvider getInputProvider();LeetcodeJavaDebugEnhancer provides support for a variety of input sources such as Console(ConsoleInputProvider), File/Stream(FileInputProvider), String(StringInputProvider) and SerialMultipleInput(MultipleInputProvider) .
LeetcodeJavaDebugEnhancer uses the console as the default input source.
If you want to customize the input source, please return a valid InputProvider by overwriting this method.
Assuming there is now a file named "input.txt", the file content is as follows:
[2,7,11,15] 9
[3,2,4] 6
[3,3] 6
Here is an example code that uses the input.txt file as the input source:
//SimpleTest.java
import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileInputProvider;
import java.io.FileNotFoundException;
public class SimpleTest extends LeetcodeJavaDebugEnhancer {
class Solution {
public int[] twoSum(int[] nums, int target) {
int n = nums.length;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}
@Override
public InputProvider getInputProvider() {
try {
// FileInputProvider can accept file-name, file-object, and input-stream as construction parameters.
return new FileInputProvider("input.txt");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}public OutputConsumer getOutputConsumer();LeetcodeJavaDebugEnhancer provides support for a variety of output sources such as Console(ConsoleOutputConsumer), File/Stream(FileOutputConsumer) and ParallelMultipleOutput(MultipleOutputConsumer) .
LeetcodeJavaDebugEnhancer uses the console as the default output source.
If you want to customize the output source, please return a valid OutputConsumer by overwriting this method.
Continuing from the above example, the following is an example code that uses the input.txt file as the input source and the output.txt file as the output source:
//SimpleTest.java
import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.base.OutputConsumer;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileInputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileOutputConsumer;
import java.io.FileNotFoundException;
public class SimpleTest extends LeetcodeJavaDebugEnhancer {
class Solution {
public int[] twoSum(int[] nums, int target) {
int n = nums.length;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}
@Override
public InputProvider getInputProvider() {
try {
// FileInputProvider can accept file-name, file-object, and input-stream as construction parameters.
return new FileInputProvider("input.txt");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public OutputConsumer getOutputConsumer() {
try {
// FileOutputConsumer can accept file-name, file-object, and ouput-stream as construction parameters.
return new FileOutputConsumer("output.txt");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}@Target({TYPE, FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
@Repeatable(Requires.class)
public @interface Require {
/**
* The requirement string values;
*
* @return requirement string values.
*/
String[] values() default "";
/**
* The requirement types.
*
* @return requirement types.
*/
Class<?>[] types() default {};
}The Require annotation is used to mark and declare debugging resources required for the runtime of the debugging enhancer, such as input sources, output sources, etc. This annotation officially opened its feature to the public starting from version 1.0.2, supporting its use on class, field, method, and parameter.
Currently(v1.0.2), you can:
- Use the Require annotation on the debugging enhancer startup class to declare custom input and output sources. Furthermore, if you want to customize an IO source for a debugging enhancer now, you can not only provide a custom IO source instance for the debugging enhancer by
overwriting the
getInputProvider()orgetOutputConsumer()methods, but also customize the IO source for the debugging enhancer through convenient annotations.
//SimpleTest.java
//Customize input provider.
@Require(values = "case/input1.txt", types = FileInputProvider.class)
@Require(values = "[0,4,3,0] 0", types = StringInputProvider.class)
//Customize output consumer.
@Require(values = "case/output.txt", types = FileOutputConsumer.class)
public class SimpleTest extends LeetcodeJavaDebugEnhancer {
class Solution {
public int[] twoSum(int[] nums, int target) {
int n = nums.length;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return new int[0];
}
}
}The following is an example that lists all available uses of using Require annotation to customize IO sources.
//SimpleTest.java
//Customize input provider.
@Require(types = ConsoleInputProvider.class)
@Require(values = "case/input1.txt", types = FileInputProvider.class)
@Require(values = {"case/input1.txt", "case/input2.txt"}, types = FileInputProvider.class)
@Require(values = "[0,4,3,0] 0", types = StringInputProvider.class)
@Require(values = {"[0,4,3,0] 0", "[3,3] 6"}, types = StringInputProvider.class)
@Require(values = {
"[0,4,3,0] 0",
"[3,3] 6",
"case/input1.txt"
},
types = {
StringInputProvider.class,
StringInputProvider.class,
FileInputProvider.class
})
@Require(values = {
"case/input1.txt",
"",
"[0,4,3,0] 0"
},
types = {
FileInputProvider.class,
ConsoleInputProvider.class,
StringInputProvider.class
})
@Require(values = {
"case/input1.txt",
"",
"[0,4,3,0] 0",
"case/input2.txt",
"[3,3] 6",
},
types = {
FileInputProvider.class,
ConsoleInputProvider.class,
StringInputProvider.class,
FileInputProvider.class,
StringInputProvider.class
})
//Customize output consumer.
@Require(types = ConsoleOutputConsumer.class)
@Require(values = "case/output.txt", types = FileOutputConsumer.class)
@Require(values = {"case/output.txt", "case/output_1.txt"}, types = FileOutputConsumer.class)
@Require(values = {"case/output.txt", ""}, types = {FileOutputConsumer.class, ConsoleOutputConsumer.class})
public class SimpleTest extends LeetcodeJavaDebugEnhancer {
class Solution {/**ignored**/}
}LeetcodeJavaDebugEnhancer uses GitHub’s integrated issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:
- Before you log a bug, please search the Issue Tracker to see if someone has already reported the problem.
- If the issue doesn’t already exist, please create a new issue.
- Please provide as much information as possible with the issue report. We like to know the debugging enhancer version, jvm version, exception stack output, leetcode problem, input and output you’re using or getting.
- If you need to paste code or include a stack trace, use Markdown. ``` escapes before and after your text.
- If possible, try to create a test case that replicates the problem and attach it to the issue.
Any feedback, suggestions, or new feature requests regarding LeetcodeJavaDebugEnhancer can be provided to me by posting an Issue.
Of course, you can also contact me directly by email:
Nickname: Jidcoo
Email: jidcoo@163.com
Welcome anyone to contribute in any form to this project!!! Whether it's new feature requests, Issue reports, code submissions, documentation, or other kinds of contributions or support!!!
Isn't the true joy of open source from here?!!! Right?!!!
All submissions require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
LeetcodeJavaDebugEnhancer is an Open Source project released under the Apache 2.0 license.
Copyright 2024-2026 Jidcoo(https://github.com/jidcoo).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.