If you need to use a method in AT as a starting point for
- * debugging enhancements, please provide an instance of that method. And
- * then the {@link LeetcodeJavaDebugEnhancer} will start from that point.
- *
- *
If the method returns null, the {@link LeetcodeJavaDebugEnhancer} will look for
- * the internal class Solution in AT and find a suitable startup point
- * from Solution as a debugging enhancement startup point.
- *
- *
When the AT is a data structure design class, it is
- * necessary to return a non-null debugging enhancement startup point. Otherwise,
- * the {@link LeetcodeJavaDebugEnhancer} will not be able to start normally
- * with enhanced performance
- *
- * @return the enhancements point.
- */
- public Method getEnhancementPoint() {
- return null;
- }
+ String VERSION = "1.0.3";
/**
*
If you need to customize an input provider, please return a valid instance of
@@ -74,7 +52,7 @@ public Method getEnhancementPoint() {
*
* @return the input provider.
*/
- public InputProvider getInputProvider() {
+ default InputProvider getInputProvider() {
return null;
}
@@ -88,7 +66,7 @@ public InputProvider getInputProvider() {
*
* @return the output consumer.
*/
- public OutputConsumer getOutputConsumer() {
+ default OutputConsumer getOutputConsumer() {
return null;
}
@@ -100,7 +78,7 @@ public OutputConsumer getOutputConsumer() {
*
* @return a list of printing strategies
*/
- public List> getOutputPrintStrategies() {
+ default List> getOutputPrintStrategies() {
return null;
}
@@ -117,33 +95,64 @@ public List> getOutputPrintStrategies() {
* @see Level#WARNING
* @see Level#INFO
*/
- public Level getEnhancerLogLevel() {
+ default Level getEnhancerLogLevel() {
return Level.OFF;
}
+ /**
+ * Return the custom enhancer payload.
+ *
+ *
For example, if you want to debug an outer algorithm solution
+ * instead of an inner algorithm solution, you can use this api to
+ * specify the outer algorithm solution class.
+ *
+ * @return the Enhancer payload class.
+ * @since 1.0.3
+ */
+ default Class> getEnhancerPayload() {
+ return null;
+ }
+
+ /**
+ *
If you need to customize the accepting of the input parameter, please return
+ * a list of parameter accepting strategies, and the {@link LeetcodeJavaDebugEnhancer} will
+ * try to find the appropriate strategy from this list to accept the input parameter.
+ *
+ * @return a list of parameter accepting strategies
+ * @since 1.0.3
+ */
+ default List> getParameterAcceptStrategies() {
+ return null;
+ }
+
/**
* Return the LeetcodeJavaDebugEnhancer version.
*
* @return the LeetcodeJavaDebugEnhancer version.
*/
- public final String getEnhancerVersion() {
+ static String getEnhancerVersion() {
return VERSION;
}
/**
- * LeetcodeJavaDebugEnhancer starting main point.
+ * LeetcodeJavaDebugEnhancer running point.
*
- * @param args start args.
+ * @param __AT__ the AT name.
*/
- public static void main(String[] args) {
- String __AT__ = System.getProperty("sun.java.command");
+ @SuppressWarnings("unchecked")
+ static void run(String __AT__) {
System.out.println("LeetcodeJavaDebugEnhancer[" + VERSION + "] started.");
if (!"io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer".equals(__AT__)) {
try {
+ Class> atClass = Class.forName(__AT__);
+ AssertUtil.isTrue(
+ ReflectUtil.isImplementInterface(atClass, LeetcodeJavaDebugEnhancer.class),
+ "The class is not an AT class."
+ );
// Let's do a great work here now.
- LeetcodeJavaDebugEnhanceProcessor.process((Class extends LeetcodeJavaDebugEnhancer>) Class.forName(__AT__));
+ LeetcodeJavaDebugEnhanceProcessor.process((Class extends LeetcodeJavaDebugEnhancer>) atClass);
} catch (Exception | Error err) {
- EnhancerLogUtil.logE("LeetcodeJavaDebugEnhancer[%s] runtime error: %s", VERSION, err.getMessage());
+ EnhancerLogUtil.logE("LeetcodeJavaDebugEnhancer[%s] runtime error: %s: %s", VERSION, err.getClass().getName(), err.getMessage());
throw new EnhancerException("LeetcodeJavaDebugEnhancer runtime error: " + err.getMessage(), err);
}
} else {
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BaseParameterAcceptStrategy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BaseParameterAcceptStrategy.java
index 04a4985..fa4d3e6 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BaseParameterAcceptStrategy.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BaseParameterAcceptStrategy.java
@@ -16,8 +16,14 @@
package io.github.jidcoo.opto.lcdb.enhancer.base;
+import io.github.jidcoo.opto.lcdb.enhancer.core.parser.ParameterAcceptResult;
+import io.github.jidcoo.opto.lcdb.enhancer.core.parser.ParameterAcceptStrategyTracer;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.TypeUtil;
+
+import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
+import java.util.Stack;
/**
*
BaseParameterAcceptStrategy is an abstract class
@@ -52,8 +58,47 @@ public abstract class BaseParameterAcceptStrategy implements Strategi
*
* @return the accepted parameter.
*/
- protected abstract Parameter acceptParameter(Object object, java.lang.reflect.Parameter type,
- Map, Set>> strategiesMap) throws Throwable;
+ protected abstract Parameter acceptParameter(Object object, Type type,
+ Map, Set>> strategiesMap);
+
+ /**
+ * Common accepting parameter function.
+ *
+ * @param strategies the strategy set for parameter accepting.
+ * @param parameterType the parameter type.
+ * @param object the parameter object.
+ * @return {@link ParameterAcceptResult}
+ * @since 1.0.3
+ */
+ protected ParameterAcceptResult commonAcceptingFunction(Map, Set>> strategies,
+ Type parameterType,
+ Object object) {
+ // Create a tracer stack for tracking the acceptance process.
+ Stack tracerStack = new Stack<>();
+
+ try {
+ // Find the strategy set for the parameter acceptance.
+ Set> strategySet = findStrategySet(
+ TypeUtil.obtainRawTypeOfType(parameterType),
+ strategies
+ );
+ for (BaseParameterAcceptStrategy> acceptStrategy : strategySet) {
+ try {
+ // Try to accept the parameter and return the accepted result.
+ return ParameterAcceptResult.accept(acceptStrategy.accept(parameterType, object, strategies));
+ } catch (Throwable e) {
+ // Push the throwable with the object tracer into stack.
+ tracerStack.push(new ParameterAcceptStrategyTracer(acceptStrategy.getClass().getName(), e));
+ }
+ }
+ } catch (Throwable throwable) {
+ // Push the throwable with the object tracer into stack.
+ tracerStack.push(new ParameterAcceptStrategyTracer(null, throwable));
+ }
+
+ // Return the rejected result.
+ return ParameterAcceptResult.reject(object, tracerStack);
+ }
/**
* Accept the object by the class type.
@@ -64,9 +109,9 @@ protected abstract Parameter acceptParameter(Object object, java.lang.reflect.Pa
* @return the accepted output.
*/
@Override
- public final Parameter accept(Object classType, Object object,
+ public final Parameter accept(Type classType, Object object,
Map, Set>> strategiesMap) throws Throwable {
// Do real call the acceptParameter() method.
- return acceptParameter(object, (java.lang.reflect.Parameter) classType, strategiesMap);
+ return acceptParameter(object, classType, strategiesMap);
}
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BasePrintingStrategy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BasePrintingStrategy.java
index e429e01..4cc1a7f 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BasePrintingStrategy.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/BasePrintingStrategy.java
@@ -16,6 +16,7 @@
package io.github.jidcoo.opto.lcdb.enhancer.base;
+import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
@@ -57,7 +58,7 @@ public abstract class BasePrintingStrategy
*
*
ParameterAcceptor performs appropriate acceptance
- * of input objects based on built-in parameter
- * acceptance strategies and external acceptance
- * strategies by {@link #accept(Parameter, Object)}.
+ * of input objects based on built-in or external parameter
+ * acceptance strategies by {@link #acceptParameter(Object, Type, Map)}
*
*
* @author Jidcoo
@@ -49,17 +44,12 @@
* @see IRMatchInputParserNode
* @since 1.0
*/
-final class ParameterAcceptor extends BaseParameterAcceptStrategy {
+final class ParameterAcceptor extends BaseParameterAcceptStrategy {
/**
* Builtin parameter acceptance strategy map.
*/
- private Map, Set>> builtinAcceptStrategyMap;
-
- /**
- * BaseParameterAcceptStrategy comparator.
- */
- private final Comparator strategyComparator = Comparator.comparingInt(Order::getOrder).reversed();
+ private final Map, Set>> builtinAcceptStrategyMap;
/**
* Built-in parameter acceptance strategy set package location.
@@ -69,6 +59,7 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy {
/**
* Create a ParameterAcceptor instance.
*/
+ @SuppressWarnings("all")
ParameterAcceptor() {
this.builtinAcceptStrategyMap = new HashMap<>();
// Collect all builtin parameter acceptance strategies.
@@ -77,7 +68,7 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy {
(Class type) -> type.isAnnotationPresent(Require.class) && ReflectUtil.isExtendsClass(type,
BaseParameterAcceptStrategy.class) && !Modifier.isAbstract(type.getModifiers()), (Class
extends BaseParameterAcceptStrategy> beanType) -> ReflectUtil.createInstance(beanType)).stream().filter(Objects::nonNull).collect(Collectors.toList());
- if (!ContainerCheckUtil.isListEmpty(strategies)) {
+ if (ContainerUtil.isNotEmpty(strategies)) {
// Add all strategies to the builtinAcceptStrategyMap.
for (BaseParameterAcceptStrategy> strategy : strategies) {
addParameterAcceptStrategy(strategy.getAcceptableType(), strategy, builtinAcceptStrategyMap);
@@ -85,58 +76,6 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy {
}
}
- /**
- * Wrap the strategy add function.
- *
- * @param type the accepted class type.
- * @param strategy the acceptance strategy.
- * @param strategyMap the acceptance strategy map.
- */
- private void addParameterAcceptStrategy(Class> type, BaseParameterAcceptStrategy> strategy, Map,
- Set>> strategyMap) {
- AssertUtil.nonNull(strategy, "The parameter acceptance strategy cannot be null.");
- AssertUtil.nonNull(type, "The type of the " + strategy + " cannot be null.");
- // Get the strategySet by clazz.
- Set> strategySet = strategyMap.computeIfAbsent(type,
- key -> new TreeSet<>(strategyComparator));
- // Add the strategy to the set.
- strategySet.add(strategy);
- }
-
- /**
- * Accept an object with the parameter type.
- *
- * @param invokerParameterType the leetcode invoker parameter type.
- * @param object the input object for accepting.
- * @return the parameter acceptance result.
- */
- public ParameterAcceptResult accept(Parameter invokerParameterType, Object object) {
- // Create a tracer stack for tracking the acceptance process.
- Stack tracerStack = new Stack<>();
-
- try {
- // Find the strategy set for the parameter acceptance.
- Set> strategySet = findStrategySet(invokerParameterType.getType(),
- builtinAcceptStrategyMap);
- for (BaseParameterAcceptStrategy> acceptStrategy : strategySet) {
- try {
- // Try to accept the parameter and return the accepted result.
- return ParameterAcceptResult.accept(acceptStrategy.accept(invokerParameterType, object,
- builtinAcceptStrategyMap));
- } catch (Throwable e) {
- // Push the throwable with the object tracer into stack.
- tracerStack.push(new ParameterAcceptStrategyTracer(acceptStrategy.getClass().getName(), e));
- }
- }
- } catch (Throwable throwable) {
- // Push the throwable with the object tracer into stack.
- tracerStack.push(new ParameterAcceptStrategyTracer(null, throwable));
- }
-
- // Return the rejected result.
- return ParameterAcceptResult.reject(object, tracerStack);
- }
-
/**
* Accept the object.
*
@@ -151,10 +90,13 @@ public ParameterAcceptResult accept(Parameter invokerParameterType, Object objec
* @return the accepted parameter.
*/
@Override
- protected Object acceptParameter(Object object, Parameter type,
- Map, Set>> strategiesMap) throws Throwable {
- // This method is not supported in ParameterAcceptor.
- throw new RuntimeException("Unsupported!");
+ protected ParameterAcceptResult acceptParameter(Object object, Type type,
+ Map, Set>> strategiesMap) {
+ if (Objects.isNull(strategiesMap)) {
+ // Use built-in parameter accepting strategies.
+ strategiesMap = this.builtinAcceptStrategyMap;
+ }
+ return commonAcceptingFunction(strategiesMap, type, object);
}
/**
@@ -164,8 +106,7 @@ protected Object acceptParameter(Object object, Parameter type,
*/
@Override
public int getOrder() {
- // This method is not supported in ParameterAcceptor.
- throw new RuntimeException("Unsupported!");
+ return Integer.MAX_VALUE;
}
/**
@@ -174,8 +115,48 @@ public int getOrder() {
* @return the acceptable type.
*/
@Override
- public Class> getAcceptableType() {
- // This method is not supported in ParameterAcceptor.
- throw new RuntimeException("Unsupported!");
+ public Class getAcceptableType() {
+ return ParameterAcceptResult.class;
+ }
+
+ /**
+ * Return a combination strategy set containing built-in strategies and custom strategies.
+ *
+ * @param strategies the custom strategies.
+ * @return null if the custom strategies list is empty,
+ * else a combination parameter accepting strategy set.
+ * @since 1.0.3
+ */
+ Map, Set>> combineCustomStrategies(List> strategies) {
+ if (ContainerUtil.isEmpty(strategies)) {
+ return null;
+ }
+ Map, Set>> combinedCustomStrategiesMap = new HashMap<>();
+ // Build map by origin builtinAcceptStrategyMap.
+ this.builtinAcceptStrategyMap.forEach((key, val) -> {
+ val.forEach(strategy -> addParameterAcceptStrategy(key, strategy, combinedCustomStrategiesMap));
+ });
+ // Combine the custom strategies.
+ strategies.forEach(strategy -> addParameterAcceptStrategy(strategy.getAcceptableType(), strategy,
+ combinedCustomStrategiesMap));
+ return combinedCustomStrategiesMap;
+ }
+
+ /**
+ * Wrap the strategy add function.
+ *
+ * @param type the accepted class type.
+ * @param strategy the acceptance strategy.
+ * @param strategyMap the acceptance strategy map.
+ */
+ private void addParameterAcceptStrategy(Class> type, BaseParameterAcceptStrategy> strategy, Map,
+ Set>> strategyMap) {
+ AssertUtil.nonNull(strategy, "The parameter acceptance strategy cannot be null.");
+ AssertUtil.nonNull(type, "The type of the " + strategy + " cannot be null.");
+ // Get the strategySet by clazz.
+ Set> strategySet = strategyMap.computeIfAbsent(type,
+ key -> new TreeSet<>(OrderUtil.descComparator()));
+ // Add the strategy to the set.
+ strategySet.add(strategy);
}
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BasicListParameterAcceptStrategy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BasicListParameterAcceptStrategy.java
new file mode 100644
index 0000000..9f43cab
--- /dev/null
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BasicListParameterAcceptStrategy.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin;
+
+import io.github.jidcoo.opto.lcdb.enhancer.base.BaseParameterAcceptStrategy;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Strategizable;
+import io.github.jidcoo.opto.lcdb.enhancer.core.parser.ParameterAcceptResult;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.*;
+
+import java.lang.reflect.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ *
BasicListParameterAcceptStrategy is a parameter
+ * acceptance strategy used to accept {@link java.util.List} type
+ * and accept it to a array as {@link java.util.List}
+ * instance.
+ *
+ * @author Jidcoo
+ * @see BaseParameterAcceptStrategy
+ * @since 1.0.3
+ */
+@Require
+@SuppressWarnings("rawtypes")
+public final class BasicListParameterAcceptStrategy extends BaseParameterAcceptStrategy {
+
+ /**
+ * Accept the object.
+ *
+ * @param object the object.
+ * @param type the parameter type.
+ * @param strategiesMap the strategies map that can be used during this accepting process.
+ *
The key is the output object class to which this BaseParameterAcceptStrategy
+ * applies. The value is a set of strategy with the same accepted type.
+ * And the set is sorted the priority of {@link Strategizable} based on
+ * {@code getOrder()}.
+ *
+ * @return the accepted parameter.
+ */
+ @Override
+ protected List> acceptParameter(Object object, Type type,
+ Map, Set>> strategiesMap) {
+ AssertUtil.nonNull(object, "The object cannot be null.");
+ AssertUtil.isTrue((object instanceof String || object instanceof List),
+ "The object is not a String object or a List object.");
+ Type elementType = TypeUtil.obtainListElementType(type);
+ Type elementRawType = TypeUtil.obtainRawTypeOfType(elementType);
+ List> originList = object instanceof List ? (List>) object : parseString2List((String) object);
+ if (elementRawType == Object.class) {
+ return originList;
+ }
+ return originList.stream().map(ele -> {
+ if (Objects.nonNull(ele) && ele.getClass().equals(elementRawType)) {
+ // Quick return.
+ return ele;
+ }
+ ParameterAcceptResult parameterAcceptResult = commonAcceptingFunction(strategiesMap, elementType, ele);
+ if (parameterAcceptResult.isAccepted()) {
+ return parameterAcceptResult.getObject();
+ }
+ String logBuf = "BasicListParameterAcceptStrategy: Cannot accept list ele: " +
+ ele +
+ ", ele-type: " +
+ elementType +
+ ": " +
+ parameterAcceptResult;
+ EnhancerLogUtil.logW("%s", logBuf);
+ throw new RuntimeException("Cannot accept list element: " + ele);
+ }).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the order of the object.
+ *
+ * @return the int order of the object.
+ */
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ /**
+ * Get the acceptable type.
+ *
+ * @return the acceptable type.
+ */
+ @Override
+ public Class extends List> getAcceptableType() {
+ return List.class;
+ }
+
+ private List> parseString2List(String string) {
+ AssertUtil.isTrue(!StringUtil.isBlank(string), "The string cannot be blank.");
+ return GsonUtil.fromJson(string, List.class);
+ }
+}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BinaryTreeParameterAcceptStrategy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BinaryTreeParameterAcceptStrategy.java
index d515cae..f50512d 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BinaryTreeParameterAcceptStrategy.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BinaryTreeParameterAcceptStrategy.java
@@ -16,13 +16,15 @@
package io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin;
+import com.google.gson.reflect.TypeToken;
import io.github.jidcoo.opto.lcdb.enhancer.base.BaseParameterAcceptStrategy;
import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
import io.github.jidcoo.opto.lcdb.enhancer.base.Strategizable;
import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import io.github.jidcoo.opto.lcdb.enhancer.core.parser.ParameterAcceptResult;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import java.lang.reflect.Parameter;
+import java.lang.reflect.Type;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -55,11 +57,18 @@ public final class BinaryTreeParameterAcceptStrategy extends BaseParameterAccept
* @return the accepted parameter.
*/
@Override
- protected TreeNode acceptParameter(Object object, Parameter type,
- Map, Set>> strategiesMap) throws Throwable {
+ protected TreeNode acceptParameter(Object object, Type type,
+ Map, Set>> strategiesMap) {
AssertUtil.nonNull(object, "The object cannot be null.");
- AssertUtil.isTrue((object instanceof List), "The object is not a List.");
- List originIntegerList = ((List) object);
+ ParameterAcceptResult acceptResult = commonAcceptingFunction(
+ strategiesMap,
+ TypeToken.getParameterized(List.class, Integer.class).getType(),
+ object
+ );
+ if (!acceptResult.isAccepted()) {
+ throw new RuntimeException("BinaryTreeParameterAcceptStrategy: Cannot accept object as a List object: " + acceptResult);
+ }
+ List originIntegerList = acceptResult.getObject();
if (originIntegerList.isEmpty()) {
return null;
}
@@ -70,7 +79,7 @@ protected TreeNode acceptParameter(Object object, Parameter type,
return new TreeNode(val);
};
List treeNodeList = originIntegerList.stream()
- .map(val -> treeNodeCreator.apply(val))
+ .map(treeNodeCreator)
.collect(Collectors.toList());
Queue nodeQueue = new ArrayDeque<>();
int treeNodeIdx = 0;
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/GodParameterAcceptStrategy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/GodParameterAcceptStrategy.java
index 0d88898..5bf61b0 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/GodParameterAcceptStrategy.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/GodParameterAcceptStrategy.java
@@ -22,7 +22,7 @@
import io.github.jidcoo.opto.lcdb.enhancer.utils.GsonUtil;
import javax.lang.model.type.NullType;
-import java.lang.reflect.Parameter;
+import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
@@ -62,12 +62,12 @@ public final class GodParameterAcceptStrategy extends BaseParameterAcceptStrateg
* @return the accepted parameter.
*/
@Override
- protected Object acceptParameter(Object object, Parameter type,
- Map, Set>> strategiesMap) throws Throwable {
+ protected Object acceptParameter(Object object, Type type,
+ Map, Set>> strategiesMap) {
// This can handle most situations!!!
// How magical!!!
// How beautiful the world is!!!
- return GsonUtil.fromJson(GsonUtil.toJson(object), type.getParameterizedType());
+ return GsonUtil.fromJson(GsonUtil.toJson(object), type);
}
/**
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/SinglyLinkedListParameterAcceptStrategy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/SinglyLinkedListParameterAcceptStrategy.java
index 13be2c5..a6017dc 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/SinglyLinkedListParameterAcceptStrategy.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/SinglyLinkedListParameterAcceptStrategy.java
@@ -16,13 +16,15 @@
package io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin;
+import com.google.gson.reflect.TypeToken;
import io.github.jidcoo.opto.lcdb.enhancer.base.BaseParameterAcceptStrategy;
import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
import io.github.jidcoo.opto.lcdb.enhancer.base.Strategizable;
import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import io.github.jidcoo.opto.lcdb.enhancer.core.parser.ParameterAcceptResult;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import java.lang.reflect.Parameter;
+import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -55,15 +57,24 @@ public final class SinglyLinkedListParameterAcceptStrategy extends BaseParameter
* @return the accepted parameter.
*/
@Override
- protected ListNode acceptParameter(Object object, Parameter type,
- Map, Set>> strategiesMap) throws Throwable {
+ protected ListNode acceptParameter(Object object, Type type,
+ Map, Set>> strategiesMap) {
AssertUtil.nonNull(object, "The object cannot be null.");
- AssertUtil.isTrue((object instanceof List), "The object is not a List.");
- List originIntegerList = ((List) object);
+ ParameterAcceptResult acceptResult = commonAcceptingFunction(
+ strategiesMap,
+ TypeToken.getParameterized(List.class, Integer.class).getType(),
+ object
+ );
+ if (!acceptResult.isAccepted()) {
+ throw new RuntimeException("SinglyLinkedListParameterAcceptStrategy: Cannot accept object as a List object: " + acceptResult);
+ }
+ List originIntegerList = acceptResult.getObject();
+ if (originIntegerList.isEmpty()) {
+ return null;
+ }
ListNode header = null;
ListNode last = null;
- for (int i = 0; i < originIntegerList.size(); i++) {
- Integer val = originIntegerList.get(i);
+ for (Integer val : originIntegerList) {
ListNode node = new ListNode(val);
if (header == null) header = node;
if (last != null) last.next = node;
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/DataStructureDesignScenePipelineRunner.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/DataStructureDesignScenePipelineRunner.java
index 86f1e55..96c3f96 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/DataStructureDesignScenePipelineRunner.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/DataStructureDesignScenePipelineRunner.java
@@ -23,9 +23,9 @@
import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeExecutorProcessor;
import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeInvokerFactory;
import io.github.jidcoo.opto.lcdb.enhancer.core.parser.InputParserProcessor;
-import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.DebugEnhancerProxy;
+import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.EnhancerProxyFactory;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
import java.util.*;
@@ -52,8 +52,8 @@ final class DataStructureDesignScenePipelineRunner extends PipelineRunner {
*/
@Require
List processOnDataStructureDesignScene(List operations, List> data) {
- AssertUtil.isTrue(!ContainerCheckUtil.isListEmpty(operations), "The operation list cannot be empty.");
- AssertUtil.isTrue(!ContainerCheckUtil.isListEmpty(data), "The data list cannot be empty.");
+ AssertUtil.isTrue(ContainerUtil.isNotEmpty(operations), "The operation list cannot be empty.");
+ AssertUtil.isTrue(ContainerUtil.isNotEmpty(data), "The data list cannot be empty.");
AssertUtil.isTrue(operations.size() == data.size(), "The size of lists operation and data is not equal.");
// Aware inner-class from leetcode executor.
Class> dataStructureKlass = (Class>) ReflectUtil.getFieldValue("instance", Object.class,
@@ -61,12 +61,12 @@ List processOnDataStructureDesignScene(List operations, List constructorInvokers = Arrays.stream(dataStructureKlass.getDeclaredConstructors())
- .map(LeetcodeInvokerFactory::getLeetcodeInvoker)
+ .map(constructor -> LeetcodeInvokerFactory.getLeetcodeInvoker(constructor, Integer.MAX_VALUE))
// Enable Friendly-Matching-Mode to ConstructorLeetcodeInvoker instance.
.peek(leetcodeInvoker -> ReflectUtil.setFieldValue("matchingFriendly", boolean.class, Boolean.TRUE, leetcodeInvoker))
.collect(Collectors.toList());
List methodInvokers = Arrays.stream(dataStructureKlass.getDeclaredMethods())
- .map(LeetcodeInvokerFactory::getLeetcodeInvoker)
+ .map(method -> LeetcodeInvokerFactory.getLeetcodeInvoker(method, Integer.MAX_VALUE))
.collect(Collectors.toList());
// Map invokerName -> List
Map> invokersMap = Stream.concat(constructorInvokers.stream(),
@@ -80,7 +80,7 @@ List processOnDataStructureDesignScene(List operations, List input = data.get(idx);
// Get candidate leetcode invokers by cur operation.
List leetcodeInvokers = invokersMap.get(operation);
- AssertUtil.isTrue(!ContainerCheckUtil.isListEmpty(leetcodeInvokers),
+ AssertUtil.isTrue(ContainerUtil.isNotEmpty(leetcodeInvokers),
"Cannot find any candidate leetcode invoker by operation: " + operation);
// Create a LeetcodeExecutor instance.
Object leetcodeExecutor = LeetcodeExecutorFactory.getLeetcodeExecutor(idx == 0 ? getEnhancer()
@@ -113,14 +113,9 @@ public int getOrder() {
return 0;
}
- /**
- * Get enhancer of this pipeline runner.
- *
- * @return enhancer.
- */
@Override
protected LeetcodeJavaDebugEnhancer getEnhancer() {
- // Return the origin enhancer.
- return DebugEnhancerProxy.awareSource(super.getEnhancer());
+ // Get the source instance.
+ return EnhancerProxyFactory.awareSourceEnhancer(super.getEnhancer());
}
}
\ No newline at end of file
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java
index 18bac33..e88aa55 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java
@@ -23,8 +23,10 @@
import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeInvokerFactory;
import io.github.jidcoo.opto.lcdb.enhancer.core.parser.InputParserProcessor;
import io.github.jidcoo.opto.lcdb.enhancer.core.printer.OutputPrinterProcessor;
+import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.EnhancerProxyFactory;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.BeanUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.OrderUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
import java.lang.reflect.Method;
@@ -124,7 +126,9 @@ final class LeetcodeJavaDebugEnhancerPipeline extends PipelineRunner {
klass -> klass.isAnnotationPresent(Require.class) && ReflectUtil.isExtendsClass(klass,
PipelineRunner.class) && !Modifier.isAbstract(klass.getModifiers()),
klass -> ReflectUtil.createInstance(klass))
- .stream().filter(Objects::nonNull).sorted(Comparator.comparingInt(Order::getOrder).reversed())
+ .stream()
+ .filter(Objects::nonNull)
+ .sorted(OrderUtil.descComparator())
.collect(Collectors.toList());
// Dispatch each builtinPipelineRunner into the pipelineRunnerMap.
for (PipelineRunner builtinPipelineRunner : builtinPipelineRunners) {
@@ -135,7 +139,7 @@ final class LeetcodeJavaDebugEnhancerPipeline extends PipelineRunner {
continue;
}
// Create a LeetcodeInvoker instance by the candidateMethod.
- LeetcodeInvoker leetcodeInvoker = LeetcodeInvokerFactory.getLeetcodeInvoker(candidateMethod);
+ LeetcodeInvoker leetcodeInvoker = LeetcodeInvokerFactory.getLeetcodeInvoker(candidateMethod, Integer.MIN_VALUE);
// Add leetcodeInvoker to pipelineRunnerInvokers list.
pipelineRunnerInvokers.add(leetcodeInvoker);
// Map leetcodeInvoker's id -> pipelineRunner owner.
@@ -156,7 +160,7 @@ void run() {
if (inputProvider.isEnd(input)) {
break;
}
- Object bossLeetcodeExecutor = leetcodeExecutor;
+ Object bossLeetcodeExecutor = LeetcodeExecutorFactory.copyByLeetcodeExecutor(leetcodeExecutor);
// Do enhance before input parsing.
bossLeetcodeExecutor = doEnhanceBeforeInputParseProcess(bossLeetcodeExecutor);
// Parse the string input to input object.
@@ -203,6 +207,8 @@ private Object doEnhanceBeforeInputParseProcess(Object bossLeetcodeExecutor) {
* @return the final leetcode executor.
*/
private Object doEnhanceAfterInputParseProcess(Object bossLeetcodeExecutor) {
+ createLeetcodeInstanceIfNecessary(bossLeetcodeExecutor);
+
// Aware leetcode invoker from the bossLeetcodeExecutor.
LeetcodeInvoker leetcodeInvoker = ReflectUtil.getFieldValue("executor", LeetcodeInvoker.class,
bossLeetcodeExecutor);
@@ -225,6 +231,59 @@ private Object doEnhanceAfterInputParseProcess(Object bossLeetcodeExecutor) {
return finalLeetcodeExecutor;
}
+ /**
+ * Try to create leetcode solution instance by bossLeetcodeExecutor.
+ *
+ * @param bossLeetcodeExecutor
+ */
+ private void createLeetcodeInstanceIfNecessary(Object bossLeetcodeExecutor) {
+ Object instance = ReflectUtil.getFieldValue("instance", Object.class, bossLeetcodeExecutor);
+ if (!(instance instanceof Class>)) {
+ return;
+ }
+ Class> solutionClass = (Class>) instance;
+ if (ReflectUtil.isImplementInterface(solutionClass, LeetcodeJavaDebugEnhancer.class)) {
+ return;
+ }
+ if (Modifier.isAbstract(solutionClass.getModifiers())) {
+ return;
+ }
+ if (!solutionClass.getSimpleName().contains("Solution")) {
+ return;
+ }
+ LeetcodeInvoker leetcodeInvoker = ReflectUtil.getFieldValue("executor", LeetcodeInvoker.class,
+ bossLeetcodeExecutor);
+ if (!leetcodeInvoker.isSuitable(solutionClass)) {
+ return;
+ }
+ Class> enclosingClass = solutionClass.getEnclosingClass();
+ if (Objects.isNull(enclosingClass) || Modifier.isStatic(solutionClass.getModifiers())) {
+ ReflectUtil.setFieldValue(
+ "instance",
+ Object.class,
+ ReflectUtil.createInstance(solutionClass),
+ bossLeetcodeExecutor
+ );
+ return;
+ }
+ if (Objects.nonNull(enclosingClass.getEnclosingClass())) {
+ return;
+ }
+ if (!ReflectUtil.isImplementInterface(enclosingClass, LeetcodeJavaDebugEnhancer.class)) {
+ return;
+ }
+ ReflectUtil.setFieldValue(
+ "instance",
+ Object.class,
+ ReflectUtil.createInstance(
+ solutionClass,
+ new Class[]{enclosingClass},
+ EnhancerProxyFactory.awareSourceEnhancer(getEnhancer())
+ ),
+ bossLeetcodeExecutor
+ );
+ }
+
/**
* Set up pipeline runner with this current pipeline instance.
*
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipelineProcessor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipelineProcessor.java
index cfd2124..dff54cd 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipelineProcessor.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipelineProcessor.java
@@ -20,16 +20,10 @@
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.executor.LeetcodeExecutorFactory;
-import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeInvokerFactory;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.IOFactory;
import io.github.jidcoo.opto.lcdb.enhancer.core.parser.InputParserFactory;
import io.github.jidcoo.opto.lcdb.enhancer.core.printer.OutputPrinterFactory;
-import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.DebugEnhancerProxy;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
-
-import java.lang.reflect.Method;
-import java.util.Objects;
/**
*
LeetcodeJavaDebugEnhancerPipelineProcessor is a publicly
@@ -60,8 +54,12 @@ public final class LeetcodeJavaDebugEnhancerPipelineProcessor {
public static void process(LeetcodeJavaDebugEnhancer enhancer) throws Exception, Error {
// Check NPE.
AssertUtil.nonNull(enhancer, "The enhancer cannot be null.");
+
+ Class> payload = enhancer.getEnhancerPayload();
+ AssertUtil.nonNull(payload, "The enhancer payload cannot be null.");
+
// Create a LeetcodeExecutor from the enhancer.
- Object leetcodeExecutor = createBootstrapLeetcodeExecutor(enhancer);
+ Object leetcodeExecutor = LeetcodeExecutorFactory.getLeetcodeExecutor(payload);
// Create an OutputPrinter from the enhancer.
Object outputPrinter = OutputPrinterFactory.getOutputPrinter(enhancer);
// Create a InputParser from the enhancer.
@@ -82,40 +80,4 @@ public static void process(LeetcodeJavaDebugEnhancer enhancer) throws Exception,
}
}
-
- /**
- * Create a bootstrap leetcode executor instance by enhancer.
- *
- * @param enhancer the LeetcodeJavaDebugEnhancer instance.
- * @return the leetcode executor instance.
- */
- private static Object createBootstrapLeetcodeExecutor(LeetcodeJavaDebugEnhancer enhancer) {
- // At first, if the enhancement point from the enhancer is not null,
- // we will prioritize using it.
- final LeetcodeJavaDebugEnhancer __enhancer__ = enhancer;
- enhancer = DebugEnhancerProxy.awareSource(__enhancer__);
- Method enhancementPoint;
- if (Objects.nonNull((enhancementPoint = __enhancer__.getEnhancementPoint()))) {
- return LeetcodeExecutorFactory.getLeetcodeExecutor(enhancer,
- LeetcodeInvokerFactory.getLeetcodeInvoker(enhancementPoint));
- }
-
- // Then, we will try to resolve all first level INNER-CLASS in AT.
- Class>[] innerClasses = ReflectUtil.resolveInnerClasses(enhancer.getClass());
- // The innerClasses length must be greater than zero.
- AssertUtil.isTrue(innerClasses.length > 0, "Cannot resolve any inner class from the AT instance.");
- // Unfortunately, we are currently unable to handle situations where
- // there are multiple INNER-CLASS in AT.
- AssertUtil.isTrue(innerClasses.length < 2, "Multiple inner classes were found in AT instance. There can only be one inner class in AT instance.");
- // Use this only inner class as an instance of leetcode executor.
- Class> bossInnerClassInstance = innerClasses[0];
- // If the name of bossInnerClassInstance is "Solution",
- // then we only need to instantiate the class.
- if ("Solution".equals(bossInnerClassInstance.getSimpleName())) {
- return LeetcodeExecutorFactory.getLeetcodeExecutor(ReflectUtil.createInstance(bossInnerClassInstance,
- new Class[]{enhancer.getClass()}, enhancer));
- }
- // Create a leetcode executor by bossInnerClassInstance and return it.
- return LeetcodeExecutorFactory.getLeetcodeExecutor(bossInnerClassInstance);
- }
}
\ No newline at end of file
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinter.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinter.java
index 2557961..a81db5d 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinter.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinter.java
@@ -20,7 +20,7 @@
import io.github.jidcoo.opto.lcdb.enhancer.base.Strategizable;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.GsonUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.base.Order;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.OrderUtil;
import javax.lang.model.type.NullType;
import java.util.*;
@@ -72,15 +72,13 @@ final class OutputPrinter extends BasePrintingStrategy {
printingStrategyList.add(this);
// Filter out all null object.
printingStrategyList = printingStrategyList.stream().filter(Objects::nonNull).collect(Collectors.toList());
- // Define the PrintingStrategy Comparator.
- Comparator printingStrategyComparator = Comparator.comparingInt(Order::getOrder).reversed();
// Wrap the printingStrategyMap build process as a BiConsumer.
BiConsumer, BasePrintingStrategy>> mapBuilder = (Class> clazz,
BasePrintingStrategy> printingStrategy) -> {
AssertUtil.nonNull(clazz, "The accepted type of the " + printingStrategy + " cannot be null.");
// Get the strategySet by clazz.
Set> strategySet = printingStrategyMap.computeIfAbsent(clazz,
- key -> new TreeSet<>(printingStrategyComparator));
+ key -> new TreeSet<>(OrderUtil.descComparator()));
// Add the printingStrategy to the set.
strategySet.add(printingStrategy);
};
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinterFactory.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinterFactory.java
index 6ad16f9..63911ab 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinterFactory.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/printer/OutputPrinterFactory.java
@@ -21,7 +21,7 @@
import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.BeanUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
import java.lang.reflect.Modifier;
@@ -61,7 +61,7 @@ public static OutputPrinter getOutputPrinter(LeetcodeJavaDebugEnhancer enhancer)
(Class extends BasePrintingStrategy> beanType) -> ReflectUtil.createInstance(beanType))
.stream().filter(Objects::nonNull).collect(Collectors.toList());
// Add all enhancer's printStrategies to the list.
- if (!ContainerCheckUtil.isListEmpty(enhancer.getOutputPrintStrategies())) {
+ if (ContainerUtil.isNotEmpty(enhancer.getOutputPrintStrategies())) {
builtinOutputPrintStrategies.addAll(enhancer.getOutputPrintStrategies());
}
return new OutputPrinter(builtinOutputPrintStrategies);
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/DebugEnhancerProxy.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/DebugEnhancerProxy.java
deleted file mode 100644
index b21352b..0000000
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/DebugEnhancerProxy.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (C) 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.
- */
-
-package io.github.jidcoo.opto.lcdb.enhancer.core.proxy;
-
-import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
-import io.github.jidcoo.opto.lcdb.enhancer.base.*;
-import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeInvokerFactory;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.StringUtil;
-
-import java.lang.reflect.Method;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.stream.Collectors;
-
-/**
- *
DebugEnhancerProxy is a static proxy class
- * used to enhance and intercept the functionality of
- * {@link LeetcodeJavaDebugEnhancer}.
- *
- *
In versions 1.0.2 and later, all new feature
- * implementations will be based on it.
- * DebugEnhancerProxy intercepts and processes methods
- * with {@link ProxyPoint} as an enhanced granularity.
- *
- * @author Jidcoo
- * @see LeetcodeJavaDebugEnhancer
- * @see ProxyPointInterceptor
- * @see ProxyPointInterceptorManager
- * @since 1.0.2
- */
-public final class DebugEnhancerProxy extends LeetcodeJavaDebugEnhancer {
-
- /**
- * No param proxy point type.
- */
- private static final Class>[] DEFAULT_NO_PARAM_TYPE = new Class[]{};
-
- /**
- * Proxy method points map.
- */
- private final Map PROXY_POINTS_MAP = Arrays.asList(
- new ProxyPoint("getEnhancementPoint", DEFAULT_NO_PARAM_TYPE),
- new ProxyPoint("getInputProvider", DEFAULT_NO_PARAM_TYPE),
- new ProxyPoint("getOutputConsumer", DEFAULT_NO_PARAM_TYPE),
- new ProxyPoint("getOutputPrintStrategies", DEFAULT_NO_PARAM_TYPE),
- new ProxyPoint("getEnhancerLogLevel", DEFAULT_NO_PARAM_TYPE)
- ).stream().collect(Collectors.toMap(ProxyPoint::getPointName, proxyPoint -> proxyPoint));
-
- /**
- * Proxy point instances map.
- */
- private Map proxyPointInstancesMap;
-
- /**
- * ProxyPointInterceptor manager.
- */
- private ProxyPointInterceptorManager proxyPointInterceptorManager;
-
- /**
- * The LeetcodeJavaDebugEnhancer target.
- */
- private final LeetcodeJavaDebugEnhancer target;
-
- /**
- * Create a DebugEnhancerProxy instance.
- *
- * @param target The LeetcodeJavaDebugEnhancer target.
- */
- public DebugEnhancerProxy(LeetcodeJavaDebugEnhancer target) {
- AssertUtil.nonNull(target, "The LeetcodeJavaDebugEnhancer target cannot be null.");
- Class> targetClass = target.getClass();
- proxyPointInstancesMap = new HashMap<>();
- proxyPointInterceptorManager = new ProxyPointInterceptorManager(PROXY_POINTS_MAP.keySet());
- PROXY_POINTS_MAP.forEach((proxyPointName, proxyPoint) -> proxyPointInstancesMap.put(proxyPointName,
- proxyPoint.findPoint(targetClass)));
- this.target = target;
- }
-
- /**
- * Do real proxy point invoke.
- *
- * @param pointName the proxy point name.
- * @param returnType the return type.
- * @param args invoke args.
- * @return final proxy invoke result.
- */
- private RETURN proxyPointInvoke(String pointName, Class returnType, Object... args) {
- ProxyPoint proxyPoint = PROXY_POINTS_MAP.getOrDefault(pointName, null);
- AssertUtil.nonNull(proxyPoint, "Cannot found the proxy point: " + pointName);
- LeetcodeInvoker proxyPointInvoker = proxyPointInstancesMap.getOrDefault(pointName, null);
- AssertUtil.nonNull(proxyPointInvoker, "Cannot found the proxy point invoker: " + pointName);
- ProxyPointParameterView parameterView = new ProxyPointParameterView(proxyPoint.getParamTypes(), args);
- Object result;
- try {
- proxyPointInterceptorManager.doInterceptOnBefore(this, pointName, parameterView);
- result = proxyPointInvoker.invoke(target, args);
- return returnType.cast(proxyPointInterceptorManager.doInterceptOnAfter(this, pointName, result));
- } catch (Throwable throwable) {
- throw new EnhancerException("proxy invoke error: " + throwable.getMessage(), throwable);
- }
- }
-
- /**
- * Return the LeetcodeJavaDebugEnhancer target.
- *
- * @return the LeetcodeJavaDebugEnhancer target.
- */
- public LeetcodeJavaDebugEnhancer getTarget() {
- return target;
- }
-
- /**
- * Return the source enhancer from the special LeetcodeJavaDebugEnhancer instance.
- *
- * @param enhancer the LeetcodeJavaDebugEnhancer instance.
- * @return the source LeetcodeJavaDebugEnhancer instance.
- */
- public static LeetcodeJavaDebugEnhancer awareSource(LeetcodeJavaDebugEnhancer enhancer) {
- if (Objects.isNull(enhancer)) {
- return null;
- }
- if (enhancer instanceof DebugEnhancerProxy) {
- return ((DebugEnhancerProxy) enhancer).getTarget();
- }
- return enhancer;
- }
-
- /**
- * ProxyPoint is a method point that describes
- * the need to wrap around a proxy.
- */
- private final class ProxyPoint {
-
- private final String pointName;
-
- private final Class>[] paramTypes;
-
- ProxyPoint(String pointName, Class>[] paramTypes) {
- AssertUtil.isTrue(!StringUtil.isBlank(pointName), "The proxy point name cannot be blank.");
- AssertUtil.nonNull(paramTypes, "The proxy point param types cannot be null.");
- this.pointName = pointName;
- this.paramTypes = paramTypes;
- }
-
- String getPointName() {
- return pointName;
- }
-
- Class>[] getParamTypes() {
- return paramTypes;
- }
-
- LeetcodeInvoker findPoint(Class> klass) {
- AssertUtil.nonNull(klass, "The class cannot be null.");
- try {
- return LeetcodeInvokerFactory.getLeetcodeInvoker(ReflectUtil.getMethod(klass, this.pointName,
- this.paramTypes));
- } catch (Exception e) {
- e.printStackTrace();
- throw new EnhancerException("Cannot found proxy point in class " + klass.getSimpleName() + ", point " + "name is " + this.pointName + ", param type is " + Arrays.toString(paramTypes) + ".");
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- ProxyPoint that = (ProxyPoint) o;
- return Objects.equals(pointName, that.pointName) && Arrays.equals(paramTypes, that.paramTypes);
- }
-
- @Override
- public int hashCode() {
- int result = Objects.hash(pointName);
- result = 31 * result + Arrays.hashCode(paramTypes);
- return result;
- }
- }
-
- /*************** STATIC PROXY FUNCTIONS START***************/
-
- /**
- * Static proxy on method :
- * getEnhancementPoint().
- *
- * @return the enhancement point.
- */
- @Override
- public Method getEnhancementPoint() {
- return proxyPointInvoke("getEnhancementPoint", Method.class);
- }
-
- /**
- * Static proxy on method :
- * getInputProvider().
- *
- * @return the input provider.
- */
- @Override
- public InputProvider getInputProvider() {
- return proxyPointInvoke("getInputProvider", InputProvider.class);
- }
-
- /**
- * Static proxy on method :
- * getOutputConsumer().
- *
- * @return the output consumer.
- */
- @Override
- public OutputConsumer getOutputConsumer() {
- return proxyPointInvoke("getOutputConsumer", OutputConsumer.class);
- }
-
- /**
- * Static proxy on method :
- * getOutputPrintStrategies().
- *
- * @return the output print strategies list.
- */
- @Override
- public List> getOutputPrintStrategies() {
- return proxyPointInvoke("getOutputPrintStrategies", List.class);
- }
-
- /**
- * Static proxy on method :
- * getEnhancerLogLevel().
- *
- * @return the enhancer log level.
- */
- @Override
- public Level getEnhancerLogLevel() {
- return proxyPointInvoke("getEnhancerLogLevel", Level.class);
- }
-
- /*************** STATIC PROXY FUNCTIONS END***************/
-}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyFactory.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyFactory.java
new file mode 100644
index 0000000..46e62d6
--- /dev/null
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyFactory.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.core.proxy;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.Objects;
+
+/**
+ *
EnhancerProxyFactory is a factory class
+ * to product the {@link LeetcodeJavaDebugEnhancer} instance proxy.
+ *
+ * @author Jidcoo
+ * @since 1.0.3
+ */
+public class EnhancerProxyFactory {
+
+ /**
+ * Create A LeetcodeJavaDebugEnhancer instance proxy by AT Class.
+ *
+ * @param AT the AT class.
+ * @return LeetcodeJavaDebugEnhancer instance proxy.
+ */
+ public static LeetcodeJavaDebugEnhancer createEnhancerProxy(Class extends LeetcodeJavaDebugEnhancer> AT) {
+ AssertUtil.nonNull(AT, "The AT class cannot be null.");
+ return (LeetcodeJavaDebugEnhancer) Proxy.newProxyInstance(
+ AT.getClassLoader(),
+ new Class[]{LeetcodeJavaDebugEnhancer.class},
+ new EnhancerProxyHandler(ReflectUtil.createInstance(AT))
+ );
+ }
+
+ /**
+ * Aware source LeetcodeJavaDebugEnhancer from the specific LeetcodeJavaDebugEnhancer instance.
+ *
+ * @param enhancer the specific LeetcodeJavaDebugEnhancer instance.
+ * @return the source LeetcodeJavaDebugEnhancer instance.
+ */
+ public static LeetcodeJavaDebugEnhancer awareSourceEnhancer(LeetcodeJavaDebugEnhancer enhancer) {
+ if (Objects.isNull(enhancer)) {
+ return null;
+ }
+ if (!Proxy.isProxyClass(enhancer.getClass())) {
+ return enhancer;
+ }
+ InvocationHandler invocationHandler = Proxy.getInvocationHandler(enhancer);
+ if (invocationHandler instanceof EnhancerProxyHandler) {
+ return awareSourceEnhancer(((EnhancerProxyHandler) invocationHandler).getTarget());
+ }
+ // enhancer is a proxy instance but the invocationHandler is not an EnhancerProxyHandler instance.
+ return null;
+ }
+}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyHandler.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyHandler.java
new file mode 100644
index 0000000..e28b840
--- /dev/null
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyHandler.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.core.proxy;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.base.EnhancerException;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
+
+/**
+ *
EnhancerProxyHandler is a proxy invocation handler
+ * used for enhancing {@link LeetcodeJavaDebugEnhancer}
+ * agents.
+ *
+ *
In versions 1.0.3 and later, all new feature
+ * implementations will be based on {@link EnhancerProxyHandler}.
+ *
+ * @author Jidcoo
+ * @see LeetcodeJavaDebugEnhancer
+ * @see ProxyPointInterceptorManager
+ * @since 1.0.3
+ */
+final class EnhancerProxyHandler implements InvocationHandler {
+
+ /**
+ * The LeetcodeJavaDebugEnhancer target.
+ */
+ private final LeetcodeJavaDebugEnhancer target;
+
+ /**
+ * ProxyPointInterceptor manager.
+ */
+ private ProxyPointInterceptorManager proxyPointInterceptorManager;
+
+ /**
+ * Create an EnhancerProxyHandler instance.
+ *
+ * @param enhancer The LeetcodeJavaDebugEnhancer instance.
+ */
+ EnhancerProxyHandler(LeetcodeJavaDebugEnhancer enhancer) {
+ AssertUtil.nonNull(enhancer, "The LeetcodeJavaDebugEnhancer instance cannot be null.");
+ this.target = enhancer;
+ this.proxyPointInterceptorManager = new ProxyPointInterceptorManager();
+ }
+
+ /**
+ * Return the LeetcodeJavaDebugEnhancer target.
+ *
+ * @return the LeetcodeJavaDebugEnhancer target.
+ */
+ LeetcodeJavaDebugEnhancer getTarget() {
+ return target;
+ }
+
+ /**
+ * Processes a method invocation on a proxy instance and returns
+ * the result. This method will be invoked on an invocation handler
+ * when a method is invoked on a proxy instance that it is
+ * associated with.
+ *
+ * @param proxy the proxy instance that the method was invoked on
+ * @param method the {@code Method} instance corresponding to
+ * the interface method invoked on the proxy instance. The declaring
+ * class of the {@code Method} object will be the interface that
+ * the method was declared in, which may be a superinterface of the
+ * proxy interface that the proxy class inherits the method through.
+ * @param args an array of objects containing the values of the
+ * arguments passed in the method invocation on the proxy instance,
+ * or {@code null} if interface method takes no arguments.
+ * Arguments of primitive types are wrapped in instances of the
+ * appropriate primitive wrapper class, such as
+ * {@code java.lang.Integer} or {@code java.lang.Boolean}.
+ * @return the value to return from the method invocation on the
+ * proxy instance. If the declared return type of the interface
+ * method is a primitive type, then the value returned by
+ * this method must be an instance of the corresponding primitive
+ * wrapper class; otherwise, it must be a type assignable to the
+ * declared return type. If the value returned by this method is
+ * {@code null} and the interface method's return type is
+ * primitive, then a {@code NullPointerException} will be
+ * thrown by the method invocation on the proxy instance. If the
+ * value returned by this method is otherwise not compatible with
+ * the interface method's declared return type as described above,
+ * a {@code ClassCastException} will be thrown by the method
+ * invocation on the proxy instance.
+ * @throws Throwable the exception to throw from the method
+ * invocation on the proxy instance. The exception's type must be
+ * assignable either to any of the exception types declared in the
+ * {@code throws} clause of the interface method or to the
+ * unchecked exception types {@code java.lang.RuntimeException}
+ * or {@code java.lang.Error}. If a checked exception is
+ * thrown by this method that is not assignable to any of the
+ * exception types declared in the {@code throws} clause of
+ * the interface method, then an
+ * {@link UndeclaredThrowableException} containing the
+ * exception that was thrown by this method will be thrown by the
+ * method invocation on the proxy instance.
+ * @see UndeclaredThrowableException
+ */
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return proxyPointInvoke(proxy, method, args);
+ }
+
+ /**
+ * Do real proxy point invoke.
+ *
+ * @param proxy the proxy instance.
+ * @param point the proxy method point.
+ * @param args invoke args.
+ * @return final proxy invoke result.
+ */
+ private Object proxyPointInvoke(Object proxy, Method point, Object... args) {
+ LeetcodeJavaDebugEnhancer enhancer = (LeetcodeJavaDebugEnhancer) proxy;
+ String pointName = point.getName();
+ ProxyPointParameterView parameterView = new ProxyPointParameterView(point.getParameterTypes(), args);
+ Object result;
+ try {
+ proxyPointInterceptorManager.doInterceptOnBefore(enhancer, pointName, parameterView);
+ result = point.invoke(target, args);
+ return proxyPointInterceptorManager.doInterceptOnAfter(enhancer, pointName, result);
+ } catch (Throwable throwable) {
+ throw new EnhancerException("proxy invoke error: " + throwable.getMessage(), throwable);
+ }
+ }
+}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java
index 1799b88..e07d00b 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java
@@ -17,7 +17,6 @@
package io.github.jidcoo.opto.lcdb.enhancer.core.proxy;
import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
-import io.github.jidcoo.opto.lcdb.enhancer.base.Order;
import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
import io.github.jidcoo.opto.lcdb.enhancer.utils.*;
@@ -30,14 +29,16 @@
* manager.
*
*
It will scan all possible {@link ProxyPointInterceptor}
- * for the {@link DebugEnhancerProxy} proxy point surround
+ * for the {@link LeetcodeJavaDebugEnhancer} proxy point surround
* interception processing.
*
* @author Jidcoo
* @see ProxyPointInterceptor
- * @see DebugEnhancerProxy
+ * @see LeetcodeJavaDebugEnhancer
+ * @see EnhancerProxyHandler
* @since 1.0.2
*/
+@SuppressWarnings(value = {"rawtypes", "unchecked"})
final class ProxyPointInterceptorManager {
/**
@@ -52,11 +53,8 @@ final class ProxyPointInterceptorManager {
/**
* Create a ProxyPointInterceptorManager instance.
- *
- * @param allowedProxyPointsSet the all allowed proxy points set.
*/
- ProxyPointInterceptorManager(Set allowedProxyPointsSet) {
- AssertUtil.nonNull(allowedProxyPointsSet, "The allowed proxy points set cannot be null.");
+ ProxyPointInterceptorManager() {
// init all proxy point interceptors.
proxyPointInterceptorsMap = BeanUtil.collectBeans(ProxyPointInterceptor.class, PROXY_POINT_INTERCEPTOR_SCANNER_BASE_PACKAGE,
(Class type) -> {
@@ -69,19 +67,12 @@ final class ProxyPointInterceptorManager {
Require requireAnnotation = (Require) type.getAnnotation(Require.class);
return requireAnnotation.types().length > 0 && ProxyPointInterceptor.class.equals(requireAnnotation.types()[0]);
},
- (Class extends ProxyPointInterceptor> beanType) -> {
- ProxyPointInterceptor interceptor = ReflectUtil.createInstance(beanType);
- if (allowedProxyPointsSet.contains(interceptor.interceptPoint())) {
- return interceptor;
- }
- EnhancerLogUtil.logW("Invalid interceptor, detected a disallowed intercept-proxy-point: " + interceptor.interceptPoint());
- return null;
- }
+ ReflectUtil::createInstance
).stream().filter(Objects::nonNull).collect(
Collectors.groupingBy(ProxyPointInterceptor::interceptPoint,
Collectors.collectingAndThen(Collectors.toList(),
list -> {
- list.sort(Comparator.comparingInt(Order::getOrder).reversed());
+ OrderUtil.descSort(list);
return list;
}
)));
@@ -95,13 +86,12 @@ final class ProxyPointInterceptorManager {
* @param pointName the proxy point name.
* @param parameterView the proxy point parameter view.
*/
- @SuppressWarnings("unchecked")
public void doInterceptOnBefore(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhancer,
String pointName, ProxyPointParameterView parameterView) {
AssertUtil.isTrue(!StringUtil.isBlank(pointName), "The proxy point name cannot be blank.");
AssertUtil.nonNull(parameterView, "The proxy point parameter view cannot be null.");
List interceptors = proxyPointInterceptorsMap.getOrDefault(pointName, null);
- if (ContainerCheckUtil.isListEmpty(interceptors)) {
+ if (ContainerUtil.isEmpty(interceptors)) {
return;
}
for (ProxyPointInterceptor interceptor : interceptors) {
@@ -123,7 +113,7 @@ public Object doInterceptOnAfter(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnha
String pointName, Object o) {
AssertUtil.isTrue(!StringUtil.isBlank(pointName), "The proxy point name cannot be blank.");
List interceptors = proxyPointInterceptorsMap.getOrDefault(pointName, null);
- if (!ContainerCheckUtil.isListEmpty(interceptors)) {
+ if (ContainerUtil.isNotEmpty(interceptors)) {
for (ProxyPointInterceptor interceptor : interceptors) {
o = interceptor.onAfter(leetcodeJavaDebugEnhancer, o);
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointParameterView.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointParameterView.java
index d10c98c..bfe029e 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointParameterView.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointParameterView.java
@@ -48,6 +48,8 @@ public final class ProxyPointParameterView {
*/
private final int size;
+ static final Object[] DEFAULT_NO_PARAM = new Object[0];
+
/**
* Create a ProxyPointParameterView instance.
*
@@ -56,7 +58,7 @@ public final class ProxyPointParameterView {
*/
public ProxyPointParameterView(Class>[] types, Object[] params) {
AssertUtil.nonNull(types, "The param types cannot be null.");
- AssertUtil.nonNull(types, "The params cannot be null.");
+ if (Objects.isNull(params)) params = DEFAULT_NO_PARAM;
AssertUtil.isTrue(types.length == params.length, "The length of param types does not match the length of the "
+ "params.");
this.types = types;
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/payload/EnhancerPayloadInterceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/payload/EnhancerPayloadInterceptor.java
new file mode 100644
index 0000000..049720b
--- /dev/null
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/payload/EnhancerPayloadInterceptor.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.func.payload;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.EnhancerProxyFactory;
+import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.ProxyPointInterceptor;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.EnhancerLogUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;
+
+import java.util.Objects;
+
+/**
+ *
EnhancerPayloadInterceptor is a proxy-point
+ * interceptor used to resolve inner "Solution" class
+ * from AT class as enhancer payload.
+ *
+ * @author Jidcoo
+ * @see LeetcodeJavaDebugEnhancer#getEnhancerPayload()
+ * @see ProxyPointInterceptor
+ * @since 1.0.3
+ */
+@Require(types = ProxyPointInterceptor.class)
+final class EnhancerPayloadInterceptor implements ProxyPointInterceptor> {
+
+ /**
+ * Get the order of the object.
+ *
+ * @return the int order of the object.
+ */
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ /**
+ * Return the proxy point name that needs to
+ * be intercepted.
+ *
+ * @return the proxy point name.
+ */
+ @Override
+ public String interceptPoint() {
+ return "getEnhancerPayload";
+ }
+
+ /**
+ * Intercept and process proxy point result
+ * after invoking proxy point.
+ *
+ * @param leetcodeJavaDebugEnhancer the LeetcodeJavaDebugEnhancer instance.
+ * @param aClass the proxy point result.
+ * @return the processed proxy point result.
+ */
+ @Override
+ public Class> onAfter(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhancer, Class> aClass) {
+ if (Objects.nonNull(aClass)) {
+ return aClass;
+ }
+ // Try to load inner class from AT instance.
+ LeetcodeJavaDebugEnhancer target = EnhancerProxyFactory.awareSourceEnhancer(leetcodeJavaDebugEnhancer);
+ if (Objects.isNull(target)) {
+ EnhancerLogUtil.logW("EnhancerPayloadInterceptor: cannot aware source enhancer from the AT instance.");
+ return null;
+ }
+ Class>[] innerClasses = ReflectUtil.resolveInnerClasses(target.getClass());
+ if (innerClasses.length == 0) {
+ EnhancerLogUtil.logW("EnhancerPayloadInterceptor: cannot resolve any inner class from the AT instance.");
+ return null;
+ }
+ // Unfortunately, we are currently unable to handle situations where
+ // there are multiple INNER-CLASS in AT.
+ if (innerClasses.length > 1) {
+ EnhancerLogUtil.logW("EnhancerPayloadInterceptor: multiple inner classes were found in AT instance, there" +
+ " can only be one inner class in AT instance.");
+ return null;
+ }
+ // Use this only inner class as an instance of leetcode executor.
+ return innerClasses[0];
+ }
+}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/AbsIORequireSupporter.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/AbsIORequireSupporter.java
index 06afd5a..bcc23e9 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/AbsIORequireSupporter.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/AbsIORequireSupporter.java
@@ -20,9 +20,9 @@
import io.github.jidcoo.opto.lcdb.enhancer.base.EnhancerException;
import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
import io.github.jidcoo.opto.lcdb.enhancer.base.Requires;
-import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.DebugEnhancerProxy;
+import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.EnhancerProxyFactory;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.EnhancerLogUtil;
import java.util.*;
@@ -98,7 +98,7 @@ protected IO_SOURCE generateIOSource(String source, Class extends IO_SOURCE> t
*/
@SuppressWarnings("all")
protected List awareAcceptableIOSourceRequire(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhancer) {
- LeetcodeJavaDebugEnhancer source = DebugEnhancerProxy.awareSource(leetcodeJavaDebugEnhancer);
+ LeetcodeJavaDebugEnhancer source = EnhancerProxyFactory.awareSourceEnhancer(leetcodeJavaDebugEnhancer);
AssertUtil.nonNull(source, "The leetcodeJavaDebugEnhancer cannot be null.");
Class> sourceKlass = source.getClass();
Requires requiresAnnotation = sourceKlass.getAnnotation(Requires.class);
@@ -118,7 +118,7 @@ protected List awareAcceptableIOSourceRequire(LeetcodeJavaDebugEnhancer
}
for (Class> type : types) {
if (!ACCEPTABLE_IO_SOURCE_TYPES.containsKey(type)) {
- EnhancerLogUtil.logW("Unaccepted io source type in IO-Require-Annotation(types are %s, values are" +
+ EnhancerLogUtil.logW("AbsIORequireSupporter: unaccepted io source type in IO-Require-Annotation(types are %s, values are" +
" %s): %s",
Arrays.toString(types), Arrays.toString(require.values()), type.getSimpleName());
return false;
@@ -129,9 +129,9 @@ protected List awareAcceptableIOSourceRequire(LeetcodeJavaDebugEnhancer
int typesLength = require.types().length;
int valuesLength = require.values().length;
if (typesLength > 1 && typesLength > valuesLength) {
- EnhancerLogUtil.logW("Invalid types-length(%d) and values-length(%d) in IO-Require-Annotation(types " +
+ EnhancerLogUtil.logW("AbsIORequireSupporter: invalid types-length(%d) and values-length(%d) in IO-Require-Annotation(types " +
"are %s, values are %s): " +
- "Only supports single type and multi value or types and values with the same length.",
+ "only supports single type and multi value or types and values with the same length.",
typesLength, valuesLength, Arrays.toString(require.types()), Arrays.toString(require.values()));
return false;
}
@@ -149,7 +149,7 @@ protected List awareAcceptableIOSourceRequire(LeetcodeJavaDebugEnhancer
protected final List awareIOSources(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhancer) {
List requireList = awareAcceptableIOSourceRequire(leetcodeJavaDebugEnhancer);
List ioSourceList = new ArrayList<>();
- if (!ContainerCheckUtil.isListEmpty(requireList)) {
+ if (ContainerUtil.isNotEmpty(requireList)) {
for (Require require : requireList) {
Class>[] types = require.types();
String[] values = require.values();
@@ -168,7 +168,7 @@ protected final List awareIOSources(LeetcodeJavaDebugEnhancer leetcod
return generateIOSource(source, ioSourceType);
}).filter(Objects::nonNull).collect(Collectors.toList());
}
- if (!ContainerCheckUtil.isListEmpty(curSources)) {
+ if (ContainerUtil.isNotEmpty(curSources)) {
ioSourceList.addAll(curSources);
}
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/InputProviderRequireInterceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/InputProviderRequireInterceptor.java
index 4f929b5..0a5b4b9 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/InputProviderRequireInterceptor.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/InputProviderRequireInterceptor.java
@@ -26,7 +26,7 @@
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.ProxyPointInterceptor;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.StringUtil;
import java.io.FileNotFoundException;
@@ -98,7 +98,7 @@ public String interceptPoint() {
@SuppressWarnings("all")
public InputProvider onAfter(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhancer, InputProvider inputProvider) {
List inputProviderList = awareIOSources(leetcodeJavaDebugEnhancer);
- if (!ContainerCheckUtil.isListEmpty(inputProviderList)) {
+ if (ContainerUtil.isNotEmpty(inputProviderList)) {
if (Objects.nonNull(inputProvider)) {
inputProviderList.add(inputProvider);
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/OutputConsumerRequireInterceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/OutputConsumerRequireInterceptor.java
index 7ff3b4e..a59b32b 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/OutputConsumerRequireInterceptor.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/OutputConsumerRequireInterceptor.java
@@ -25,7 +25,7 @@
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.MultipleOutputConsumer;
import io.github.jidcoo.opto.lcdb.enhancer.core.proxy.ProxyPointInterceptor;
import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil;
-import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil;
+import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerUtil;
import io.github.jidcoo.opto.lcdb.enhancer.utils.StringUtil;
import java.io.FileNotFoundException;
@@ -97,7 +97,7 @@ public String interceptPoint() {
@SuppressWarnings("all")
public OutputConsumer onAfter(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhancer, OutputConsumer outputConsumer) {
List outputConsumerList = awareIOSources(leetcodeJavaDebugEnhancer);
- if (!ContainerCheckUtil.isListEmpty(outputConsumerList)) {
+ if (ContainerUtil.isNotEmpty(outputConsumerList)) {
if (Objects.nonNull(outputConsumer)) {
outputConsumerList.add(outputConsumer);
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/BeanUtil.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/BeanUtil.java
index d11f7e6..49a864f 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/BeanUtil.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/BeanUtil.java
@@ -47,7 +47,7 @@ public static List collectBeans(Class extends T> type, String packageNa
AssertUtil.nonNull(classFilter, "The class filter cannot be null.");
AssertUtil.nonNull(beanCreator, "The bean creator cannot be null.");
List> classesByPackage = PackageUtil.getClassesByPackage(packageName);
- if (!ContainerCheckUtil.isListEmpty(classesByPackage)) {
+ if (ContainerUtil.isNotEmpty(classesByPackage)) {
return classesByPackage.stream().filter(klass -> classFilter.apply(klass)).map(klass -> beanCreator.apply((Class extends T>) klass)).collect(Collectors.toList());
}
return new ArrayList<>();
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ContainerCheckUtil.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ContainerUtil.java
similarity index 58%
rename from src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ContainerCheckUtil.java
rename to src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ContainerUtil.java
index a44894d..18affb8 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ContainerCheckUtil.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ContainerUtil.java
@@ -22,12 +22,12 @@
import java.util.Set;
/**
- * A common java data container check util.
+ * A common java data container util.
*
* @author Jidcoo
* @since 1.0
*/
-public class ContainerCheckUtil {
+public class ContainerUtil {
/**
* Check if the map is empty.
@@ -35,27 +35,60 @@ public class ContainerCheckUtil {
* @param map the map.
* @return true if the map is null or empty.
*/
- public static boolean isMapEmpty(Map map) {
+ public static boolean isEmpty(Map, ?> map) {
return Objects.isNull(map) || map.isEmpty();
}
+ /**
+ * Check if the map is not empty.
+ *
+ * @param map the map.
+ * @return true if the map is not null and not empty.
+ * @since 1.0.3
+ */
+ public static boolean isNotEmpty(Map, ?> map) {
+ return !isEmpty(map);
+ }
+
/**
* Check if the set is empty.
*
* @param set the set.
* @return true if the set is null or empty.
*/
- public static boolean isSetEmpty(Set set) {
+ public static boolean isEmpty(Set> set) {
return Objects.isNull(set) || set.isEmpty();
}
+ /**
+ * Check if the set is not empty.
+ *
+ * @param set the set.
+ * @return true if the set is not null and not empty.
+ * @since 1.0.3
+ */
+ public static boolean isNotEmpty(Set> set) {
+ return !isEmpty(set);
+ }
+
/**
* Check if the list is empty.
*
* @param list the list.
* @return true if the list is null or empty.
*/
- public static boolean isListEmpty(List list) {
+ public static boolean isEmpty(List> list) {
return Objects.isNull(list) || list.isEmpty();
}
+
+ /**
+ * Check if the list is not empty.
+ *
+ * @param list the list.
+ * @return true if the list is not null and not empty.
+ * @since 1.0.3
+ */
+ public static boolean isNotEmpty(List> list) {
+ return !isEmpty(list);
+ }
}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/OrderUtil.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/OrderUtil.java
new file mode 100644
index 0000000..8f97b86
--- /dev/null
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/OrderUtil.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.utils;
+
+import io.github.jidcoo.opto.lcdb.enhancer.base.Order;
+
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * A common order util for {@link io.github.jidcoo.opto.lcdb.enhancer.base.Order}.
+ *
+ * @author Jidcoo
+ * @see Order
+ * @since 1.0.3
+ */
+public class OrderUtil {
+
+ private static final Comparator super Order> ASC_ORDER_CMP = Comparator.comparingInt(Order::getOrder);
+
+ private static final Comparator super Order> DESC_ORDER_CMP = ASC_ORDER_CMP.reversed();
+
+ /**
+ * ASC sort.
+ *
+ * @param list the order-able list.
+ */
+ public static void ascSort(List extends Order> list) {
+ orderSort(list, ASC_ORDER_CMP);
+ }
+
+ /**
+ * DESC sort.
+ *
+ * @param list the order-able list.
+ */
+ public static void descSort(List extends Order> list) {
+ orderSort(list, DESC_ORDER_CMP);
+ }
+
+ /**
+ * Get asc order comparator.
+ *
+ * @return Comparator
+ */
+ public static Comparator super Order> ascComparator() {
+ return ASC_ORDER_CMP;
+ }
+
+ /**
+ * Get desc order comparator.
+ *
+ * @return Comparator
+ */
+ public static Comparator super Order> descComparator() {
+ return DESC_ORDER_CMP;
+ }
+
+ private static void orderSort(List extends Sortable> list, Comparator super Sortable> cmp) {
+ AssertUtil.nonNull(list, "The list cannot be null.");
+ list.sort(cmp);
+ }
+}
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ReflectUtil.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ReflectUtil.java
index 03a4a2c..1c4ae96 100644
--- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ReflectUtil.java
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/ReflectUtil.java
@@ -87,7 +87,14 @@ public static Class>[] resolveInnerClasses(Class> clazz) {
public static boolean isImplementInterface(Class> clazz, Class> interfaceClass) {
AssertUtil.nonNull(clazz, "The class cannot be null.");
AssertUtil.nonNull(interfaceClass, "The interface cannot be null.");
- return Arrays.stream(clazz.getInterfaces()).anyMatch(clz -> interfaceClass == clz);
+ Class> classFinder = clazz;
+ while (Objects.nonNull(classFinder)) {
+ if (Arrays.stream(classFinder.getInterfaces()).anyMatch(clz -> interfaceClass == clz)) {
+ return true;
+ }
+ classFinder = classFinder.getSuperclass();
+ }
+ return false;
}
/**
diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/TypeUtil.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/TypeUtil.java
new file mode 100644
index 0000000..94934c0
--- /dev/null
+++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/TypeUtil.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.utils;
+
+import java.lang.reflect.*;
+import java.util.List;
+
+/**
+ * Java type util.
+ *
+ * @author Jidcoo
+ * @since 1.0.3
+ */
+public class TypeUtil {
+
+ /**
+ * Obtain list element type from a {@link List} type.
+ *
+ * @param listType a {@link List} type.
+ * @return the list element type.
+ */
+ public static Type obtainListElementType(Type listType) {
+ if (listType instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) listType;
+ Type rawType = pt.getRawType();
+
+ AssertUtil.isTrue((rawType instanceof Class && List.class.isAssignableFrom((Class>) rawType)),
+ "The type must be a java.util.List type.");
+
+ Type[] typeArgs = pt.getActualTypeArguments();
+ if (typeArgs.length == 0) {
+ return Object.class;
+ }
+
+ Type firstArg = typeArgs[0];
+ if (firstArg instanceof WildcardType) {
+ WildcardType wt = (WildcardType) firstArg;
+ Type[] upperBounds = wt.getUpperBounds();
+ return upperBounds.length > 0 ? upperBounds[0] : Object.class;
+ }
+ return firstArg;
+ } else if (listType instanceof Class && List.class.isAssignableFrom((Class>) listType)) {
+ return Object.class;
+ }
+ throw new IllegalArgumentException("The type must be a java.util.List type.");
+ }
+
+ /**
+ * Obtain raw type from the specified type.
+ *
+ * @param type the specified type.
+ * @return the raw type of the specified type.
+ */
+ public static Class> obtainRawTypeOfType(Type type) {
+ if (type instanceof Class) {
+ return (Class>) type;
+ } else if (type instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type rawType = parameterizedType.getRawType();
+ return obtainRawTypeOfType(rawType);
+ } else if (type instanceof GenericArrayType) {
+ GenericArrayType arrayType = (GenericArrayType) type;
+ Type componentType = arrayType.getGenericComponentType();
+ Class> componentRawType = obtainRawTypeOfType(componentType);
+ return Array.newInstance(componentRawType, 0).getClass();
+ } else if (type instanceof TypeVariable) {
+ return Object.class;
+ } else if (type instanceof WildcardType) {
+ WildcardType wildcardType = (WildcardType) type;
+ Type[] upperBounds = wildcardType.getUpperBounds();
+ return upperBounds.length > 0 ? obtainRawTypeOfType(upperBounds[0]) : Object.class;
+ }
+ throw new IllegalArgumentException("Cannot obtain raw type: " + type);
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java
new file mode 100644
index 0000000..6e8f370
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer;
+
+import io.github.jidcoo.opto.lcdb.enhancer.base.OutputConsumer;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.MultipleOutputConsumer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ *
UnitTestDriver is a driver that run a junit-test on this project.
+ *
All junit-test classes must extend from this class!!!
+ *
+ * @author Jidcoo
+ * @see UnitTestDriver#registerDriver()
+ * @see UnitTestDriver#registerDriverWithAutoCustomStdIn(String...)
+ * @see UnitTestDriver#expectString(String...)
+ * @see UnitTestDriver#ignoreTestResult()
+ */
+@RunWith(JUnit4.class)
+public abstract class UnitTestDriver extends LJDEStarter {
+
+ private static final UnitTestOutputCollector __GLOBAL__OC__ = new UnitTestOutputCollector();
+
+ private final static Lock __GLOBAL__SYS_STD_IN_CHANEL_LOCK__ = new ReentrantLock();
+
+ private final static InputStream __GLOBAL__SYS_STD_IN_HOLDER__ = System.in;
+
+ private final String __UNIT_TEST_ID__ = UUID.randomUUID().toString();
+
+ private String __TEST_EXPECTED_RESULT__;
+
+ private InputStream __CUSTOM_STD_IN_HOLDER__;
+
+ private boolean __IS__REGISTERED__;
+
+ private boolean __IS__IGNORED__OUTPUT__;
+
+ @Before
+ public final void __PROCESS_BEFORE_ON_DRIVER__() {
+ __GLOBAL__OC__.attach(this);
+ }
+
+ @After
+ public final void __PROCESS_AFTER_ON_DRIVER__() {
+ __GLOBAL__OC__.detach(this);
+ if (__CUSTOM_STD_IN_HOLDER__ != null) {
+ try {
+ __CUSTOM_STD_IN_HOLDER__.close();
+ } catch (IOException ignored) {
+ }
+ __CUSTOM_STD_IN_HOLDER__ = null;
+ System.setIn(__GLOBAL__SYS_STD_IN_HOLDER__);
+ __GLOBAL__SYS_STD_IN_CHANEL_LOCK__.unlock();
+ }
+ }
+
+ @Test
+ public final void __PROCESS_TEST_ON_DRIVER__() {
+ Assert.assertTrue(__IS__REGISTERED__);
+ LJDEStarter.main(new String[]{this.getClass().getName()});
+ if (__IS__IGNORED__OUTPUT__) {
+ return;
+ }
+ Assert.assertEquals(__TEST_EXPECTED_RESULT__, __GLOBAL__OC__.collectOutput(this));
+ }
+
+ @Override
+ public OutputConsumer getOutputConsumer() {
+ OutputConsumer originOutputConsumer = super.getOutputConsumer();
+ List outputConsumers = new ArrayList<>();
+ outputConsumers.add(__GLOBAL__OC__);
+ if (originOutputConsumer != null) {
+ outputConsumers.add(originOutputConsumer);
+ }
+ return new MultipleOutputConsumer(outputConsumers);
+ }
+
+ /**
+ * Ignore the test result.
+ */
+ protected final void ignoreTestResult() {
+ if (!__IS__IGNORED__OUTPUT__) {
+ __IS__IGNORED__OUTPUT__ = true;
+ }
+ }
+
+ /**
+ * Assert that the test result with expected result.
+ *
+ * @param expectedResult the expected results.
+ */
+ protected final void expectString(String... expectedResult) {
+ if (__IS__IGNORED__OUTPUT__) {
+ return;
+ }
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < expectedResult.length; i++) {
+ if (i > 0) {
+ buf.append("\n");
+ }
+ buf.append(expectedResult[i]);
+ }
+ __TEST_EXPECTED_RESULT__ = buf.toString();
+ }
+
+ /**
+ * Register driver to cur junit-test instance.
+ *
+ * @apiNote Before running the test, one of {@link UnitTestDriver#registerDriver()}
+ * or {@link UnitTestDriver#registerDriverWithAutoCustomStdIn(String...)}
+ * must be called to register the driver to current junit-test instance.
+ */
+ protected final void registerDriver() {
+ if (!__IS__REGISTERED__) {
+ __IS__REGISTERED__ = true;
+ }
+ }
+
+ /**
+ * Register driver to cur junit-test instance with auto custom
+ * system standard input.
+ *
+ * @apiNote Before running the test, one of {@link UnitTestDriver#registerDriver()}
+ * or {@link UnitTestDriver#registerDriverWithAutoCustomStdIn(String...)}
+ * must be called to register the driver to current junit-test instance.
+ */
+ protected final void registerDriverWithAutoCustomStdIn(String... stdIn) {
+ Assert.assertNotNull(stdIn);
+ if (stdIn.length == 0) {
+ registerDriver();
+ } else {
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < stdIn.length; i++) {
+ if (i > 0) {
+ buf.append("\n");
+ }
+ buf.append(stdIn[i]);
+ }
+ if (!__IS__REGISTERED__) {
+ ByteArrayInputStream in = new ByteArrayInputStream(buf.toString().getBytes());
+ __GLOBAL__SYS_STD_IN_CHANEL_LOCK__.lock();
+ __CUSTOM_STD_IN_HOLDER__ = in;
+ System.setIn(__CUSTOM_STD_IN_HOLDER__);
+ registerDriver();
+ }
+ }
+
+ }
+
+ private static class UnitTestOutputCollector implements OutputConsumer {
+
+ private final Map UNITTEST_OUTPUT_POOL;
+
+ private final ThreadLocal UNITTEST_INSTANCE_REGISTRY;
+
+ UnitTestOutputCollector() {
+ UNITTEST_OUTPUT_POOL = new ConcurrentHashMap<>();
+ UNITTEST_INSTANCE_REGISTRY = new InheritableThreadLocal<>();
+ }
+
+ void attach(UnitTestDriver driver) {
+ Assert.assertNotNull(driver);
+ Assert.assertNotNull(driver.__UNIT_TEST_ID__);
+ Assert.assertEquals(false, UNITTEST_OUTPUT_POOL.containsKey(driver.__UNIT_TEST_ID__));
+ Assert.assertNull(UNITTEST_INSTANCE_REGISTRY.get());
+ UNITTEST_INSTANCE_REGISTRY.set(driver.__UNIT_TEST_ID__);
+ UNITTEST_OUTPUT_POOL.put(driver.__UNIT_TEST_ID__, new StringBuffer());
+ }
+
+ void detach(UnitTestDriver driver) {
+ UNITTEST_INSTANCE_REGISTRY.remove();
+ Assert.assertNotNull(driver);
+ Assert.assertNotNull(driver.__UNIT_TEST_ID__);
+ StringBuffer output = UNITTEST_OUTPUT_POOL.remove(driver.__UNIT_TEST_ID__);
+ if (output != null) {
+ output.delete(0, output.length());
+ }
+ }
+
+ String collectOutput(UnitTestDriver driver) {
+ Assert.assertNotNull(driver);
+ Assert.assertNotNull(driver.__UNIT_TEST_ID__);
+ Assert.assertEquals(true, UNITTEST_OUTPUT_POOL.containsKey(driver.__UNIT_TEST_ID__));
+ Assert.assertNotNull(UNITTEST_INSTANCE_REGISTRY.get());
+ Assert.assertEquals(driver.__UNIT_TEST_ID__, UNITTEST_INSTANCE_REGISTRY.get());
+ StringBuffer output = UNITTEST_OUTPUT_POOL.get(driver.__UNIT_TEST_ID__);
+ Assert.assertNotNull(output);
+ String ret = output.toString();
+ output.delete(0, ret.length());
+ Assert.assertEquals(driver.__UNIT_TEST_ID__, UNITTEST_INSTANCE_REGISTRY.get());
+ return ret;
+ }
+
+ @Override
+ public void consumeNextOutput(String output) {
+ String unitTestInstance = UNITTEST_INSTANCE_REGISTRY.get();
+ Assert.assertNotNull(unitTestInstance);
+ Assert.assertEquals(true, UNITTEST_OUTPUT_POOL.containsKey(unitTestInstance));
+ StringBuffer outputBuffer = UNITTEST_OUTPUT_POOL.get(unitTestInstance);
+ if (outputBuffer.length() > 0) {
+ outputBuffer.append("\n");
+ }
+ outputBuffer.append(output);
+ }
+
+ @Override
+ public void close() throws Exception {
+
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase01.java
new file mode 100644
index 0000000..93af2e5
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase01.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[2,7,11,15] 9", "[3,2,4] 6", "[3,3] 6");
+ expectString("[0,1]", "[1,2]", "[0,1]");
+ }
+
+ 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];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase02.java
new file mode 100644
index 0000000..f3131ae
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase02.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = "[2,7,11,15] 9")
+@Require(types = StringInputProvider.class, values = "[3,2,4] 6\n[3,3] 6")
+public class TestSet1_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("[0,1]", "[1,2]", "[0,1]");
+ }
+
+ 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];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase03.java
new file mode 100644
index 0000000..aeea336
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase03.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = "[2,7,11,15] 9")
+@Require(types = StringInputProvider.class, values = {"[3,2,4] 6", "[3,3] 6"})
+public class TestSet1_TestCase03 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("[0,1]", "[1,2]", "[0,1]");
+ }
+
+ 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];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase04.java
new file mode 100644
index 0000000..e0da503
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase04.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = {
+ StringInputProvider.class,
+ StringInputProvider.class
+},
+ values = {
+ "[2,7,11,15] 9\n[3,2,4] 6",
+ "[3,3] 6"
+ })
+public class TestSet1_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("[0,1]","[1,2]","[0,1]");
+ }
+
+ 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];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase05.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase05.java
new file mode 100644
index 0000000..2165cd1
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase05.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase05 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3,4]", "[1,1,1,1,1]", "[3,1,2,10,1]");
+ expectString("[1,3,6,10]", "[1,2,3,4,5]", "[3,4,6,16,17]");
+ }
+
+ class Solution {
+ public int[] runningSum(int[] nums) {
+ int n = nums.length;
+ for (int i = 1; i < n; i++) {
+ nums[i] += nums[i - 1];
+ }
+ return nums;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase06.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase06.java
new file mode 100644
index 0000000..32e15d6
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase06.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase06 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[-1,0,1,2,-1,-4]", "[0,1,1]", "[0,0,0]");
+ expectString("[[-1,-1,2],[-1,0,1]]", "[]", "[[0,0,0]]");
+ }
+
+ class Solution {
+ public List> threeSum(int[] nums) {
+ int n = nums.length;
+ Arrays.sort(nums);
+ List> ans = new ArrayList>();
+ for (int first = 0; first < n; ++first) {
+ if (first > 0 && nums[first] == nums[first - 1]) {
+ continue;
+ }
+ int third = n - 1;
+ int target = -nums[first];
+ for (int second = first + 1; second < n; ++second) {
+ if (second > first + 1 && nums[second] == nums[second - 1]) {
+ continue;
+ }
+ while (second < third && nums[second] + nums[third] > target) {
+ --third;
+ }
+ if (second == third) {
+ break;
+ }
+ if (nums[second] + nums[third] == target) {
+ List list = new ArrayList();
+ list.add(nums[first]);
+ list.add(nums[second]);
+ list.add(nums[third]);
+ ans.add(list);
+ }
+ }
+ }
+ return ans;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase07.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase07.java
new file mode 100644
index 0000000..60ee2ba
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase07.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase07 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3,4]", "[4,2,3,15]");
+ expectString("6", "5");
+ }
+
+ class Solution {
+ final int[] PRIMES = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
+ final int NUM_MAX = 30;
+ final int MOD = 1000000007;
+
+ public int numberOfGoodSubsets(int[] nums) {
+ int[] freq = new int[NUM_MAX + 1];
+ for (int num : nums) {
+ ++freq[num];
+ }
+
+ int[] f = new int[1 << PRIMES.length];
+ f[0] = 1;
+ for (int i = 0; i < freq[1]; ++i) {
+ f[0] = f[0] * 2 % MOD;
+ }
+
+ for (int i = 2; i <= NUM_MAX; ++i) {
+ if (freq[i] == 0) {
+ continue;
+ }
+
+ int subset = 0, x = i;
+ boolean check = true;
+ for (int j = 0; j < PRIMES.length; ++j) {
+ int prime = PRIMES[j];
+ if (x % (prime * prime) == 0) {
+ check = false;
+ break;
+ }
+ if (x % prime == 0) {
+ subset |= (1 << j);
+ }
+ }
+ if (!check) {
+ continue;
+ }
+
+ // 动态规划
+ for (int mask = (1 << PRIMES.length) - 1; mask > 0; --mask) {
+ if ((mask & subset) == subset) {
+ f[mask] = (int) ((f[mask] + ((long) f[mask ^ subset]) * freq[i]) % MOD);
+ }
+ }
+ }
+
+ int ans = 0;
+ for (int mask = 1, maskMax = (1 << PRIMES.length); mask < maskMax; ++mask) {
+ ans = (ans + f[mask]) % MOD;
+ }
+
+ return ans;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase08.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase08.java
new file mode 100644
index 0000000..5690802
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase08.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase08 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]", "[[0,0,0],[0,0,0],[0,0,0]]");
+ expectString("35", "0");
+ }
+
+ class Solution {
+ public int maxIncreaseKeepingSkyline(int[][] grid) {
+ int n = grid.length;
+ int[] rowMax = new int[n];
+ int[] colMax = new int[n];
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < n; j++) {
+ rowMax[i] = Math.max(rowMax[i], grid[i][j]);
+ colMax[j] = Math.max(colMax[j], grid[i][j]);
+ }
+ }
+ int ans = 0;
+ for (int i = 0; i < n; i++) {
+ for (int j = 0; j < n; j++) {
+ ans += Math.min(rowMax[i], colMax[j]) - grid[i][j];
+ }
+ }
+ return ans;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase09.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase09.java
new file mode 100644
index 0000000..91903d7
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase09.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase09 extends UnitTestDriver {
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]",
+ "[[2,1],[1,2]]");
+ expectString("[[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]", "[[0,0],[0,1],[1,0],[1,1]]");
+ }
+
+ class Solution {
+ int[][] dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
+ int[][] heights;
+ int m, n;
+
+ public List> pacificAtlantic(int[][] heights) {
+ this.heights = heights;
+ this.m = heights.length;
+ this.n = heights[0].length;
+ boolean[][] pacific = new boolean[m][n];
+ boolean[][] atlantic = new boolean[m][n];
+ for (int i = 0; i < m; i++) {
+ dfs(i, 0, pacific);
+ }
+ for (int j = 1; j < n; j++) {
+ dfs(0, j, pacific);
+ }
+ for (int i = 0; i < m; i++) {
+ dfs(i, n - 1, atlantic);
+ }
+ for (int j = 0; j < n - 1; j++) {
+ dfs(m - 1, j, atlantic);
+ }
+ List> result = new ArrayList>();
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ if (pacific[i][j] && atlantic[i][j]) {
+ List cell = new ArrayList();
+ cell.add(i);
+ cell.add(j);
+ result.add(cell);
+ }
+ }
+ }
+ return result;
+ }
+
+ public void dfs(int row, int col, boolean[][] ocean) {
+ if (ocean[row][col]) {
+ return;
+ }
+ ocean[row][col] = true;
+ for (int[] dir : dirs) {
+ int newRow = row + dir[0], newCol = col + dir[1];
+ if (newRow >= 0 && newRow < m && newCol >= 0 && newCol < n && heights[newRow][newCol] >= heights[row][col]) {
+ dfs(newRow, newCol, ocean);
+ }
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase10.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase10.java
new file mode 100644
index 0000000..d7dfb76
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase10.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet1_TestCase10 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,1,1,1,1,null,1]","[2,2,2,5,2]");
+ expectString("true", "false");
+ }
+
+ class Solution {
+ public boolean isUnivalTree(TreeNode root) {
+ if (root == null) {
+ return true;
+ }
+ if (root.left != null) {
+ if (root.val != root.left.val || !isUnivalTree(root.left)) {
+ return false;
+ }
+ }
+ if (root.right != null) {
+ if (root.val != root.right.val || !isUnivalTree(root.right)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/package-info.java
new file mode 100644
index 0000000..d705593
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * Tests for basic function of {@link io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset1;
\ No newline at end of file
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase01.java
new file mode 100644
index 0000000..9a0eec1
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase01.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = "[[1,1,1],[1,0,1],[1,1,1]]")
+public class TestSet2_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ ignoreTestResult();
+ }
+
+ class Solution {
+ public void setZeroes(int[][] matrix) {
+ int m = matrix.length, n = matrix[0].length;
+ boolean[] row = new boolean[m];
+ boolean[] col = new boolean[n];
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ if (matrix[i][j] == 0) {
+ row[i] = col[j] = true;
+ }
+ }
+ }
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ if (row[i] || col[j]) {
+ matrix[i][j] = 0;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase02.java
new file mode 100644
index 0000000..2705977
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase02.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+import java.util.*;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = {"\"hit\" \"cog\" [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"," +
+ "\"cog\"]", "\"hit\" \"cog\" [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]"})
+public class TestSet2_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("[[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]", "[]");
+ }
+
+ class Solution {
+ public List> findLadders(String beginWord, String endWord, List wordList) {
+ List> res = new ArrayList<>();
+ Set dict = new HashSet<>(wordList);
+ if (!dict.contains(endWord)) {
+ return res;
+ }
+
+ dict.remove(beginWord);
+
+ Map steps = new HashMap();
+ steps.put(beginWord, 0);
+ Map> from = new HashMap>();
+ int step = 1;
+ boolean found = false;
+ int wordLen = beginWord.length();
+ Queue queue = new ArrayDeque();
+ queue.offer(beginWord);
+ while (!queue.isEmpty()) {
+ int size = queue.size();
+ for (int i = 0; i < size; i++) {
+ String currWord = queue.poll();
+ char[] charArray = currWord.toCharArray();
+ for (int j = 0; j < wordLen; j++) {
+ char origin = charArray[j];
+ for (char c = 'a'; c <= 'z'; c++) {
+ charArray[j] = c;
+ String nextWord = String.valueOf(charArray);
+ if (steps.containsKey(nextWord) && step == steps.get(nextWord)) {
+ from.get(nextWord).add(currWord);
+ }
+ if (!dict.contains(nextWord)) {
+ continue;
+ }
+ dict.remove(nextWord);
+ queue.offer(nextWord);
+
+ from.putIfAbsent(nextWord, new ArrayList<>());
+ from.get(nextWord).add(currWord);
+ steps.put(nextWord, step);
+ if (nextWord.equals(endWord)) {
+ found = true;
+ }
+ }
+ charArray[j] = origin;
+ }
+ }
+ step++;
+ if (found) {
+ break;
+ }
+ }
+
+ if (found) {
+ Deque path = new ArrayDeque<>();
+ path.add(endWord);
+ backtrack(from, path, beginWord, endWord, res);
+ }
+ return res;
+ }
+
+ public void backtrack(Map> from, Deque path, String beginWord, String cur,
+ List> res) {
+ if (cur.equals(beginWord)) {
+ res.add(new ArrayList<>(path));
+ return;
+ }
+ for (String precursor : from.get(cur)) {
+ path.addFirst(precursor);
+ backtrack(from, path, beginWord, precursor, res);
+ path.removeFirst();
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase03.java
new file mode 100644
index 0000000..bd67777
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase03.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet2_TestCase03 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("2","3");
+ expectString("2","3");
+ }
+
+ class Solution {
+ public int climbStairs(int n) {
+ int p = 0, q = 0, r = 1;
+ for (int i = 1; i <= n; ++i) {
+ p = q;
+ q = r;
+ r = p + q;
+ }
+ return r;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase04.java
new file mode 100644
index 0000000..e80c8df
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase04.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = {"[1,2,3]", "[-10,9,20,null,null,15,7]"})
+public class TestSet2_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("6", "42");
+ }
+
+ class Solution {
+ int maxSum;
+
+ public int maxPathSum(TreeNode root) {
+ maxSum = Integer.MIN_VALUE;
+ maxGain(root);
+ return maxSum;
+ }
+
+ private int maxGain(TreeNode node) {
+ if (node == null) {
+ return 0;
+ }
+
+ int leftGain = Math.max(maxGain(node.left), 0);
+ int rightGain = Math.max(maxGain(node.right), 0);
+
+ int priceNewpath = node.val + leftGain + rightGain;
+
+ maxSum = Math.max(maxSum, priceNewpath);
+
+ return node.val + Math.max(leftGain, rightGain);
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase05.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase05.java
new file mode 100644
index 0000000..86c5fed
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase05.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+import java.util.Arrays;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = {"2 [2,4,1]", "2 [3,2,6,5,0,3]"})
+public class TestSet2_TestCase05 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("2", "7");
+ }
+
+ class Solution {
+ public int maxProfit(int k, int[] prices) {
+ if (prices.length == 0) {
+ return 0;
+ }
+
+ int n = prices.length;
+ k = Math.min(k, n / 2);
+ int[][] buy = new int[n][k + 1];
+ int[][] sell = new int[n][k + 1];
+
+ buy[0][0] = -prices[0];
+ sell[0][0] = 0;
+ for (int i = 1; i <= k; ++i) {
+ buy[0][i] = sell[0][i] = Integer.MIN_VALUE / 2;
+ }
+
+ for (int i = 1; i < n; ++i) {
+ buy[i][0] = Math.max(buy[i - 1][0], sell[i - 1][0] - prices[i]);
+ for (int j = 1; j <= k; ++j) {
+ buy[i][j] = Math.max(buy[i - 1][j], sell[i - 1][j] - prices[i]);
+ sell[i][j] = Math.max(sell[i - 1][j], buy[i - 1][j - 1] + prices[i]);
+ }
+ }
+
+ return Arrays.stream(sell[n - 1]).max().getAsInt();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase06.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase06.java
new file mode 100644
index 0000000..30be77e
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase06.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class, values = {"[10,5,15,3,7,null,18] 7 15", "[10,5,15,3,7,13,18,1,null,6] 6 10"})
+public class TestSet2_TestCase06 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("32", "23");
+ }
+
+ class Solution {
+ public int rangeSumBST(TreeNode root, int low, int high) {
+ if (root == null) {
+ return 0;
+ }
+ if (root.val > high) {
+ return rangeSumBST(root.left, low, high);
+ }
+ if (root.val < low) {
+ return rangeSumBST(root.right, low, high);
+ }
+ return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high);
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase07.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase07.java
new file mode 100644
index 0000000..40766c8
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase07.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet2_TestCase07 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("\"aa\" \"a\"", "\"aa\" \"*\"", "\"cb\" \"?a\"");
+ expectString("false", "true", "false");
+ }
+
+ class Solution {
+ public boolean isMatch(String s, String p) {
+ int m = s.length();
+ int n = p.length();
+ boolean[][] dp = new boolean[m + 1][n + 1];
+ dp[0][0] = true;
+ for (int i = 1; i <= n; ++i) {
+ if (p.charAt(i - 1) == '*') {
+ dp[0][i] = true;
+ } else {
+ break;
+ }
+ }
+ for (int i = 1; i <= m; ++i) {
+ for (int j = 1; j <= n; ++j) {
+ if (p.charAt(j - 1) == '*') {
+ dp[i][j] = dp[i][j - 1] || dp[i - 1][j];
+ } else if (p.charAt(j - 1) == '?' || s.charAt(i - 1) == p.charAt(j - 1)) {
+ dp[i][j] = dp[i - 1][j - 1];
+ }
+ }
+ }
+ return dp[m][n];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase08.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase08.java
new file mode 100644
index 0000000..ebb2bcf
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase08.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet2_TestCase08 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn(
+ "[\"5\",\"2\",\"C\",\"D\",\"+\"]",
+ "[\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]",
+ "[\"1\"]"
+ );
+ expectString("30", "27", "1");
+ }
+
+ class Solution {
+ public int calPoints(String[] ops) {
+ int ret = 0;
+ List points = new ArrayList();
+ for (String op : ops) {
+ int n = points.size();
+ switch (op.charAt(0)) {
+ case '+':
+ ret += points.get(n - 1) + points.get(n - 2);
+ points.add(points.get(n - 1) + points.get(n - 2));
+ break;
+ case 'D':
+ ret += 2 * points.get(n - 1);
+ points.add(2 * points.get(n - 1));
+ break;
+ case 'C':
+ ret -= points.get(n - 1);
+ points.remove(n - 1);
+ break;
+ default:
+ ret += Integer.parseInt(op);
+ points.add(Integer.parseInt(op));
+ break;
+ }
+ }
+ return ret;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase09.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase09.java
new file mode 100644
index 0000000..a1311fd
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase09.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.PriorityQueue;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet2_TestCase09 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]", "[[1,2,3],[1,2,3],[1,2,3]]");
+ expectString("[20,24]", "[1,1]");
+ }
+
+ class Solution {
+ public int[] smallestRange(List> nums) {
+ int rangeLeft = 0, rangeRight = Integer.MAX_VALUE;
+ int minRange = rangeRight - rangeLeft;
+ int max = Integer.MIN_VALUE;
+ int size = nums.size();
+ int[] next = new int[size];
+ PriorityQueue priorityQueue = new PriorityQueue(new Comparator() {
+ public int compare(Integer index1, Integer index2) {
+ return nums.get(index1).get(next[index1]) - nums.get(index2).get(next[index2]);
+ }
+ });
+ for (int i = 0; i < size; i++) {
+ priorityQueue.offer(i);
+ max = Math.max(max, nums.get(i).get(0));
+ }
+ while (true) {
+ int minIndex = priorityQueue.poll();
+ int curRange = max - nums.get(minIndex).get(next[minIndex]);
+ if (curRange < minRange) {
+ minRange = curRange;
+ rangeLeft = nums.get(minIndex).get(next[minIndex]);
+ rangeRight = max;
+ }
+ next[minIndex]++;
+ if (next[minIndex] == nums.get(minIndex).size()) {
+ break;
+ }
+ priorityQueue.offer(minIndex);
+ max = Math.max(max, nums.get(minIndex).get(next[minIndex]));
+ }
+ return new int[]{rangeLeft, rangeRight};
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase10.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase10.java
new file mode 100644
index 0000000..353fe7d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase10.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet2_TestCase10 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("\"this apple is sweet\" \"this apple is sour\"",
+ "\"apple apple\" \"banana\"");
+ expectString("[\"sweet\",\"sour\"]", "[\"banana\"]");
+ }
+
+ class Solution {
+ public String[] uncommonFromSentences(String s1, String s2) {
+ Map freq = new HashMap();
+ insert(s1, freq);
+ insert(s2, freq);
+
+ List ans = new ArrayList();
+ for (Map.Entry entry : freq.entrySet()) {
+ if (entry.getValue() == 1) {
+ ans.add(entry.getKey());
+ }
+ }
+ return ans.toArray(new String[0]);
+ }
+
+ public void insert(String s, Map freq) {
+ String[] arr = s.split(" ");
+ for (String word : arr) {
+ freq.put(word, freq.getOrDefault(word, 0) + 1);
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/package-info.java
new file mode 100644
index 0000000..9043293
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * Tests for basic function of {@link io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer}.
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset2;
\ No newline at end of file
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase01.java
new file mode 100644
index 0000000..c656e2b
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase01.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3,4,5] 2", "[1] 1", "[1,2] 1");
+ expectString("[1,2,3,5]", "[]", "[1]");
+ }
+
+ class Solution {
+ public ListNode removeNthFromEnd(ListNode head, int n) {
+ int i = 0;
+ ListNode fast = head;
+ while (i < n) {
+ fast = fast.next;
+ ++i;
+ }
+ ListNode last;
+ ListNode dummy = new ListNode(0, head);
+ ListNode slow = dummy;
+ while (fast != null) {
+ fast = fast.next;
+ slow = slow.next;
+ }
+ slow.next = slow.next.next;
+ return dummy.next;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase02.java
new file mode 100644
index 0000000..3d8740d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase02.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3,4,5] 2 4", "[5] 1 1");
+ expectString("[1,4,3,2,5]", "[5]");
+ }
+
+ class Solution {
+ public ListNode reverseBetween(ListNode head, int left, int right) {
+ ListNode dummyNode = new ListNode(-1);
+ dummyNode.next = head;
+
+ ListNode pre = dummyNode;
+ for (int i = 0; i < left - 1; i++) {
+ pre = pre.next;
+ }
+
+ ListNode rightNode = pre;
+ for (int i = 0; i < right - left + 1; i++) {
+ rightNode = rightNode.next;
+ }
+
+ ListNode leftNode = pre.next;
+ ListNode curr = rightNode.next;
+
+ pre.next = null;
+ rightNode.next = null;
+
+ reverseLinkedList(leftNode);
+
+ pre.next = rightNode;
+ leftNode.next = curr;
+ return dummyNode.next;
+ }
+
+ private void reverseLinkedList(ListNode head) {
+ ListNode pre = null;
+ ListNode cur = head;
+
+ while (cur != null) {
+ ListNode next = cur.next;
+ cur.next = pre;
+ pre = cur;
+ cur = next;
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase03.java
new file mode 100644
index 0000000..728df52
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase03.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase03 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[0,1,2,3] [0,1,3]", "[0,1,2,3,4] [0,3,1,4]");
+ expectString("2", "2");
+ }
+
+ class Solution {
+ public int numComponents(ListNode head, int[] nums) {
+ Set numsSet = new HashSet();
+ for (int num : nums) {
+ numsSet.add(num);
+ }
+ boolean inSet = false;
+ int res = 0;
+ while (head != null) {
+ if (numsSet.contains(head.val)) {
+ if (!inSet) {
+ inSet = true;
+ res++;
+ }
+ } else {
+ inSet = false;
+ }
+ head = head.next;
+ }
+ return res;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase04.java
new file mode 100644
index 0000000..66e61db
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase04.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3] [1,2,3,4,5]", "[1] [1,2,1,2,1,2]", "[5] [1,2,3,4]");
+ expectString("[4,5]", "[2,2,2]", "[1,2,3,4]");
+ }
+
+ class Solution {
+ public ListNode modifiedList(int[] nums, ListNode head) {
+ Set set = new HashSet<>(nums.length);
+ for (int x : nums) {
+ set.add(x);
+ }
+ ListNode dummy = new ListNode(0, head);
+ ListNode cur = dummy;
+ while (cur.next != null) {
+ if (set.contains(cur.next.val)) {
+ cur.next = cur.next.next;
+ } else {
+ cur = cur.next;
+ }
+ }
+ return dummy.next;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase05.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase05.java
new file mode 100644
index 0000000..4579a71
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase05.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase05 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[7,2,4,3] [5,6,4]", "[2,4,3] [5,6,4]", "[0] [0]");
+ expectString("[7,8,0,7]", "[8,0,7]", "[0]");
+ }
+
+ class Solution {
+ public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
+ Deque stack1 = new ArrayDeque();
+ Deque stack2 = new ArrayDeque();
+ while (l1 != null) {
+ stack1.push(l1.val);
+ l1 = l1.next;
+ }
+ while (l2 != null) {
+ stack2.push(l2.val);
+ l2 = l2.next;
+ }
+ int carry = 0;
+ ListNode ans = null;
+ while (!stack1.isEmpty() || !stack2.isEmpty() || carry != 0) {
+ int a = stack1.isEmpty() ? 0 : stack1.pop();
+ int b = stack2.isEmpty() ? 0 : stack2.pop();
+ int cur = a + b + carry;
+ carry = cur / 10;
+ cur %= 10;
+ ListNode curnode = new ListNode(cur);
+ curnode.next = ans;
+ ans = curnode;
+ }
+ return ans;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase06.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase06.java
new file mode 100644
index 0000000..40b0641
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase06.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase06 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[2,1,5]", "[2,7,4,3,5]");
+ expectString("[5,5,0]", "[7,0,5,5,0]");
+ }
+
+ class Solution {
+ public int[] nextLargerNodes(ListNode head) {
+ List ans = new ArrayList();
+ Deque stack = new ArrayDeque();
+
+ ListNode cur = head;
+ int idx = -1;
+ while (cur != null) {
+ ++idx;
+ ans.add(0);
+ while (!stack.isEmpty() && stack.peek()[0] < cur.val) {
+ ans.set(stack.pop()[1], cur.val);
+ }
+ stack.push(new int[]{cur.val, idx});
+ cur = cur.next;
+ }
+
+ int size = ans.size();
+ int[] arr = new int[size];
+ for (int i = 0; i < size; ++i) {
+ arr[i] = ans.get(i);
+ }
+ return arr;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase07.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase07.java
new file mode 100644
index 0000000..aa425e9
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase07.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.*;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode} and {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase07 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3,4,5,null,7,8]");
+ ignoreTestResult();
+ }
+
+ class Solution {
+ public ListNode[] listOfDepth(TreeNode tree) {
+ Queue queue = new LinkedList<>();
+ List> lists = new ArrayList<>();
+ if (tree != null) {
+ queue.add(tree);
+ }
+ while (!queue.isEmpty()) {
+ List list = new ArrayList<>();
+ for (int i = queue.size(); i > 0; i--) {
+ TreeNode tmp = queue.poll();
+ list.add(tmp.val);
+ if (tmp.left != null) {
+ queue.add(tmp.left);
+ }
+ if (tmp.right != null) {
+ queue.add(tmp.right);
+ }
+ }
+ lists.add(list);
+ }
+ ListNode[] a = new ListNode[lists.size()];
+
+ for (int i = 0; i < lists.size(); i++) {
+ ListNode l = new ListNode(0);
+ ListNode ll = l;
+ for (int j = 0; j < lists.get(i).size(); j++) {
+ ListNode tmp = new ListNode(lists.get(i).get(j));
+ l.next = tmp;
+ l = l.next;
+ }
+ a[i] = ll.next;
+ }
+ return a;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase08.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase08.java
new file mode 100644
index 0000000..007d80a
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase08.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase08 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[5,4,2,1]", "[4,2,2,3]", "[1,100000]");
+ expectString("6", "7", "100001");
+ }
+
+ class Solution {
+ public int pairSum(ListNode head) {
+ ListNode prev = null, curr = head, last = head;
+ while (last != null) {
+ last = last.next.next;
+ ListNode temp = curr.next;
+ curr.next = prev;
+ prev = curr;
+ curr = temp;
+ }
+ int max = 0;
+ while (curr != null) {
+ max = Math.max(max, prev.val + curr.val);
+ prev = prev.next;
+ curr = curr.next;
+ }
+ return max;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase09.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase09.java
new file mode 100644
index 0000000..5c7f04e
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase09.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase09 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[0,3,1,0,4,5,2,0]");
+ expectString("[4,11]");
+ }
+
+ class Solution {
+ public ListNode mergeNodes(ListNode head) {
+ ListNode dummy = new ListNode();
+ ListNode tail = dummy;
+ int total = 0;
+ for (ListNode cur = head.next; cur != null; cur = cur.next) {
+ if (cur.val == 0) {
+ ListNode node = new ListNode(total);
+ tail.next = node;
+ tail = tail.next;
+ total = 0;
+ } else {
+ total += cur.val;
+ }
+ }
+
+ return dummy.next;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase10.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase10.java
new file mode 100644
index 0000000..1f60d3a
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase10.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link ListNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet3_TestCase10 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,2,3,4,5] 2");
+ expectString("[4,5,1,2,3]");
+ }
+
+ class Solution {
+ public ListNode rotateRight(ListNode head, int k) {
+ if (k == 0 || head == null || head.next == null) {
+ return head;
+ }
+ int n = 1;
+ ListNode iter = head;
+ while (iter.next != null) {
+ iter = iter.next;
+ n++;
+ }
+ int add = n - k % n;
+ if (add == n) {
+ return head;
+ }
+ iter.next = head;
+ while (add-- > 0) {
+ iter = iter.next;
+ }
+ ListNode ret = iter.next;
+ iter.next = null;
+ return ret;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/package-info.java
new file mode 100644
index 0000000..a87c1dc
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/package-info.java
@@ -0,0 +1,7 @@
+/**
+ * Tests for basic function of {@link io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer}
+ * with data structure {@link io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode}.
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset3;
\ No newline at end of file
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase01.java
new file mode 100644
index 0000000..c9ccbd5
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase01.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.ConsoleInputProvider;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.ConsoleOutputConsumer;
+import org.junit.Before;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+@Require(types = ConsoleInputProvider.class)
+@Require(types = ConsoleOutputConsumer.class)
+public class TestSet4_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", " +
+ "\"get\", \"get\", \"get\"] " +
+ "[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]");
+ expectString("[null,null,null,1,null,-1,null,-1,3,4]");
+ }
+
+ class LRUCache {
+ private Map cache = new HashMap();
+ private int size;
+ private int capacity;
+ private DLinkedNode head, tail;
+
+ public LRUCache(int capacity) {
+ this.size = 0;
+ this.capacity = capacity;
+ head = new DLinkedNode();
+ tail = new DLinkedNode();
+ head.next = tail;
+ tail.prev = head;
+ }
+
+ public int get(int key) {
+ DLinkedNode node = cache.get(key);
+ if (node == null) {
+ return -1;
+ }
+ moveToHead(node);
+ return node.value;
+ }
+
+ public void put(int key, int value) {
+ DLinkedNode node = cache.get(key);
+ if (node == null) {
+ DLinkedNode newNode = new DLinkedNode(key, value);
+ cache.put(key, newNode);
+ addToHead(newNode);
+ ++size;
+ if (size > capacity) {
+ DLinkedNode tail = removeTail();
+ cache.remove(tail.key);
+ --size;
+ }
+ } else {
+ node.value = value;
+ moveToHead(node);
+ }
+ }
+
+ private void addToHead(DLinkedNode node) {
+ node.prev = head;
+ node.next = head.next;
+ head.next.prev = node;
+ head.next = node;
+ }
+
+ private void removeNode(DLinkedNode node) {
+ node.prev.next = node.next;
+ node.next.prev = node.prev;
+ }
+
+ private void moveToHead(DLinkedNode node) {
+ removeNode(node);
+ addToHead(node);
+ }
+
+ private DLinkedNode removeTail() {
+ DLinkedNode res = tail.prev;
+ removeNode(res);
+ return res;
+ }
+
+ class DLinkedNode {
+ int key;
+ int value;
+ DLinkedNode prev;
+ DLinkedNode next;
+
+ public DLinkedNode() {
+ }
+
+ public DLinkedNode(int _key, int _value) {
+ key = _key;
+ value = _value;
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase02.java
new file mode 100644
index 0000000..aadd1ba
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase02.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.Deque;
+import java.util.LinkedList;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"MinStack\",\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"top\"," +
+ "\"getMin\"] [[],[-2],[0],[-3],[],[],[],[]]");
+ expectString("[null,null,null,null,-3,null,0,-2]");
+ }
+
+ class MinStack {
+ Deque xStack;
+ Deque minStack;
+
+ public MinStack() {
+ xStack = new LinkedList();
+ minStack = new LinkedList();
+ minStack.push(Integer.MAX_VALUE);
+ }
+
+ public void push(int x) {
+ xStack.push(x);
+ minStack.push(Math.min(minStack.peek(), x));
+ }
+
+ public void pop() {
+ xStack.pop();
+ minStack.pop();
+ }
+
+ public int top() {
+ return xStack.peek();
+ }
+
+ public int getMin() {
+ return minStack.peek();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase03.java
new file mode 100644
index 0000000..bdaa9a4
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase03.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase03 extends UnitTestDriver {
+
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\"," +
+ "\"search\",\"search\",\"search\"] [[],[\"bad\"],[\"dad\"],[\"mad\"],[\"pad\"],[\"bad\"],[\".ad\"]," +
+ "[\"b..\"]]");
+ expectString("[null,null,null,null,false,true,true,true]");
+ }
+
+ class WordDictionary {
+ private Trie root;
+
+ public WordDictionary() {
+ root = new Trie();
+ }
+
+ public void addWord(String word) {
+ root.insert(word);
+ }
+
+ public boolean search(String word) {
+ return dfs(word, 0, root);
+ }
+
+ private boolean dfs(String word, int index, Trie node) {
+ if (index == word.length()) {
+ return node.isEnd();
+ }
+ char ch = word.charAt(index);
+ if (Character.isLetter(ch)) {
+ int childIndex = ch - 'a';
+ Trie child = node.getChildren()[childIndex];
+ if (child != null && dfs(word, index + 1, child)) {
+ return true;
+ }
+ } else {
+ for (int i = 0; i < 26; i++) {
+ Trie child = node.getChildren()[i];
+ if (child != null && dfs(word, index + 1, child)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+ class Trie {
+ private Trie[] children;
+ private boolean isEnd;
+
+ public Trie() {
+ children = new Trie[26];
+ isEnd = false;
+ }
+
+ public void insert(String word) {
+ Trie node = this;
+ for (int i = 0; i < word.length(); i++) {
+ char ch = word.charAt(i);
+ int index = ch - 'a';
+ if (node.children[index] == null) {
+ node.children[index] = new Trie();
+ }
+ node = node.children[index];
+ }
+ node.isEnd = true;
+ }
+
+ public Trie[] getChildren() {
+ return children;
+ }
+
+ public boolean isEnd() {
+ return isEnd;
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase04.java
new file mode 100644
index 0000000..f6c2f71
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase04.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"NumArray\", \"sumRange\", \"sumRange\", \"sumRange\"] [[[-2, 0, 3, -5, " +
+ "2, -1]], [0, 2], [2, 5], [0, 5]]");
+ expectString("[null,1,-1,-3]");
+ }
+
+ class NumArray {
+ int[] sums;
+
+ public NumArray(int[] nums) {
+ int n = nums.length;
+ sums = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ sums[i + 1] = sums[i] + nums[i];
+ }
+ }
+
+ public int sumRange(int i, int j) {
+ return sums[j + 1] - sums[i];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase05.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase05.java
new file mode 100644
index 0000000..f6f016b
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase05.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase05 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"NumMatrix\",\"sumRegion\",\"sumRegion\",\"sumRegion\"] [[[[3,0,1,4,2]," +
+ "[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]]],[2,1,4,3],[1,1,2,2],[1,2,2,4]]");
+ expectString("[null,8,11,12]");
+ }
+
+ class NumMatrix {
+ int[][] sums;
+
+ public NumMatrix(int[][] matrix) {
+ int m = matrix.length;
+ if (m > 0) {
+ int n = matrix[0].length;
+ sums = new int[m][n + 1];
+ for (int i = 0; i < m; i++) {
+ for (int j = 0; j < n; j++) {
+ sums[i][j + 1] = sums[i][j] + matrix[i][j];
+ }
+ }
+ }
+ }
+
+ public int sumRegion(int row1, int col1, int row2, int col2) {
+ int sum = 0;
+ for (int i = row1; i <= row2; i++) {
+ sum += sums[i][col2 + 1] - sums[i][col1];
+ }
+ return sum;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase06.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase06.java
new file mode 100644
index 0000000..8fabccc
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase06.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase06 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"NumArray\", \"sumRange\", \"update\", \"sumRange\"] [[[1, 3, 5]], [0, " +
+ "2], [1, 2], [0, 2]]");
+ expectString("[null,9,null,8]");
+ }
+
+ class NumArray {
+ private int[] segmentTree;
+ private int n;
+
+ public NumArray(int[] nums) {
+ n = nums.length;
+ segmentTree = new int[nums.length * 4];
+ build(0, 0, n - 1, nums);
+ }
+
+ public void update(int index, int val) {
+ change(index, val, 0, 0, n - 1);
+ }
+
+ public int sumRange(int left, int right) {
+ return range(left, right, 0, 0, n - 1);
+ }
+
+ private void build(int node, int s, int e, int[] nums) {
+ if (s == e) {
+ segmentTree[node] = nums[s];
+ return;
+ }
+ int m = s + (e - s) / 2;
+ build(node * 2 + 1, s, m, nums);
+ build(node * 2 + 2, m + 1, e, nums);
+ segmentTree[node] = segmentTree[node * 2 + 1] + segmentTree[node * 2 + 2];
+ }
+
+ private void change(int index, int val, int node, int s, int e) {
+ if (s == e) {
+ segmentTree[node] = val;
+ return;
+ }
+ int m = s + (e - s) / 2;
+ if (index <= m) {
+ change(index, val, node * 2 + 1, s, m);
+ } else {
+ change(index, val, node * 2 + 2, m + 1, e);
+ }
+ segmentTree[node] = segmentTree[node * 2 + 1] + segmentTree[node * 2 + 2];
+ }
+
+ private int range(int left, int right, int node, int s, int e) {
+ if (left == s && right == e) {
+ return segmentTree[node];
+ }
+ int m = s + (e - s) / 2;
+ if (right <= m) {
+ return range(left, right, node * 2 + 1, s, m);
+ } else if (left > m) {
+ return range(left, right, node * 2 + 2, m + 1, e);
+ } else {
+ return range(left, m, node * 2 + 1, s, m) + range(m + 1, right, node * 2 + 2, m + 1, e);
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase07.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase07.java
new file mode 100644
index 0000000..7a5012c
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase07.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.Require;
+import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.StringInputProvider;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+@Require(types = StringInputProvider.class,
+ values = "[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"insertFront\", \"insertFront\", " +
+ "\"getRear\", " +
+ "\"isFull\", \"deleteLast\", \"insertFront\", \"getFront\"] [[3], [1], [2], [3], [4], [], [], [], " +
+ "[4], []]")
+
+public class TestSet4_TestCase07 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriver();
+ expectString("[null,true,true,true,false,2,true,true,true,4]");
+ }
+
+ class MyCircularDeque {
+ private int[] elements;
+ private int rear, front;
+ private int capacity;
+
+ public MyCircularDeque(int k) {
+ capacity = k + 1;
+ rear = front = 0;
+ elements = new int[k + 1];
+ }
+
+ public boolean insertFront(int value) {
+ if (isFull()) {
+ return false;
+ }
+ front = (front - 1 + capacity) % capacity;
+ elements[front] = value;
+ return true;
+ }
+
+ public boolean insertLast(int value) {
+ if (isFull()) {
+ return false;
+ }
+ elements[rear] = value;
+ rear = (rear + 1) % capacity;
+ return true;
+ }
+
+ public boolean deleteFront() {
+ if (isEmpty()) {
+ return false;
+ }
+ front = (front + 1) % capacity;
+ return true;
+ }
+
+ public boolean deleteLast() {
+ if (isEmpty()) {
+ return false;
+ }
+ rear = (rear - 1 + capacity) % capacity;
+ return true;
+ }
+
+ public int getFront() {
+ if (isEmpty()) {
+ return -1;
+ }
+ return elements[front];
+ }
+
+ public int getRear() {
+ if (isEmpty()) {
+ return -1;
+ }
+ return elements[(rear - 1 + capacity) % capacity];
+ }
+
+ public boolean isEmpty() {
+ return rear == front;
+ }
+
+ public boolean isFull() {
+ return (rear + 1) % capacity == front;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase08.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase08.java
new file mode 100644
index 0000000..5dceaf4
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase08.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase08 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"MagicDictionary\", \"buildDict\", \"search\", \"search\", \"search\", " +
+ "\"search\"] [[], [[\"hello\", \"leetcode\"]], [\"hello\"], [\"hhllo\"], [\"hell\"], [\"leetcoded\"]]");
+ expectString("[null,null,false,true,false,false]");
+ }
+
+ class MagicDictionary {
+ private String[] words;
+
+ public MagicDictionary() {
+
+ }
+
+ public void buildDict(String[] dictionary) {
+ words = dictionary;
+ }
+
+ public boolean search(String searchWord) {
+ for (String word : words) {
+ if (word.length() != searchWord.length()) {
+ continue;
+ }
+
+ int diff = 0;
+ for (int i = 0; i < word.length(); ++i) {
+ if (word.charAt(i) != searchWord.charAt(i)) {
+ ++diff;
+ if (diff > 1) {
+ break;
+ }
+ }
+ }
+ if (diff == 1) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase09.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase09.java
new file mode 100644
index 0000000..077e3ae
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase09.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase09 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"MapSum\", \"insert\", \"sum\", \"insert\", \"sum\"] [[], [\"apple\", " +
+ "3], [\"ap\"], [\"app\", 2], [\"ap\"]]");
+ expectString("[null,null,3,null,5]");
+ }
+
+ class MapSum {
+ Map map;
+
+ public MapSum() {
+ map = new HashMap<>();
+ }
+
+ public void insert(String key, int val) {
+ map.put(key, val);
+ }
+
+ public int sum(String prefix) {
+ int res = 0;
+ for (String s : map.keySet()) {
+ if (s.startsWith(prefix)) {
+ res += map.get(s);
+ }
+ }
+ return res;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase10.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase10.java
new file mode 100644
index 0000000..54c52aa
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase10.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.PriorityQueue;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase10 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"KthLargest\", \"add\", \"add\", \"add\", \"add\", \"add\"] " +
+ "[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]");
+ expectString("[null,4,5,5,8,8]");
+ }
+
+ class KthLargest {
+ PriorityQueue pq;
+ int k;
+
+ public KthLargest(int k, int[] nums) {
+ this.k = k;
+ pq = new PriorityQueue();
+ for (int x : nums) {
+ add(x);
+ }
+ }
+
+ public int add(int val) {
+ pq.offer(val);
+ if (pq.size() > k) {
+ pq.poll();
+ }
+ return pq.peek();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase11.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase11.java
new file mode 100644
index 0000000..0ed9823
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase11.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase11 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"insert\"," +
+ " \"search\"] [[], [\"apple\"], [\"apple\"], [\"app\"], [\"app\"], [\"app\"], [\"app\"]]");
+ expectString("[null,null,true,false,true,null,true]");
+ }
+
+ class Trie {
+ private Trie[] children;
+ private boolean isEnd;
+
+ public Trie() {
+ children = new Trie[26];
+ isEnd = false;
+ }
+
+ public void insert(String word) {
+ Trie node = this;
+ for (int i = 0; i < word.length(); i++) {
+ char ch = word.charAt(i);
+ int index = ch - 'a';
+ if (node.children[index] == null) {
+ node.children[index] = new Trie();
+ }
+ node = node.children[index];
+ }
+ node.isEnd = true;
+ }
+
+ public boolean search(String word) {
+ Trie node = searchPrefix(word);
+ return node != null && node.isEnd;
+ }
+
+ public boolean startsWith(String prefix) {
+ return searchPrefix(prefix) != null;
+ }
+
+ private Trie searchPrefix(String prefix) {
+ Trie node = this;
+ for (int i = 0; i < prefix.length(); i++) {
+ char ch = prefix.charAt(i);
+ int index = ch - 'a';
+ if (node.children[index] == null) {
+ return null;
+ }
+ node = node.children[index];
+ }
+ return node;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase12.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase12.java
new file mode 100644
index 0000000..4469068
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase12.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase12 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"Allocator\", \"allocate\", \"allocate\", \"allocate\", \"freeMemory\", " +
+ "\"allocate\", \"allocate\", \"allocate\", \"freeMemory\", \"allocate\", \"freeMemory\"] [[10], [1, " +
+ "1], [1, 2], [1, 3], [2], [3, 4], [1, 1], [1, 1], [1], [10, 2], [7]]");
+ expectString("[null,0,1,2,1,3,1,6,3,-1,0]");
+ }
+
+ class Allocator {
+ private int n;
+ private int[] memory;
+
+ public Allocator(int n) {
+ this.n = n;
+ this.memory = new int[n];
+ }
+
+ public int allocate(int size, int mID) {
+ int count = 0;
+ for (int i = 0; i < n; ++i) {
+ if (memory[i] != 0) {
+ count = 0;
+ } else {
+ ++count;
+ if (count == size) {
+ for (int j = i - count + 1; j <= i; ++j) {
+ memory[j] = mID;
+ }
+ return i - count + 1;
+ }
+ }
+ }
+ return -1;
+ }
+
+ public int freeMemory(int mID) {
+ int count = 0;
+ for (int i = 0; i < n; ++i) {
+ if (memory[i] == mID) {
+ ++count;
+ memory[i] = 0;
+ }
+ }
+ return count;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase13.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase13.java
new file mode 100644
index 0000000..4f72679
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase13.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase13 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"TextEditor\", \"addText\", \"deleteText\", \"addText\", " +
+ "\"cursorRight\", \"cursorLeft\", \"deleteText\", \"cursorLeft\", \"cursorRight\"] " +
+ "[[], [\"leetcode\"], [4], [\"practice\"], [3], [8], [10], [2], [6]]");
+ expectString("[null,null,4,null,\"etpractice\",\"leet\",4,\"\",\"practi\"]");
+ }
+
+ class TextEditor {
+
+ private Node cursor;
+
+ public TextEditor() {
+ cursor = new Node('\0');
+ }
+
+ public void addText(String text) {
+ for (char c : text.toCharArray()) {
+ cursor.insert(c);
+ }
+ }
+
+ public int deleteText(int k) {
+ int count = 0;
+ while (k > 0 && cursor.prev != null) {
+ cursor.remove();
+ k--;
+ count++;
+ }
+ return count;
+ }
+
+ public String cursorLeft(int k) {
+ while (k > 0 && cursor.prev != null) {
+ cursor = cursor.prev;
+ k--;
+ }
+ Node head = cursor;
+ for (int i = 0; i < 10 && head.prev != null; i++) {
+ head = head.prev;
+ }
+ return head.range(cursor);
+ }
+
+ public String cursorRight(int k) {
+ while (k > 0 && cursor.next != null) {
+ cursor = cursor.next;
+ k--;
+ }
+ Node head = cursor;
+ for (int i = 0; i < 10 && head.prev != null; i++) {
+ head = head.prev;
+ }
+ return head.range(cursor);
+ }
+
+ class Node {
+ char val;
+ Node prev, next;
+
+ Node(char val) {
+ this.val = val;
+ }
+
+ void insert(char val) {
+ Node node = new Node(val);
+ node.next = this;
+ node.prev = this.prev;
+ if (this.prev != null) {
+ this.prev.next = node;
+ }
+ this.prev = node;
+ }
+
+ void remove() {
+ Node node = this.prev;
+ this.prev = node.prev;
+ if (node.prev != null) {
+ node.prev.next = this;
+ }
+ }
+
+ String range(Node end) {
+ StringBuilder sb = new StringBuilder();
+ Node node = this;
+ while (node != end) {
+ sb.append(node.val);
+ node = node.next;
+ }
+ return sb.toString();
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase14.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase14.java
new file mode 100644
index 0000000..f42463e
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase14.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase14 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"SnapshotArray\",\"set\",\"snap\",\"set\",\"get\"]" +
+ " [[3],[0,5],[],[0,6],[0,0]]");
+ expectString("[null,null,0,null,5]");
+ }
+
+ @SuppressWarnings("unchecked")
+ class SnapshotArray {
+ private int snap_cnt;
+ private List[] data;
+
+ public SnapshotArray(int length) {
+ snap_cnt = 0;
+ data = new List[length];
+ for (int i = 0; i < length; i++) {
+ data[i] = new ArrayList();
+ }
+ }
+
+ public void set(int index, int val) {
+ data[index].add(new int[]{snap_cnt, val});
+ }
+
+ public int snap() {
+ return snap_cnt++;
+ }
+
+ public int get(int index, int snap_id) {
+ int x = binarySearch(index, snap_id);
+ return x == 0 ? 0 : data[index].get(x - 1)[1];
+ }
+
+ private int binarySearch(int index, int snap_id) {
+ int low = 0, high = data[index].size();
+ while (low < high) {
+ int mid = low + (high - low) / 2;
+ int[] pair = data[index].get(mid);
+ if (pair[0] > snap_id + 1 || (pair[0] == snap_id + 1 && pair[1] >= 0)) {
+ high = mid;
+ } else {
+ low = mid + 1;
+ }
+ }
+ return low;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase15.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase15.java
new file mode 100644
index 0000000..ea237ca
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase15.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase15 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"StreamChecker\", \"query\", \"query\", \"query\", \"query\", \"query\"," +
+ " \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\"] " +
+ "[[[\"cd\", \"f\", \"kl\"]], [\"a\"], [\"b\"], [\"c\"], [\"d\"], [\"e\"], [\"f\"], [\"g\"], [\"h\"], " +
+ "[\"i\"], [\"j\"], [\"k\"], [\"l\"]]");
+ expectString("[null,false,false,false,true,false,true,false,false,false,false,false,true]");
+ }
+
+ class StreamChecker {
+
+ class TrieNode {
+ TrieNode[] children;
+ boolean isEnd;
+ TrieNode fail;
+
+ public TrieNode() {
+ children = new TrieNode[26];
+ }
+
+ public TrieNode getChild(int index) {
+ return children[index];
+ }
+
+ public void setChild(int index, TrieNode node) {
+ children[index] = node;
+ }
+
+ public boolean getIsEnd() {
+ return isEnd;
+ }
+
+ public void setIsEnd(boolean b) {
+ isEnd = b;
+ }
+
+ public TrieNode getFail() {
+ return fail;
+ }
+
+ public void setFail(TrieNode node) {
+ fail = node;
+ }
+ }
+
+ TrieNode root;
+ TrieNode temp;
+
+ public StreamChecker(String[] words) {
+ root = new TrieNode();
+ for (String word : words) {
+ TrieNode cur = root;
+ for (int i = 0; i < word.length(); i++) {
+ int index = word.charAt(i) - 'a';
+ if (cur.getChild(index) == null) {
+ cur.setChild(index, new TrieNode());
+ }
+ cur = cur.getChild(index);
+ }
+ cur.setIsEnd(true);
+ }
+ root.setFail(root);
+ Queue q = new LinkedList<>();
+ for (int i = 0; i < 26; i++) {
+ if (root.getChild(i) != null) {
+ root.getChild(i).setFail(root);
+ q.add(root.getChild(i));
+ } else {
+ root.setChild(i, root);
+ }
+ }
+ while (!q.isEmpty()) {
+ TrieNode node = q.poll();
+ node.setIsEnd(node.getIsEnd() || node.getFail().getIsEnd());
+ for (int i = 0; i < 26; i++) {
+ if (node.getChild(i) != null) {
+ node.getChild(i).setFail(node.getFail().getChild(i));
+ q.offer(node.getChild(i));
+ } else {
+ node.setChild(i, node.getFail().getChild(i));
+ }
+ }
+ }
+
+ temp = root;
+ }
+
+ public boolean query(char letter) {
+ temp = temp.getChild(letter - 'a');
+ return temp.getIsEnd();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase16.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase16.java
new file mode 100644
index 0000000..2112e9e
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase16.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.*;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase16 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"MajorityChecker\", \"query\", \"query\", \"query\"] " +
+ "[[[1, 1, 2, 2, 1, 1]], [0, 5, 4], [0, 3, 3], [2, 3, 2]]");
+ expectString("[null,1,-1,2]");
+ }
+
+ class MajorityChecker {
+ public static final int K = 20;
+ private int[] arr;
+ private Map> loc;
+ private Random random;
+
+ public MajorityChecker(int[] arr) {
+ this.arr = arr;
+ this.loc = new HashMap>();
+ for (int i = 0; i < arr.length; ++i) {
+ loc.putIfAbsent(arr[i], new ArrayList());
+ loc.get(arr[i]).add(i);
+ }
+ this.random = new Random();
+ }
+
+ public int query(int left, int right, int threshold) {
+ int length = right - left + 1;
+
+ for (int i = 0; i < K; ++i) {
+ int x = arr[left + random.nextInt(length)];
+ List pos = loc.get(x);
+ int occ = searchEnd(pos, right) - searchStart(pos, left);
+ if (occ >= threshold) {
+ return x;
+ } else if (occ * 2 >= length) {
+ return -1;
+ }
+ }
+
+ return -1;
+ }
+
+ private int searchStart(List pos, int target) {
+ int low = 0, high = pos.size();
+ while (low < high) {
+ int mid = low + (high - low) / 2;
+ if (pos.get(mid) >= target) {
+ high = mid;
+ } else {
+ low = mid + 1;
+ }
+ }
+ return low;
+ }
+
+ private int searchEnd(List pos, int target) {
+ int low = 0, high = pos.size();
+ while (low < high) {
+ int mid = low + (high - low) / 2;
+ if (pos.get(mid) > target) {
+ high = mid;
+ } else {
+ low = mid + 1;
+ }
+ }
+ return low;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase17.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase17.java
new file mode 100644
index 0000000..3fb6685
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase17.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase17 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"AllOne\", \"inc\", \"inc\", \"getMaxKey\", \"getMinKey\", \"inc\", " +
+ "\"getMaxKey\", \"getMinKey\"] " +
+ "[[], [\"hello\"], [\"hello\"], [], [], [\"leet\"], [], []]");
+ expectString("[null,null,null,\"hello\",\"hello\",null,\"hello\",\"leet\"]");
+ }
+
+ class AllOne {
+ Node root;
+ Map nodes;
+
+ public AllOne() {
+ root = new Node();
+ root.prev = root;
+ root.next = root;
+ nodes = new HashMap();
+ }
+
+ public void inc(String key) {
+ if (nodes.containsKey(key)) {
+ Node cur = nodes.get(key);
+ Node nxt = cur.next;
+ if (nxt == root || nxt.count > cur.count + 1) {
+ nodes.put(key, cur.insert(new Node(key, cur.count + 1)));
+ } else {
+ nxt.keys.add(key);
+ nodes.put(key, nxt);
+ }
+ cur.keys.remove(key);
+ if (cur.keys.isEmpty()) {
+ cur.remove();
+ }
+ } else {
+ if (root.next == root || root.next.count > 1) {
+ nodes.put(key, root.insert(new Node(key, 1)));
+ } else {
+ root.next.keys.add(key);
+ nodes.put(key, root.next);
+ }
+ }
+ }
+
+ public void dec(String key) {
+ Node cur = nodes.get(key);
+ if (cur.count == 1) {
+ nodes.remove(key);
+ } else {
+ Node pre = cur.prev;
+ if (pre == root || pre.count < cur.count - 1) {
+ nodes.put(key, cur.prev.insert(new Node(key, cur.count - 1)));
+ } else {
+ pre.keys.add(key);
+ nodes.put(key, pre);
+ }
+ }
+ cur.keys.remove(key);
+ if (cur.keys.isEmpty()) {
+ cur.remove();
+ }
+ }
+
+ public String getMaxKey() {
+ return root.prev != null ? root.prev.keys.iterator().next() : "";
+ }
+
+ public String getMinKey() {
+ return root.next != null ? root.next.keys.iterator().next() : "";
+ }
+
+ class Node {
+ Node prev;
+ Node next;
+ Set keys;
+ int count;
+
+ public Node() {
+ this("", 0);
+ }
+
+ public Node(String key, int count) {
+ this.count = count;
+ keys = new HashSet();
+ keys.add(key);
+ }
+
+ public Node insert(Node node) {
+ node.prev = this;
+ node.next = this.next;
+ node.prev.next = node;
+ node.next.prev = node;
+ return node;
+ }
+
+ public void remove() {
+ this.prev.next = this.next;
+ this.next.prev = this.prev;
+ }
+ }
+ }
+
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase18.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase18.java
new file mode 100644
index 0000000..9bbf786
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase18.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase18 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"MyCalendar\", \"book\", \"book\", \"book\"] " +
+ "[[], [10, 20], [15, 25], [20, 30]]");
+ expectString("[null,true,false,true]");
+ }
+
+ class MyCalendar {
+ List booked;
+
+ public MyCalendar() {
+ booked = new ArrayList();
+ }
+
+ public boolean book(int start, int end) {
+ for (int[] arr : booked) {
+ int l = arr[0], r = arr[1];
+ if (l < end && start < r) {
+ return false;
+ }
+ }
+ booked.add(new int[]{start, end});
+ return true;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase19.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase19.java
new file mode 100644
index 0000000..a9e98f6
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase19.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase19 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"TopVotedCandidate\", \"q\", \"q\", \"q\", \"q\", \"q\", \"q\"] " +
+ "[[[0, 1, 1, 0, 0, 1, 0], [0, 5, 10, 15, 20, 25, 30]], [3], [12], [25], [15], [24], [8]]");
+ expectString("[null,0,1,1,0,0,1]");
+ }
+
+ class TopVotedCandidate {
+ List tops;
+ Map voteCounts;
+ int[] times;
+
+ public TopVotedCandidate(int[] persons, int[] times) {
+ tops = new ArrayList();
+ voteCounts = new HashMap();
+ voteCounts.put(-1, -1);
+ int top = -1;
+ for (int i = 0; i < persons.length; ++i) {
+ int p = persons[i];
+ voteCounts.put(p, voteCounts.getOrDefault(p, 0) + 1);
+ if (voteCounts.get(p) >= voteCounts.get(top)) {
+ top = p;
+ }
+ tops.add(top);
+ }
+ this.times = times;
+ }
+
+ public int q(int t) {
+ int l = 0, r = times.length - 1;
+ while (l < r) {
+ int m = l + (r - l + 1) / 2;
+ if (times[m] <= t) {
+ l = m;
+ } else {
+ r = m - 1;
+ }
+ }
+ return tops.get(l);
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase20.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase20.java
new file mode 100644
index 0000000..06109d0
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase20.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+public class TestSet4_TestCase20 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"BrowserHistory\",\"visit\",\"visit\",\"visit\",\"back\",\"back\"," +
+ "\"forward\",\"visit\",\"forward\",\"back\",\"back\"] " +
+ "[[\"leetcode.com\"],[\"google.com\"],[\"facebook.com\"],[\"youtube.com\"],[1],[1],[1],[\"linkedin" +
+ ".com\"],[2],[2],[7]]");
+ expectString("[null,null,null,null,\"facebook.com\",\"google.com\",\"facebook.com\",null,\"linkedin.com\"," +
+ "\"google.com\",\"leetcode.com\"]");
+ }
+
+ class BrowserHistory {
+ private List urls;
+ private int currIndex;
+
+ public BrowserHistory(String homepage) {
+ this.urls = new ArrayList<>();
+ this.urls.add(homepage);
+ this.currIndex = 0;
+ }
+
+ public void visit(String url) {
+ while (urls.size() > currIndex + 1) {
+ urls.remove(urls.size() - 1);
+ }
+ urls.add(url);
+ this.currIndex++;
+ }
+
+ public String back(int steps) {
+ currIndex = Math.max(currIndex - steps, 0);
+ return urls.get(currIndex);
+ }
+
+ public String forward(int steps) {
+ currIndex = Math.min(currIndex + steps, urls.size() - 1);
+ return urls.get(currIndex);
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/package-info.java
new file mode 100644
index 0000000..d0a4d13
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/package-info.java
@@ -0,0 +1,7 @@
+/**
+ * Tests for basic function of {@link io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer}
+ * with data structure design problem.
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset4;
\ No newline at end of file
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase01.java
new file mode 100644
index 0000000..c3e8415
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase01.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,null,2,3]", "[]", "[1]");
+ expectString("[1,3,2]", "[]", "[1]");
+ }
+
+ class Solution {
+ public List inorderTraversal(TreeNode root) {
+ List res = new ArrayList();
+ inorder(root, res);
+ return res;
+ }
+
+ public void inorder(TreeNode root, List res) {
+ if (root == null) {
+ return;
+ }
+ inorder(root.left, res);
+ res.add(root.val);
+ inorder(root.right, res);
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase02.java
new file mode 100644
index 0000000..bd8d215
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase02.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[3,9,20,15,7] [9,3,15,20,7]", "[-1] [-1]");
+ expectString("[3,9,20,null,null,15,7]", "[-1]");
+ }
+
+ class Solution {
+ private Map indexMap;
+
+ public TreeNode myBuildTree(int[] preorder, int[] inorder, int preorder_left, int preorder_right,
+ int inorder_left, int inorder_right) {
+ if (preorder_left > preorder_right) {
+ return null;
+ }
+
+ int preorder_root = preorder_left;
+ int inorder_root = indexMap.get(preorder[preorder_root]);
+
+ TreeNode root = new TreeNode(preorder[preorder_root]);
+ int size_left_subtree = inorder_root - inorder_left;
+ root.left = myBuildTree(preorder, inorder, preorder_left + 1, preorder_left + size_left_subtree,
+ inorder_left, inorder_root - 1);
+ root.right = myBuildTree(preorder, inorder, preorder_left + size_left_subtree + 1, preorder_right,
+ inorder_root + 1, inorder_right);
+ return root;
+ }
+
+ public TreeNode buildTree(int[] preorder, int[] inorder) {
+ int n = preorder.length;
+ indexMap = new HashMap();
+ for (int i = 0; i < n; i++) {
+ indexMap.put(inorder[i], i);
+ }
+ return myBuildTree(preorder, inorder, 0, n - 1, 0, n - 1);
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase03.java
new file mode 100644
index 0000000..4952b71
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase03.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase03 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[-10,-3,0,5,9]", "[]");
+ expectString("[0,-3,9,-10,null,5]", "[]");
+ }
+
+ class Solution {
+ public TreeNode sortedListToBST(ListNode head) {
+ return buildTree(head, null);
+ }
+
+ public TreeNode buildTree(ListNode left, ListNode right) {
+ if (left == right) {
+ return null;
+ }
+ ListNode mid = getMedian(left, right);
+ TreeNode root = new TreeNode(mid.val);
+ root.left = buildTree(left, mid);
+ root.right = buildTree(mid.next, right);
+ return root;
+ }
+
+ public ListNode getMedian(ListNode left, ListNode right) {
+ ListNode fast = left;
+ ListNode slow = left;
+ while (fast != right && fast.next != right) {
+ fast = fast.next;
+ fast = fast.next;
+ slow = slow.next;
+ }
+ return slow;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase04.java
new file mode 100644
index 0000000..4428f81
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase04.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,null,2,null,3,null,4,null,null]", "[2,1,3]");
+ expectString("[2,1,3,null,null,null,4]", "[2,1,3]");
+ }
+
+ class Solution {
+ List inorderSeq;
+
+ public TreeNode balanceBST(TreeNode root) {
+ inorderSeq = new ArrayList<>();
+ getInorder(root);
+ return build(0, inorderSeq.size() - 1);
+ }
+
+ private void getInorder(TreeNode o) {
+ if (o.left != null) {
+ getInorder(o.left);
+ }
+ inorderSeq.add(o.val);
+ if (o.right != null) {
+ getInorder(o.right);
+ }
+ }
+
+ private TreeNode build(int l, int r) {
+ int mid = (l + r) >> 1;
+ TreeNode o = new TreeNode(inorderSeq.get(mid));
+ if (l <= mid - 1) {
+ o.left = build(l, mid - 1);
+ }
+ if (mid + 1 <= r) {
+ o.right = build(mid + 1, r);
+ }
+ return o;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase05.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase05.java
new file mode 100644
index 0000000..a02d109
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase05.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase05 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[2,3,5,8,13,21,34]", "[0,1,2,0,0,0,0,1,1,1,1,2,2,2,2]");
+ expectString("[2,5,3,8,13,21,34]", "[0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]");
+ }
+
+ class Solution {
+ public TreeNode reverseOddLevels(TreeNode root) {
+ Queue queue = new ArrayDeque();
+ queue.offer(root);
+ boolean isOdd = false;
+ while (!queue.isEmpty()) {
+ int sz = queue.size();
+ List arr = new ArrayList();
+ for (int i = 0; i < sz; i++) {
+ TreeNode node = queue.poll();
+ if (isOdd) {
+ arr.add(node);
+ }
+ if (node.left != null) {
+ queue.offer(node.left);
+ queue.offer(node.right);
+ }
+ }
+ if (isOdd) {
+ for (int l = 0, r = sz - 1; l < r; l++, r--) {
+ int temp = arr.get(l).val;
+ arr.get(l).val = arr.get(r).val;
+ arr.get(r).val = temp;
+ }
+ }
+ isOdd ^= true;
+ }
+ return root;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase06.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase06.java
new file mode 100644
index 0000000..e5340cd
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase06.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase06 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[5,1,2,3,null,6,4] 3 6", "[2,1] 2 1");
+ expectString("\"UURL\"", "\"L\"");
+ }
+
+ class Solution {
+ StringBuilder res, start, dest;
+
+ public String getDirections(TreeNode root, int startValue, int destValue) {
+ res = new StringBuilder();
+ start = new StringBuilder();
+ dest = new StringBuilder();
+ TreeNode ancestor = findRoot(root, startValue, destValue);
+ dfsStart(ancestor, startValue);
+ dfsDest(ancestor, destValue);
+ return res.toString();
+ }
+
+ private void dfsStart(TreeNode root, int startValue) {
+ if (root == null) {
+ return;
+ }
+ if (root.val == startValue) {
+ res.append(start);
+ return;
+ }
+ start.append("U");
+ dfsStart(root.left, startValue);
+ start.deleteCharAt(start.length() - 1);
+ start.append("U");
+ dfsStart(root.right, startValue);
+ start.deleteCharAt(start.length() - 1);
+ }
+
+ private void dfsDest(TreeNode root, int destValue) {
+ if (root == null) {
+ return;
+ }
+ if (root.val == destValue) {
+ res.append(dest);
+ return;
+ }
+ dest.append("L");
+ dfsDest(root.left, destValue);
+ dest.deleteCharAt(dest.length() - 1);
+ dest.append("R");
+ dfsDest(root.right, destValue);
+ dest.deleteCharAt(dest.length() - 1);
+ }
+
+ private TreeNode findRoot(TreeNode root, int startValue, int destValue) {
+ if (root == null || root.val == startValue || root.val == destValue) return root;
+ TreeNode left = findRoot(root.left, startValue, destValue);
+ TreeNode right = findRoot(root.right, startValue, destValue);
+ if (left == null) return right;
+ if (right == null) return left;
+ return root;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase07.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase07.java
new file mode 100644
index 0000000..82e846f
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase07.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase07 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[3,2,1,6,0,5]", "[3,2,1]");
+ expectString("[6,3,5,null,2,0,null,null,1]", "[3,null,2,null,1]");
+ }
+
+ class Solution {
+ public TreeNode constructMaximumBinaryTree(int[] nums) {
+ return construct(nums, 0, nums.length - 1);
+ }
+
+ public TreeNode construct(int[] nums, int left, int right) {
+ if (left > right) {
+ return null;
+ }
+ int best = left;
+ for (int i = left + 1; i <= right; ++i) {
+ if (nums[i] > nums[best]) {
+ best = i;
+ }
+ }
+ TreeNode node = new TreeNode(nums[best]);
+ node.left = construct(nums, left, best - 1);
+ node.right = construct(nums, best + 1, right);
+ return node;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase08.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase08.java
new file mode 100644
index 0000000..e30360d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase08.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase08 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[3,1,4,null,2] 1", "[5,3,6,2,4,null,null,1] 3");
+ expectString("1", "3");
+ }
+
+ class Solution {
+ public int kthSmallest(TreeNode root, int k) {
+ Deque stack = new ArrayDeque();
+ while (root != null || !stack.isEmpty()) {
+ while (root != null) {
+ stack.push(root);
+ root = root.left;
+ }
+ root = stack.pop();
+ --k;
+ if (k == 0) {
+ break;
+ }
+ root = root.right;
+ }
+ return root.val;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase09.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase09.java
new file mode 100644
index 0000000..46c2d5d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase09.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase09 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[2,1,4] [1,0,3]", "[1,null,8] [8,1]");
+ expectString("[0,1,1,2,3,4]", "[1,1,8,8]");
+ }
+
+ class Solution {
+ public List getAllElements(TreeNode root1, TreeNode root2) {
+ List nums1 = new ArrayList();
+ List nums2 = new ArrayList();
+ inorder(root1, nums1);
+ inorder(root2, nums2);
+
+ List merged = new ArrayList();
+ int p1 = 0, p2 = 0;
+ while (true) {
+ if (p1 == nums1.size()) {
+ merged.addAll(nums2.subList(p2, nums2.size()));
+ break;
+ }
+ if (p2 == nums2.size()) {
+ merged.addAll(nums1.subList(p1, nums1.size()));
+ break;
+ }
+ if (nums1.get(p1) < nums2.get(p2)) {
+ merged.add(nums1.get(p1++));
+ } else {
+ merged.add(nums2.get(p2++));
+ }
+ }
+ return merged;
+ }
+
+ private void inorder(TreeNode node, List res) {
+ if (node != null) {
+ inorder(node.left, res);
+ res.add(node.val);
+ inorder(node.right, res);
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase10.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase10.java
new file mode 100644
index 0000000..0a9a980
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase10.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+/**
+ * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}
+ * with data structure {@link TreeNode}.
+ *
+ * @author Jidcoo
+ */
+public class TestSet5_TestCase10 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[1,0,2] 1 2", "[3,0,4,null,2,null,null,1] 1 3");
+ expectString("[1,null,2]", "[3,2,null,1]");
+ }
+
+ class Solution {
+ public TreeNode trimBST(TreeNode root, int low, int high) {
+ if (root == null) {
+ return null;
+ }
+ if (root.val < low) {
+ return trimBST(root.right, low, high);
+ } else if (root.val > high) {
+ return trimBST(root.left, low, high);
+ } else {
+ root.left = trimBST(root.left, low, high);
+ root.right = trimBST(root.right, low, high);
+ return root;
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/package-info.java
new file mode 100644
index 0000000..2a2a80f
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/package-info.java
@@ -0,0 +1,7 @@
+/**
+ * Tests for basic function of {@link io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer}
+ * with data structure {@link io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode}.
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset5;
\ No newline at end of file
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_AddSolution.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_AddSolution.java
new file mode 100644
index 0000000..8ba1918
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_AddSolution.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+final class TestSet6_AddSolution {
+
+ public int add(int a, int b) {
+ return a + b + 1;
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_LRUCache.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_LRUCache.java
new file mode 100644
index 0000000..8bd8fc0
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_LRUCache.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+import java.util.HashMap;
+import java.util.Map;
+
+final class TestSet6_LRUCache {
+ private Map cache = new HashMap();
+ private int size;
+ private int capacity;
+ private DLinkedNode head, tail;
+
+ public TestSet6_LRUCache(int capacity) {
+ this.size = 0;
+ this.capacity = capacity;
+ head = new DLinkedNode();
+ tail = new DLinkedNode();
+ head.next = tail;
+ tail.prev = head;
+ }
+
+ public int get(int key) {
+ DLinkedNode node = cache.get(key);
+ if (node == null) {
+ return -1;
+ }
+ moveToHead(node);
+ return node.value;
+ }
+
+ public void put(int key, int value) {
+ DLinkedNode node = cache.get(key);
+ if (node == null) {
+ DLinkedNode newNode = new DLinkedNode(key, value);
+ cache.put(key, newNode);
+ addToHead(newNode);
+ ++size;
+ if (size > capacity) {
+ DLinkedNode tail = removeTail();
+ cache.remove(tail.key);
+ --size;
+ }
+ } else {
+ node.value = value;
+ moveToHead(node);
+ }
+ }
+
+ private void addToHead(DLinkedNode node) {
+ node.prev = head;
+ node.next = head.next;
+ head.next.prev = node;
+ head.next = node;
+ }
+
+ private void removeNode(DLinkedNode node) {
+ node.prev.next = node.next;
+ node.next.prev = node.prev;
+ }
+
+ private void moveToHead(DLinkedNode node) {
+ removeNode(node);
+ addToHead(node);
+ }
+
+ private DLinkedNode removeTail() {
+ DLinkedNode res = tail.prev;
+ removeNode(res);
+ return res;
+ }
+
+ class DLinkedNode {
+ int key;
+ int value;
+ DLinkedNode prev;
+ DLinkedNode next;
+
+ public DLinkedNode() {
+ }
+
+ public DLinkedNode(int _key, int _value) {
+ key = _key;
+ value = _value;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_OuterSolutionWithAlias.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_OuterSolutionWithAlias.java
new file mode 100644
index 0000000..618bbb5
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_OuterSolutionWithAlias.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+final class TestSet6_OuterSolutionWithAlias {
+
+ 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];
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase01.java
new file mode 100644
index 0000000..77d14d4
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase01.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()}
+ *
+ * @author Jidcoo
+ */
+public class TestSet6_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[2,7,11,15] 9", "[3,2,4] 6", "[3,3] 6");
+ expectString("[0,1]", "[1,2]", "[0,1]");
+ }
+
+ @Override
+ public Class> getEnhancerPayload() {
+ return SolutionWithAlias.class;
+ }
+
+ class SolutionWithAlias {
+ 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];
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase02.java
new file mode 100644
index 0000000..d2db530
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase02.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()}
+ *
+ * @author Jidcoo
+ */
+public class TestSet6_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[2,7,11,15] 9", "[3,2,4] 6", "[3,3] 6");
+ expectString("[0,1]", "[1,2]", "[0,1]");
+ }
+
+ @Override
+ public Class> getEnhancerPayload() {
+ return TestSet6_OuterSolutionWithAlias.class;
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase03.java
new file mode 100644
index 0000000..334a04d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase03.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()}
+ *
+ * @author Jidcoo
+ */
+public class TestSet6_TestCase03 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("1 2", "2 3");
+ expectString("4", "6");
+ }
+
+ @Override
+ public Class> getEnhancerPayload() {
+ return TestSet6_AddSolution.class;
+ }
+
+ class Solution {
+
+ public int add(int a, int b) {
+ return a + b;
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase04.java
new file mode 100644
index 0000000..94a8447
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase04.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()}
+ *
+ * @author Jidcoo
+ */
+public class TestSet6_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", " +
+ "\"get\", \"get\", \"get\"] " +
+ "[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]");
+ expectString("[null,null,null,1,null,-1,null,-1,3,4]");
+ }
+
+ @Override
+ public Class> getEnhancerPayload() {
+ return LRUCache.class;
+ }
+
+ class LRUCache {
+ private Map cache = new HashMap();
+ private int size;
+ private int capacity;
+ private DLinkedNode head, tail;
+
+ public LRUCache(int capacity) {
+ this.size = 0;
+ this.capacity = capacity;
+ head = new DLinkedNode();
+ tail = new DLinkedNode();
+ head.next = tail;
+ tail.prev = head;
+ }
+
+ public int get(int key) {
+ DLinkedNode node = cache.get(key);
+ if (node == null) {
+ return -1;
+ }
+ moveToHead(node);
+ return node.value;
+ }
+
+ public void put(int key, int value) {
+ DLinkedNode node = cache.get(key);
+ if (node == null) {
+ DLinkedNode newNode = new DLinkedNode(key, value);
+ cache.put(key, newNode);
+ addToHead(newNode);
+ ++size;
+ if (size > capacity) {
+ DLinkedNode tail = removeTail();
+ cache.remove(tail.key);
+ --size;
+ }
+ } else {
+ node.value = value;
+ moveToHead(node);
+ }
+ }
+
+ private void addToHead(DLinkedNode node) {
+ node.prev = head;
+ node.next = head.next;
+ head.next.prev = node;
+ head.next = node;
+ }
+
+ private void removeNode(DLinkedNode node) {
+ node.prev.next = node.next;
+ node.next.prev = node.prev;
+ }
+
+ private void moveToHead(DLinkedNode node) {
+ removeNode(node);
+ addToHead(node);
+ }
+
+ private DLinkedNode removeTail() {
+ DLinkedNode res = tail.prev;
+ removeNode(res);
+ return res;
+ }
+
+ class DLinkedNode {
+ int key;
+ int value;
+ DLinkedNode prev;
+ DLinkedNode next;
+
+ public DLinkedNode() {
+ }
+
+ public DLinkedNode(int _key, int _value) {
+ key = _key;
+ value = _value;
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase05.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase05.java
new file mode 100644
index 0000000..5a2729d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase05.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
+
+import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import org.junit.Before;
+
+/**
+ * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()}
+ *
+ * @author Jidcoo
+ */
+public class TestSet6_TestCase05 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[\"TestSet6_LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", " +
+ "\"get\", \"get\", \"get\"] " +
+ "[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]");
+ expectString("[null,null,null,1,null,-1,null,-1,3,4]");
+ }
+
+ @Override
+ public Class> getEnhancerPayload() {
+ return TestSet6_LRUCache.class;
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/package-info.java
new file mode 100644
index 0000000..2782916
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * Tests for {@link io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer#getEnhancerPayload()}
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset6;
\ No newline at end of file
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase01.java
new file mode 100644
index 0000000..2eb1193
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase01.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset7;
+
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+/**
+ * Tests for {@link io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin.BasicListParameterAcceptStrategy}
+ *
+ * @author Jidcoo
+ */
+public class TestSet7_TestCase01 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[3,null,2]");
+ ignoreTestResult();
+ }
+
+ class Solution {
+ public void tree(TreeNode node) {
+
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase02.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase02.java
new file mode 100644
index 0000000..76eaffb
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase02.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset7;
+
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.List;
+
+/**
+ * Tests for {@link io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin.BasicListParameterAcceptStrategy}
+ *
+ * @author Jidcoo
+ */
+public class TestSet7_TestCase02 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[[3.0,null,2]]");
+ expectString("1");
+ }
+
+ class Solution {
+ public int tree(List node) {
+ return node.size();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase03.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase03.java
new file mode 100644
index 0000000..3a0ce1d
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase03.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset7;
+
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.List;
+
+/**
+ * Tests for {@link io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin.BasicListParameterAcceptStrategy}
+ *
+ * @author Jidcoo
+ */
+public class TestSet7_TestCase03 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[[3.0,null,2],[3.0,null,2]]");
+ expectString("2");
+ }
+
+ class Solution {
+ public int tree(List node) {
+ return node.size();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase04.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase04.java
new file mode 100644
index 0000000..ea14439
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase04.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package io.github.jidcoo.opto.lcdb.enhancer.testset7;
+
+import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver;
+import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode;
+import org.junit.Before;
+
+import java.util.List;
+
+/**
+ * Tests for {@link io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin.BasicListParameterAcceptStrategy}
+ *
+ * @author Jidcoo
+ */
+public class TestSet7_TestCase04 extends UnitTestDriver {
+
+ @Before
+ public void onBefore() {
+ registerDriverWithAutoCustomStdIn("[[[3.0,null,2,3,null,2.0]]]");
+ expectString("1");
+ }
+
+ class Solution {
+ public int tree(List> node) {
+ return node.size();
+ }
+ }
+}
diff --git a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/package-info.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/package-info.java
new file mode 100644
index 0000000..180902e
--- /dev/null
+++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * Tests for {@link io.github.jidcoo.opto.lcdb.enhancer.core.parser.builtin.BasicListParameterAcceptStrategy}
+ *
+ * @author Jidcoo
+ */
+package io.github.jidcoo.opto.lcdb.enhancer.testset7;
\ No newline at end of file