From 42f4d65ec8c8deb195584d26771e4f095049f7ef Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Fri, 28 Feb 2025 08:42:14 +0800 Subject: [PATCH 01/32] Add test framework. --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 718bd76..e2a3128 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,13 @@ gson 2.10.1 + + + junit + junit + 4.13.2 + test + From 32b555b39ab87e5465df99dc06a1cb70f3a5cd02 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 2 Mar 2025 22:51:29 +0800 Subject: [PATCH 02/32] add junit test framework. --- .gitignore | 3 +- .../opto/lcdb/enhancer/UnitTestDriver.java | 193 ++++++++++++++++++ .../testset1/TestSet1_TestCase01.java | 27 +++ .../testset1/TestSet1_TestCase02.java | 31 +++ .../testset1/TestSet1_TestCase03.java | 31 +++ .../testset1/TestSet1_TestCase04.java | 37 ++++ .../testset1/TestSet1_TestCase05.java | 23 +++ .../testset1/TestSet1_TestCase06.java | 51 +++++ .../testset1/TestSet1_TestCase07.java | 68 ++++++ .../testset1/TestSet1_TestCase08.java | 34 +++ .../testset1/TestSet1_TestCase09.java | 67 ++++++ .../testset1/TestSet1_TestCase10.java | 33 +++ .../testset2/TestSet2_TestCase01.java | 38 ++++ .../testset2/TestSet2_TestCase02.java | 94 +++++++++ .../testset2/TestSet2_TestCase03.java | 25 +++ .../testset2/TestSet2_TestCase04.java | 42 ++++ .../testset2/TestSet2_TestCase05.java | 47 +++++ .../testset2/TestSet2_TestCase06.java | 32 +++ .../testset2/TestSet2_TestCase07.java | 39 ++++ .../testset2/TestSet2_TestCase08.java | 49 +++++ .../testset2/TestSet2_TestCase09.java | 53 +++++ .../testset2/TestSet2_TestCase10.java | 42 ++++ .../testset3/TestSet3_TestCase01.java | 34 +++ .../testset3/TestSet3_TestCase02.java | 55 +++++ .../testset3/TestSet3_TestCase03.java | 40 ++++ .../testset3/TestSet3_TestCase04.java | 36 ++++ .../testset3/TestSet3_TestCase05.java | 45 ++++ .../testset3/TestSet3_TestCase06.java | 45 ++++ .../testset3/TestSet3_TestCase07.java | 54 +++++ .../testset3/TestSet3_TestCase08.java | 34 +++ .../testset3/TestSet3_TestCase09.java | 34 +++ .../testset3/TestSet3_TestCase10.java | 40 ++++ .../testset4/TestSet4_TestCase01.java | 103 ++++++++++ .../testset4/TestSet4_TestCase02.java | 46 +++++ .../testset4/TestSet4_TestCase03.java | 86 ++++++++ .../testset4/TestSet4_TestCase04.java | 30 +++ .../testset4/TestSet4_TestCase05.java | 39 ++++ .../testset4/TestSet4_TestCase06.java | 72 +++++++ .../testset4/TestSet4_TestCase07.java | 89 ++++++++ .../testset4/TestSet4_TestCase08.java | 48 +++++ .../testset4/TestSet4_TestCase09.java | 39 ++++ .../testset4/TestSet4_TestCase10.java | 37 ++++ .../testset4/TestSet4_TestCase11.java | 59 ++++++ .../testset4/TestSet4_TestCase12.java | 54 +++++ .../testset4/TestSet4_TestCase13.java | 101 +++++++++ .../testset4/TestSet4_TestCase14.java | 58 ++++++ .../testset4/TestSet4_TestCase15.java | 103 ++++++++++ .../testset4/TestSet4_TestCase16.java | 76 +++++++ .../testset4/TestSet4_TestCase17.java | 114 +++++++++++ .../testset4/TestSet4_TestCase18.java | 36 ++++ .../testset4/TestSet4_TestCase19.java | 54 +++++ .../testset4/TestSet4_TestCase20.java | 49 +++++ .../testset5/TestSet5_TestCase01.java | 34 +++ .../testset5/TestSet5_TestCase02.java | 48 +++++ .../testset5/TestSet5_TestCase03.java | 43 ++++ .../testset5/TestSet5_TestCase04.java | 49 +++++ .../testset5/TestSet5_TestCase05.java | 50 +++++ .../testset5/TestSet5_TestCase06.java | 69 +++++++ .../testset5/TestSet5_TestCase07.java | 36 ++++ .../testset5/TestSet5_TestCase08.java | 36 ++++ .../testset5/TestSet5_TestCase09.java | 53 +++++ .../testset5/TestSet5_TestCase10.java | 31 +++ 62 files changed, 3216 insertions(+), 2 deletions(-) create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase05.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase06.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase07.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase08.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase09.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase10.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase05.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase06.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase07.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase08.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase09.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase10.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase05.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase06.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase07.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase08.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase09.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase10.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase05.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase06.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase07.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase08.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase09.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase10.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase11.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase12.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase13.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase14.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase15.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase16.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase17.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase18.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase19.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase20.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase05.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase06.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase07.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase08.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase09.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase10.java diff --git a/.gitignore b/.gitignore index 5cf5b5d..b12591b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /LeetcodeJavaDebugEnhancer.iml /target/ -/.idea/ -/src/test/ +/.idea/ \ No newline at end of file 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..616cd11 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java @@ -0,0 +1,193 @@ +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; + +@RunWith(JUnit4.class) +public abstract class UnitTestDriver extends LeetcodeJavaDebugEnhancer { + + 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__); + LeetcodeJavaDebugEnhancer.main(null); + 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); + } + + protected final void ignoreTestResult() { + if (!__IS__IGNORED__OUTPUT__) { + __IS__IGNORED__OUTPUT__ = true; + } + } + + 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(); + } + + protected final void registerDriver() { + if (!__IS__REGISTERED__) { + System.setProperty("sun.java.command", this.getClass().getName()); + __IS__REGISTERED__ = true; + } + } + + 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..c329a96 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase01.java @@ -0,0 +1,27 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..44a6172 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase02.java @@ -0,0 +1,31 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +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; + +@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..a37558d --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase03.java @@ -0,0 +1,31 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +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; + +@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..c801ef2 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase04.java @@ -0,0 +1,37 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +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; + +@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..952cf10 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase05.java @@ -0,0 +1,23 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..1af2614 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase06.java @@ -0,0 +1,51 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +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..7b5ae74 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase07.java @@ -0,0 +1,68 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..9b2c482 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase08.java @@ -0,0 +1,34 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..8ad1605 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase09.java @@ -0,0 +1,67 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.List; + +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..abeb306 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/TestSet1_TestCase10.java @@ -0,0 +1,33 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset1; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode; +import org.junit.Before; + +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/testset2/TestSet2_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase01.java new file mode 100644 index 0000000..459be01 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase01.java @@ -0,0 +1,38 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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; + +@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..01d641f --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase02.java @@ -0,0 +1,94 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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.*; + +@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..9323dfb --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase03.java @@ -0,0 +1,25 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..571a5dc --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase04.java @@ -0,0 +1,42 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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; + +@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..fcad24a --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase05.java @@ -0,0 +1,47 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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; + +@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..9195523 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase06.java @@ -0,0 +1,32 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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; + +@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..0ee496e --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase07.java @@ -0,0 +1,39 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..717e5f7 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase08.java @@ -0,0 +1,49 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.List; + +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..8a7d64b --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase09.java @@ -0,0 +1,53 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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; + +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..fbe980b --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/TestSet2_TestCase10.java @@ -0,0 +1,42 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset2; + +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; + +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/testset3/TestSet3_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase01.java new file mode 100644 index 0000000..60145b8 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase01.java @@ -0,0 +1,34 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode; +import org.junit.Before; + +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..b125bbd --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase02.java @@ -0,0 +1,55 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode; +import org.junit.Before; + +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..be06d84 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase03.java @@ -0,0 +1,40 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +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; + +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..6e575c6 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase04.java @@ -0,0 +1,36 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +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; + +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..28a34c4 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase05.java @@ -0,0 +1,45 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +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; + +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..0ce1878 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase06.java @@ -0,0 +1,45 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +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; + +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..e66eb4e --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase07.java @@ -0,0 +1,54 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +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.*; + +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..cb354ee --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase08.java @@ -0,0 +1,34 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode; +import org.junit.Before; + +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..394c9e8 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase09.java @@ -0,0 +1,34 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode; +import org.junit.Before; + +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..022d736 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/TestSet3_TestCase10.java @@ -0,0 +1,40 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset3; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode; +import org.junit.Before; + + +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/testset4/TestSet4_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase01.java new file mode 100644 index 0000000..b6f45a2 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase01.java @@ -0,0 +1,103 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +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; + +@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..7448347 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase02.java @@ -0,0 +1,46 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.Deque; +import java.util.LinkedList; + +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..a149ced --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase03.java @@ -0,0 +1,86 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..933dec8 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase04.java @@ -0,0 +1,30 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..d28a426 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase05.java @@ -0,0 +1,39 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..f09870a --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase06.java @@ -0,0 +1,72 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..04db4e7 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase07.java @@ -0,0 +1,89 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +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; + +@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..e0143e5 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase08.java @@ -0,0 +1,48 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..ff8757a --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase09.java @@ -0,0 +1,39 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.HashMap; +import java.util.Map; + +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..75ab01d --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase10.java @@ -0,0 +1,37 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.PriorityQueue; + +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..f3c6325 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase11.java @@ -0,0 +1,59 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..7733a97 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase12.java @@ -0,0 +1,54 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..e17f628 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase13.java @@ -0,0 +1,101 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +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..dfc5197 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase14.java @@ -0,0 +1,58 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.List; + +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..b70d95d --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase15.java @@ -0,0 +1,103 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.LinkedList; +import java.util.Queue; + +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..a14b587 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase16.java @@ -0,0 +1,76 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.*; + +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..1318e4b --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase17.java @@ -0,0 +1,114 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +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; + +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..53172cc --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase18.java @@ -0,0 +1,36 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.List; + +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..917399b --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase19.java @@ -0,0 +1,54 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +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; + +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..7b4e772 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/TestSet4_TestCase20.java @@ -0,0 +1,49 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset4; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import org.junit.Before; + +import java.util.ArrayList; +import java.util.List; + +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/testset5/TestSet5_TestCase01.java b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase01.java new file mode 100644 index 0000000..19552d1 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase01.java @@ -0,0 +1,34 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..b9f5b53 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase02.java @@ -0,0 +1,48 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..8118777 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase03.java @@ -0,0 +1,43 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..53da218 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase04.java @@ -0,0 +1,49 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..73c6390 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase05.java @@ -0,0 +1,50 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..8c5d7f8 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase06.java @@ -0,0 +1,69 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode; +import org.junit.Before; + +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..3a1e1de --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase07.java @@ -0,0 +1,36 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode; +import org.junit.Before; + +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..6d58bcc --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase08.java @@ -0,0 +1,36 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..0826bd4 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase09.java @@ -0,0 +1,53 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +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; + +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..08ca4cc --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/TestSet5_TestCase10.java @@ -0,0 +1,31 @@ +package io.github.jidcoo.opto.lcdb.enhancer.testset5; + +import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; +import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode; +import org.junit.Before; + +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; + } + } + } +} From 2a12ca18b645b64be76df98f337bf9598717f28f Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Mon, 3 Mar 2025 23:16:56 +0800 Subject: [PATCH 03/32] add docs. --- .../opto/lcdb/enhancer/UnitTestDriver.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) 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 index 616cd11..3046033 100644 --- a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java @@ -1,3 +1,19 @@ +/* + * 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; @@ -20,6 +36,16 @@ 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 LeetcodeJavaDebugEnhancer { @@ -79,12 +105,20 @@ public OutputConsumer getOutputConsumer() { 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; @@ -99,6 +133,13 @@ protected final void expectString(String... expectedResult) { __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__) { System.setProperty("sun.java.command", this.getClass().getName()); @@ -106,6 +147,14 @@ protected final void registerDriver() { } } + /** + * 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) { From 264077331b2fa9726c29ef36f341fea77ec4505d Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Wed, 5 Mar 2025 23:25:50 +0800 Subject: [PATCH 04/32] Add docs for tests. --- .../testset1/TestSet1_TestCase01.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase02.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase03.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase04.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase05.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase06.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase07.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase08.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase09.java | 22 +++++++++++++++++ .../testset1/TestSet1_TestCase10.java | 22 +++++++++++++++++ .../lcdb/enhancer/testset1/package-info.java | 6 +++++ .../testset2/TestSet2_TestCase01.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase02.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase03.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase04.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase05.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase06.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase07.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase08.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase09.java | 22 +++++++++++++++++ .../testset2/TestSet2_TestCase10.java | 22 +++++++++++++++++ .../lcdb/enhancer/testset2/package-info.java | 6 +++++ .../testset3/TestSet3_TestCase01.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase02.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase03.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase04.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase05.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase06.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase07.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase08.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase09.java | 23 ++++++++++++++++++ .../testset3/TestSet3_TestCase10.java | 24 ++++++++++++++++++- .../lcdb/enhancer/testset3/package-info.java | 7 ++++++ .../testset4/TestSet4_TestCase01.java | 24 +++++++++++++++++++ .../testset4/TestSet4_TestCase02.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase03.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase04.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase05.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase06.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase07.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase08.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase09.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase10.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase11.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase12.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase13.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase14.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase15.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase16.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase17.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase18.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase19.java | 23 ++++++++++++++++++ .../testset4/TestSet4_TestCase20.java | 23 ++++++++++++++++++ .../lcdb/enhancer/testset4/package-info.java | 7 ++++++ .../testset5/TestSet5_TestCase01.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase02.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase03.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase04.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase05.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase06.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase07.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase08.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase09.java | 23 ++++++++++++++++++ .../testset5/TestSet5_TestCase10.java | 23 ++++++++++++++++++ .../lcdb/enhancer/testset5/package-info.java | 7 ++++++ 65 files changed, 1394 insertions(+), 1 deletion(-) create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset1/package-info.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset2/package-info.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset3/package-info.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset4/package-info.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset5/package-info.java 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 index c329a96..93af2e5 100644 --- 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 @@ -1,8 +1,30 @@ +/* + * 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 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 index 44a6172..f3131ae 100644 --- 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 @@ -1,10 +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.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 { 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 index a37558d..aeea336 100644 --- 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 @@ -1,10 +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.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 { 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 index c801ef2..e0da503 100644 --- 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 @@ -1,10 +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.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 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 index 952cf10..2165cd1 100644 --- 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 @@ -1,8 +1,30 @@ +/* + * 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 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 index 1af2614..32e15d6 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,11 @@ import java.util.Arrays; import java.util.List; +/** + * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}. + * + * @author Jidcoo + */ public class TestSet1_TestCase06 extends UnitTestDriver { @Before 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 index 7b5ae74..60ee2ba 100644 --- 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 @@ -1,8 +1,30 @@ +/* + * 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 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 index 9b2c482..5690802 100644 --- 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 @@ -1,8 +1,30 @@ +/* + * 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 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 index 8ad1605..91903d7 100644 --- 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 @@ -1,11 +1,33 @@ +/* + * 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() { 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 index abeb306..d7dfb76 100644 --- 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 @@ -1,9 +1,31 @@ +/* + * 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 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 index 459be01..9a0eec1 100644 --- 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 @@ -1,10 +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.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 { 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 index 01d641f..2705977 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,11 @@ 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 { 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 index 9323dfb..bd67777 100644 --- 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 @@ -1,8 +1,30 @@ +/* + * 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 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 index 571a5dc..e80c8df 100644 --- 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 @@ -1,11 +1,33 @@ +/* + * 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 { 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 index fcad24a..86c5fed 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,11 @@ 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 { 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 index 9195523..30be77e 100644 --- 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 @@ -1,11 +1,33 @@ +/* + * 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 { 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 index 0ee496e..40766c8 100644 --- 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 @@ -1,8 +1,30 @@ +/* + * 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 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 index 717e5f7..ebb2bcf 100644 --- 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 @@ -1,11 +1,33 @@ +/* + * 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 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 index 8a7d64b..a1311fd 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -8,6 +25,11 @@ import java.util.List; import java.util.PriorityQueue; +/** + * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}. + * + * @author Jidcoo + */ public class TestSet2_TestCase09 extends UnitTestDriver { @Before 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 index fbe980b..353fe7d 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -8,6 +25,11 @@ import java.util.List; import java.util.Map; +/** + * Tests for basic function of {@link LeetcodeJavaDebugEnhancer}. + * + * @author Jidcoo + */ public class TestSet2_TestCase10 extends UnitTestDriver { @Before 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 index 60145b8..c656e2b 100644 --- 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 @@ -1,9 +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.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 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 index b125bbd..3d8740d 100644 --- 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 @@ -1,9 +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.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 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 index be06d84..728df52 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 6e575c6..66e61db 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 28a34c4..4579a71 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 0ce1878..40b0641 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -9,6 +26,12 @@ 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 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 index e66eb4e..aa425e9 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index cb354ee..007d80a 100644 --- 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 @@ -1,9 +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.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 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 index 394c9e8..5c7f04e 100644 --- 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 @@ -1,9 +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.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 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 index 022d736..1f60d3a 100644 --- 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 @@ -1,10 +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.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 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 index b6f45a2..c9ccbd5 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -9,6 +26,12 @@ 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 { @@ -26,6 +49,7 @@ class LRUCache { private int size; private int capacity; private DLinkedNode head, tail; + public LRUCache(int capacity) { this.size = 0; this.capacity = capacity; 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 index 7448347..aadd1ba 100644 --- 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 @@ -1,11 +1,34 @@ +/* + * 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 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 index a149ced..bdaa9a4 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 { 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 index 933dec8..f6c2f71 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index d28a426..f6f016b 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index f09870a..8fabccc 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index 04db4e7..7a5012c 100644 --- 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 @@ -1,10 +1,33 @@ +/* + * 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\", " + 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 index e0143e5..5dceaf4 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index ff8757a..077e3ae 100644 --- 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 @@ -1,11 +1,34 @@ +/* + * 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 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 index 75ab01d..54c52aa 100644 --- 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 @@ -1,10 +1,33 @@ +/* + * 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 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 index f3c6325..0ed9823 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index 7733a97..4469068 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index e17f628..4f72679 100644 --- 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 @@ -1,8 +1,31 @@ +/* + * 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 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 index dfc5197..f42463e 100644 --- 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 @@ -1,11 +1,34 @@ +/* + * 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 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 index b70d95d..ea237ca 100644 --- 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 @@ -1,11 +1,34 @@ +/* + * 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 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 index a14b587..2112e9e 100644 --- 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 @@ -1,10 +1,33 @@ +/* + * 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 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 index 1318e4b..3fb6685 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -8,6 +25,12 @@ 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 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 index 53172cc..9bbf786 100644 --- 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 @@ -1,11 +1,34 @@ +/* + * 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 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 index 917399b..a9e98f6 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -8,6 +25,12 @@ 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 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 index 7b4e772..06109d0 100644 --- 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 @@ -1,11 +1,34 @@ +/* + * 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 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 index 19552d1..c3e8415 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index b9f5b53..bd8d215 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 8118777..4952b71 100644 --- 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 @@ -1,10 +1,33 @@ +/* + * 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 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 index 53da218..4428f81 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 73c6390..a02d109 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -9,6 +26,12 @@ 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 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 index 8c5d7f8..e5340cd 100644 --- 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 @@ -1,9 +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.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 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 index 3a1e1de..82e846f 100644 --- 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 @@ -1,9 +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.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 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 index 6d58bcc..e30360d 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 0826bd4..46c2d5d 100644 --- 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 @@ -1,5 +1,22 @@ +/* + * 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; @@ -7,6 +24,12 @@ 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 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 index 08ca4cc..0a9a980 100644 --- 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 @@ -1,9 +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.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 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 From 18761dc6d2b675e1f03c302f36374932b9c34c01 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 9 Mar 2025 15:25:34 +0800 Subject: [PATCH 05/32] JDK dynamic proxy upgrade. --- .../enhancer/LeetcodeJavaDebugEnhancer.java | 59 ++-- .../lcdb/enhancer/base/LeetcodeInvoker.java | 9 + .../LeetcodeJavaDebugEnhanceProcessor.java | 7 +- .../executor/ConstructorLeetcodeInvoker.java | 28 +- .../core/executor/MethodLeetcodeInvoker.java | 12 + ...ataStructureDesignScenePipelineRunner.java | 13 - .../LeetcodeJavaDebugEnhancerPipeline.java | 57 ++++ ...odeJavaDebugEnhancerPipelineProcessor.java | 48 +--- .../core/proxy/DebugEnhancerProxy.java | 254 ------------------ .../core/proxy/EnhancerProxyFactory.java | 71 +++++ .../core/proxy/EnhancerProxyHandler.java | 143 ++++++++++ .../proxy/ProxyPointInterceptorManager.java | 19 +- .../core/proxy/ProxyPointParameterView.java | 4 +- .../payload/EnhancerPayloadInterceptor.java | 96 +++++++ .../require/io/AbsIORequireSupporter.java | 10 +- 15 files changed, 458 insertions(+), 372 deletions(-) delete mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/DebugEnhancerProxy.java create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyFactory.java create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/EnhancerProxyHandler.java create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/payload/EnhancerPayloadInterceptor.java diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java index c8e8b06..afd6681 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java @@ -30,39 +30,19 @@ /** *

Let's start our dreams here! [↖(^ω^)↗]

* - *

LeetcodeJavaDebugEnhancer is a debugging enhanced startup class.

+ *

LeetcodeJavaDebugEnhancer is a debugging enhanced startup interface class.

*

A public algorithm class is called Algorithm-Target(AT).

- *

Notice: All AT that require debugging must extends from this class!!!

+ *

Notice: All AT that require debugging must implement this interface!!!

* * @author Jidcoo * @since 1.0 */ -public abstract class LeetcodeJavaDebugEnhancer { +public interface LeetcodeJavaDebugEnhancer { /** * LeetcodeJavaDebugEnhancer version. */ - private static final String VERSION = "1.0.2"; - - /** - *

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 +54,7 @@ public Method getEnhancementPoint() { * * @return the input provider. */ - public InputProvider getInputProvider() { + default InputProvider getInputProvider() { return null; } @@ -88,7 +68,7 @@ public InputProvider getInputProvider() { * * @return the output consumer. */ - public OutputConsumer getOutputConsumer() { + default OutputConsumer getOutputConsumer() { return null; } @@ -100,7 +80,7 @@ public OutputConsumer getOutputConsumer() { * * @return a list of printing strategies */ - public List> getOutputPrintStrategies() { + default List> getOutputPrintStrategies() { return null; } @@ -117,26 +97,39 @@ 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; + } + /** * 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"); + static void run(String __AT__) { System.out.println("LeetcodeJavaDebugEnhancer[" + VERSION + "] started."); if (!"io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer".equals(__AT__)) { try { diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java index 70efdcd..71b2df6 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java @@ -118,4 +118,13 @@ public interface LeetcodeInvoker { * include type parameters */ String toGenericString(); + + /** + * Verify whether this leetcode invoke is suitable for the specified class. + * + * @param klass the specified class. + * @return true if suitable. + * @since 1.0.3 + */ + boolean isSuitable(Class klass); } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/LeetcodeJavaDebugEnhanceProcessor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/LeetcodeJavaDebugEnhanceProcessor.java index 89702b8..c8c6ba2 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/LeetcodeJavaDebugEnhanceProcessor.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/LeetcodeJavaDebugEnhanceProcessor.java @@ -18,9 +18,8 @@ import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer; import io.github.jidcoo.opto.lcdb.enhancer.core.pipeline.LeetcodeJavaDebugEnhancerPipelineProcessor; -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.EnhancerLogUtil; -import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil; /** *

LeetcodeJavaDebugEnhanceProcessor is a primary enhancer.

@@ -47,8 +46,8 @@ public final class LeetcodeJavaDebugEnhanceProcessor { * @param AT the AT class. */ public static void process(Class AT) throws Exception, Error { - // Create an AT instance enhancer at first and then wrap it as a proxy(DebugEnhancerProxy since 1.0.2). - LeetcodeJavaDebugEnhancer enhancer = new DebugEnhancerProxy(ReflectUtil.createInstance(AT)); + // Create A LeetcodeJavaDebugEnhancer proxy instance by AT Class(EnhancerProxyFactory since 1.0.3). + LeetcodeJavaDebugEnhancer enhancer = EnhancerProxyFactory.createEnhancerProxy(AT); // Setup EnhancerLog log level. EnhancerLogUtil.setLogLevel(enhancer.getEnhancerLogLevel()); diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java index a7e274c..f55a83a 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java @@ -50,6 +50,11 @@ final class ConstructorLeetcodeInvoker implements LeetcodeInvoker { */ private boolean matchingFriendly; + /** + * Mark whether the class corresponding to the constructor of this class is an inner class. + */ + private boolean isInnerClassConstructor; + /** * Create a ConstructorLeetcodeInvoker instance. * @@ -59,6 +64,7 @@ final class ConstructorLeetcodeInvoker implements LeetcodeInvoker { ConstructorLeetcodeInvoker(Constructor constructor, Integer id) { AssertUtil.nonNull(constructor, "The constructor cannot be null."); this.constructor = constructor; + this.isInnerClassConstructor = constructor.getDeclaringClass().getEnclosingClass() != null; // Make accessible. this.constructor.setAccessible(true); this.id = id; @@ -84,7 +90,7 @@ public Integer getId() { @Override public int getParameterCount() { int parameterCount = this.constructor.getParameterCount(); - if (parameterCount > 0 && matchingFriendly) { + if (parameterCount > 0 && matchingFriendly && isInnerClassConstructor) { return parameterCount - 1; } return parameterCount; @@ -98,7 +104,7 @@ public int getParameterCount() { @Override public String getInvokerName() { String name = this.constructor.getName(); - if (name.contains("$") && matchingFriendly) { + if (matchingFriendly && isInnerClassConstructor) { return name.substring(name.lastIndexOf('$') + 1); } return name; @@ -112,7 +118,7 @@ public String getInvokerName() { @Override public Class[] getParameterTypes() { Class[] parameterTypes = this.constructor.getParameterTypes(); - if (parameterTypes.length > 0 && matchingFriendly) { + if (parameterTypes.length > 0 && matchingFriendly && isInnerClassConstructor) { return Arrays.stream(parameterTypes).skip(1).toArray(Class[]::new); } return parameterTypes; @@ -126,7 +132,7 @@ public Class[] getParameterTypes() { @Override public Parameter[] getParameters() { Parameter[] parameters = this.constructor.getParameters(); - if (parameters.length > 0 && matchingFriendly) { + if (parameters.length > 0 && matchingFriendly && isInnerClassConstructor) { return Arrays.stream(parameters).skip(1).toArray(Parameter[]::new); } return parameters; @@ -154,7 +160,7 @@ public Class getReturnType() { @Override public Object invoke(Object object, Object... args) throws Throwable { Object[] initArgsArray; - if (Modifier.isStatic(this.constructor.getDeclaringClass().getModifiers())) { + if (!isInnerClassConstructor || Modifier.isStatic(this.constructor.getDeclaringClass().getModifiers())) { initArgsArray = new Object[args.length]; System.arraycopy(args, 0, initArgsArray, 0, args.length); } else { @@ -207,4 +213,16 @@ public Object invoke(Object object, Object... args) throws Throwable { public String toGenericString() { return this.constructor.toGenericString(); } + + /** + * Verify whether this leetcode invoke is suitable for the specified class. + * + * @param klass the specified class. + * @return true if suitable. + * @since 1.0.3 + */ + @Override + public boolean isSuitable(Class klass) { + return this.constructor.getDeclaringClass() == klass; + } } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java index eac7bca..2ec5b82 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java @@ -173,4 +173,16 @@ public Object invoke(Object object, Object... args) throws Throwable { public String toGenericString() { return this.method.toGenericString(); } + + /** + * Verify whether this leetcode invoke is suitable for the specified class. + * + * @param klass the specified class. + * @return true if suitable. + * @since 1.0.3 + */ + @Override + public boolean isSuitable(Class klass) { + return this.method.getDeclaringClass() == klass; + } } 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..413fefe 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 @@ -16,14 +16,12 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.pipeline; -import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer; import io.github.jidcoo.opto.lcdb.enhancer.base.LeetcodeInvoker; import io.github.jidcoo.opto.lcdb.enhancer.base.Require; import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeExecutorFactory; 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.utils.AssertUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil; @@ -112,15 +110,4 @@ List processOnDataStructureDesignScene(List operations, List)) { + 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/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..6c1bec7 --- /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 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 ((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..4c23d24 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 @@ -30,12 +30,13 @@ * 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 */ 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,14 +67,7 @@ final class ProxyPointInterceptorManager { Require requireAnnotation = (Require) type.getAnnotation(Require.class); return requireAnnotation.types().length > 0 && ProxyPointInterceptor.class.equals(requireAnnotation.types()[0]); }, - (Class 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(), 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..f5828be 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,7 +20,7 @@ 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.EnhancerLogUtil; @@ -98,7 +98,7 @@ protected IO_SOURCE generateIOSource(String source, Class 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; } From d54666e60a5a3397fcb5aabf07e9bd055bd0264f Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 9 Mar 2025 16:00:52 +0800 Subject: [PATCH 06/32] Add LeetcodeJavaDebugEnhancerQuickStarter support. --- pom.xml | 2 +- .../enhancer/LeetcodeJavaDebugEnhancer.java | 2 +- ...LeetcodeJavaDebugEnhancerQuickStarter.java | 53 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java diff --git a/pom.xml b/pom.xml index 718bd76..8d83aee 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ - io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer + io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancerQuickStarter diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java index afd6681..1938e88 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java @@ -136,7 +136,7 @@ static void run(String __AT__) { // Let's do a great work here now. LeetcodeJavaDebugEnhanceProcessor.process((Class) Class.forName(__AT__)); } 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/LeetcodeJavaDebugEnhancerQuickStarter.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java new file mode 100644 index 0000000..9c98619 --- /dev/null +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.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; + +import io.github.jidcoo.opto.lcdb.enhancer.base.EnhancerException; +import io.github.jidcoo.opto.lcdb.enhancer.utils.StringUtil; + +/** + * LeetcodeJavaDebugEnhancer quick starter. + * + * @author Jidcoo + * @since 1.0.3 + */ +public abstract class LeetcodeJavaDebugEnhancerQuickStarter implements LeetcodeJavaDebugEnhancer { + + public static void main(String[] args) { + String AT = obtainATFromStartupArguments(args); + if (StringUtil.isBlank(AT)) { + // Depend on java runtime feature. + AT = System.getProperty("sun.java.command"); + } + if (LeetcodeJavaDebugEnhancerQuickStarter.class.getName().equals(AT)) { + throw new EnhancerException("Cannot enhance from the abstract LeetcodeJavaDebugEnhancerQuickStarter."); + } + LeetcodeJavaDebugEnhancer.run(AT); + } + + private static String obtainATFromStartupArguments(String[] args) { + if (args.length == 0) { + return null; + } + for (String arg : args) { + if (!StringUtil.isBlank(arg)) { + return arg; + } + } + return null; + } +} From 7fcae4be48b58b1ce67b65526067ff9b688ab62f Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 9 Mar 2025 16:19:38 +0800 Subject: [PATCH 07/32] Fix the bug of method ReflectUtil#isImplementInterface(). --- .../jidcoo/opto/lcdb/enhancer/utils/ReflectUtil.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; } /** From 34c8c976028efea434e04555c1f4af5e22606e5f Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 15 Mar 2025 18:30:58 +0800 Subject: [PATCH 08/32] Fix bug. --- .../core/executor/LeetcodeExecutorFactory.java | 17 +++++++++++++++++ .../LeetcodeJavaDebugEnhancerPipeline.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeExecutorFactory.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeExecutorFactory.java index 67fa06e..7f04b55 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeExecutorFactory.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeExecutorFactory.java @@ -52,4 +52,21 @@ public static LeetcodeExecutor getLeetcodeExecutor(Object instance, LeetcodeInvo } return executor; } + + /** + * Product a LeetcodeExecutor instance by copying the original + * LeetcodeExecutor instance. + * + * @param instance the original LeetcodeExecutor instance. + * @return the LeetcodeExecutor instance. + * @since 1.0.3 + */ + public static LeetcodeExecutor copyByLeetcodeExecutor(Object instance) { + AssertUtil.nonNull(instance, "The instance cannot be null."); + AssertUtil.isTrue(instance instanceof LeetcodeExecutor, "The instance is not a LeetcodeExecutor instance."); + LeetcodeExecutor curInstance = (LeetcodeExecutor) instance; + LeetcodeExecutor newInstance = new LeetcodeExecutor(curInstance.getInstance(), curInstance.getExecutor()); + newInstance.getCandidateInvokers().addAll(curInstance.getCandidateInvokers()); + return newInstance; + } } 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 3ac6da4..1d7656b 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 @@ -158,7 +158,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. From d19dd23b8730925551b0e173f8176fba17d159b0 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 15 Mar 2025 20:25:45 +0800 Subject: [PATCH 09/32] Remove unused import. --- .../jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java | 1 - .../core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java index 1938e88..4c956b4 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java @@ -23,7 +23,6 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider; import io.github.jidcoo.opto.lcdb.enhancer.base.OutputConsumer; -import java.lang.reflect.Method; import java.util.List; import java.util.logging.Level; 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 1d7656b..01df112 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 @@ -28,7 +28,6 @@ import io.github.jidcoo.opto.lcdb.enhancer.utils.BeanUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; From aa996eb58337215b5c827bf7965c926218e16809 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 15 Mar 2025 23:12:14 +0800 Subject: [PATCH 10/32] Add order util. --- .../enhancer/core/parser/InputParser.java | 9 +-- .../core/parser/ParameterAcceptor.java | 13 +--- .../LeetcodeJavaDebugEnhancerPipeline.java | 5 +- .../enhancer/core/printer/OutputPrinter.java | 6 +- .../proxy/ProxyPointInterceptorManager.java | 3 +- .../opto/lcdb/enhancer/utils/OrderUtil.java | 77 +++++++++++++++++++ 6 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/OrderUtil.java diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java index b992cdf..ba428ba 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java @@ -16,15 +16,10 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.parser; -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.AssertUtil; -import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil; -import io.github.jidcoo.opto.lcdb.enhancer.utils.PackageUtil; -import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil; +import io.github.jidcoo.opto.lcdb.enhancer.utils.*; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; /** @@ -77,7 +72,7 @@ final class InputParser { } } // Sort the inputParserNodes by Order. - inputParserNodes.sort(Comparator.comparingInt(Order::getOrder).reversed()); + OrderUtil.descSort(inputParserNodes); // Create an InputParserChain by inputParserNodes. parserChain = new InputParserChain(inputParserNodes); } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java index 2cf5484..9cc6a6e 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java @@ -17,13 +17,9 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.parser; import io.github.jidcoo.opto.lcdb.enhancer.base.BaseParameterAcceptStrategy; -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.base.Strategizable; -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.ReflectUtil; +import io.github.jidcoo.opto.lcdb.enhancer.utils.*; import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; @@ -56,11 +52,6 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy { */ private Map, Set>> builtinAcceptStrategyMap; - /** - * BaseParameterAcceptStrategy comparator. - */ - private final Comparator strategyComparator = Comparator.comparingInt(Order::getOrder).reversed(); - /** * Built-in parameter acceptance strategy set package location. */ @@ -98,7 +89,7 @@ private void addParameterAcceptStrategy(Class type, BaseParameterAcceptStrate 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)); + 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/pipeline/LeetcodeJavaDebugEnhancerPipeline.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java index 01df112..7e4a144 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 @@ -26,6 +26,7 @@ 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; @@ -125,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) { 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/proxy/ProxyPointInterceptorManager.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java index 4c23d24..5eb4ff6 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.*; @@ -72,7 +71,7 @@ final class ProxyPointInterceptorManager { Collectors.groupingBy(ProxyPointInterceptor::interceptPoint, Collectors.collectingAndThen(Collectors.toList(), list -> { - list.sort(Comparator.comparingInt(Order::getOrder).reversed()); + OrderUtil.descSort(list); return 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 ASC_ORDER_CMP = Comparator.comparingInt(Order::getOrder); + + private static final Comparator DESC_ORDER_CMP = ASC_ORDER_CMP.reversed(); + + /** + * ASC sort. + * + * @param list the order-able list. + */ + public static void ascSort(List list) { + orderSort(list, ASC_ORDER_CMP); + } + + /** + * DESC sort. + * + * @param list the order-able list. + */ + public static void descSort(List list) { + orderSort(list, DESC_ORDER_CMP); + } + + /** + * Get asc order comparator. + * + * @return Comparator + */ + public static Comparator ascComparator() { + return ASC_ORDER_CMP; + } + + /** + * Get desc order comparator. + * + * @return Comparator + */ + public static Comparator descComparator() { + return DESC_ORDER_CMP; + } + + private static void orderSort(List list, Comparator cmp) { + AssertUtil.nonNull(list, "The list cannot be null."); + list.sort(cmp); + } +} From 8315554aa52245ef576aa6d40b999bf483878fc8 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 15 Mar 2025 23:46:12 +0800 Subject: [PATCH 11/32] Make LeetcodeInvoker order-able. --- .../lcdb/enhancer/base/LeetcodeInvoker.java | 2 +- .../executor/ConstructorLeetcodeInvoker.java | 40 ++++++++++++++++++- .../core/executor/LeetcodeInvokerFactory.java | 35 +++++++++++++++- .../core/executor/MethodLeetcodeInvoker.java | 37 ++++++++++++++++- 4 files changed, 109 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java index 71b2df6..5afef3c 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/LeetcodeInvoker.java @@ -31,7 +31,7 @@ * @author Jidcoo * @since 1.0.1 */ -public interface LeetcodeInvoker { +public interface LeetcodeInvoker extends Order { /** * Get id of this invoker. diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java index f55a83a..c630c47 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java @@ -45,6 +45,13 @@ final class ConstructorLeetcodeInvoker implements LeetcodeInvoker { */ private final Integer id; + /** + * The invoker order; + * + * @since 1.0.3 + */ + private final int order; + /** * Friendly matching mode flag. */ @@ -62,12 +69,32 @@ final class ConstructorLeetcodeInvoker implements LeetcodeInvoker { * @param id the invoker id. */ ConstructorLeetcodeInvoker(Constructor constructor, Integer id) { - AssertUtil.nonNull(constructor, "The constructor cannot be null."); this.constructor = constructor; this.isInnerClassConstructor = constructor.getDeclaringClass().getEnclosingClass() != null; // Make accessible. this.constructor.setAccessible(true); this.id = id; + this.order = id; + // Friendly-Matching-Mode is closed by default. + this.matchingFriendly = false; + } + + /** + * Create a ConstructorLeetcodeInvoker instance by custom order. + * + * @param constructor the base constructor. + * @param id the invoker id. + * @param order the invoker order. + * @see io.github.jidcoo.opto.lcdb.enhancer.base.Order + * @since 1.0.3 + */ + ConstructorLeetcodeInvoker(Constructor constructor, Integer id, Integer order) { + this.constructor = constructor; + this.isInnerClassConstructor = constructor.getDeclaringClass().getEnclosingClass() != null; + // Make accessible. + this.constructor.setAccessible(true); + this.id = id; + this.order = order; // Friendly-Matching-Mode is closed by default. this.matchingFriendly = false; } @@ -225,4 +252,15 @@ public String toGenericString() { public boolean isSuitable(Class klass) { return this.constructor.getDeclaringClass() == klass; } + + /** + * Get the order of the object. + * + * @return the int order of the object. + * @since 1.0.3 + */ + @Override + public int getOrder() { + return this.order; + } } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeInvokerFactory.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeInvokerFactory.java index 7ca4367..f02844c 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeInvokerFactory.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/LeetcodeInvokerFactory.java @@ -17,6 +17,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.executor; import io.github.jidcoo.opto.lcdb.enhancer.base.LeetcodeInvoker; +import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -45,10 +46,25 @@ public final class LeetcodeInvokerFactory { * @return the LeetcodeInvoker instance. */ public static LeetcodeInvoker getLeetcodeInvoker(Method method) { - // We don't need to perform non-null check here. + AssertUtil.nonNull(method, "The method cannot be null."); return new MethodLeetcodeInvoker(method, INVOKER_ID_GENERATOR.getAndIncrement()); } + /** + * Product a LeetcodeInvoker instance by + * {@link Method} instance and custom invoker order. + * + * @param method the method instance. + * @param order the invoker order. + * @return the LeetcodeInvoker instance. + * @since 1.0.3 + */ + public static LeetcodeInvoker getLeetcodeInvoker(Method method, Integer order) { + AssertUtil.nonNull(method, "The method cannot be null."); + AssertUtil.nonNull(order, "The order cannot be null."); + return new MethodLeetcodeInvoker(method, INVOKER_ID_GENERATOR.getAndIncrement(), order); + } + /** * Product a LeetcodeInvoker instance by * {@link Constructor} instance. @@ -57,7 +73,22 @@ public static LeetcodeInvoker getLeetcodeInvoker(Method method) { * @return the LeetcodeInvoker instance. */ public static LeetcodeInvoker getLeetcodeInvoker(Constructor constructor) { - // We don't need to perform non-null check here. + AssertUtil.nonNull(constructor, "The constructor cannot be null."); return new ConstructorLeetcodeInvoker(constructor, INVOKER_ID_GENERATOR.getAndIncrement()); } + + /** + * Product a LeetcodeInvoker instance by + * {@link Constructor} instance and custom invoker order. + * + * @param constructor the constructor instance. + * @param order the invoker order. + * @return the LeetcodeInvoker instance. + * @since 1.0.3 + */ + public static LeetcodeInvoker getLeetcodeInvoker(Constructor constructor, Integer order) { + AssertUtil.nonNull(constructor, "The constructor cannot be null."); + AssertUtil.nonNull(order, "The order cannot be null."); + return new ConstructorLeetcodeInvoker(constructor, INVOKER_ID_GENERATOR.getAndIncrement(), order); + } } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java index 2ec5b82..2aff0dd 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/MethodLeetcodeInvoker.java @@ -43,6 +43,13 @@ final class MethodLeetcodeInvoker implements LeetcodeInvoker { */ private final Integer id; + /** + * The invoker order; + * + * @since 1.0.3 + */ + private final int order; + /** * Create a MethodLeetcodeInvoker instance. * @@ -50,11 +57,28 @@ final class MethodLeetcodeInvoker implements LeetcodeInvoker { * @param id the invoker id. */ MethodLeetcodeInvoker(Method method, Integer id) { - AssertUtil.nonNull(method, "The method cannot be null."); this.method = method; // Make accessible. this.method.setAccessible(true); this.id = id; + this.order = id; + } + + /** + * Create a MethodLeetcodeInvoker instance by custom order. + * + * @param method the base method. + * @param id the invoker id. + * @param order the invoker order. + * @see io.github.jidcoo.opto.lcdb.enhancer.base.Order + * @since 1.0.3 + */ + MethodLeetcodeInvoker(Method method, Integer id, Integer order) { + this.method = method; + // Make accessible. + this.method.setAccessible(true); + this.id = id; + this.order = order; } /** @@ -185,4 +209,15 @@ public String toGenericString() { public boolean isSuitable(Class klass) { return this.method.getDeclaringClass() == klass; } + + /** + * Get the order of the object. + * + * @return the int order of the object. + * @since 1.0.3 + */ + @Override + public int getOrder() { + return this.order; + } } From c70ff8d4dff8fadfbeebc23d6aef620e5ffe612c Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 16 Mar 2025 00:28:14 +0800 Subject: [PATCH 12/32] Fix bug. --- .../lcdb/enhancer/core/parser/IRMatchInputParserNode.java | 2 ++ .../core/pipeline/DataStructureDesignScenePipelineRunner.java | 4 ++-- .../core/pipeline/LeetcodeJavaDebugEnhancerPipeline.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java index 3b3f408..1091f40 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java @@ -22,6 +22,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.EnhancerLogUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.GsonUtil; +import io.github.jidcoo.opto.lcdb.enhancer.utils.OrderUtil; import java.io.*; import java.lang.reflect.Modifier; @@ -260,6 +261,7 @@ private List fetchLeetcodeInvokers(InputParserContext context, // Add public leetcode invokers list to leetcodeInvokers. leetcodeInvokers.addAll(publicLeetcodeInvokers); } + OrderUtil.descSort(leetcodeInvokers); return leetcodeInvokers; } } 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 413fefe..b73c558 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 @@ -59,12 +59,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(), 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 7e4a144..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 @@ -139,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. From adc8f84dbab7e964bc3ff281754d201075b52bb9 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 16 Mar 2025 15:06:55 +0800 Subject: [PATCH 13/32] Change classtype from Object to Type. --- .../lcdb/enhancer/base/BaseParameterAcceptStrategy.java | 7 ++++--- .../opto/lcdb/enhancer/base/BasePrintingStrategy.java | 3 ++- .../jidcoo/opto/lcdb/enhancer/base/Strategizable.java | 3 ++- .../opto/lcdb/enhancer/core/parser/ParameterAcceptor.java | 7 ++++--- .../parser/builtin/BinaryTreeParameterAcceptStrategy.java | 4 ++-- .../core/parser/builtin/GodParameterAcceptStrategy.java | 6 +++--- .../builtin/SinglyLinkedListParameterAcceptStrategy.java | 4 ++-- 7 files changed, 19 insertions(+), 15 deletions(-) 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..77382c9 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,6 +16,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.base; +import java.lang.reflect.Type; import java.util.Map; import java.util.Set; @@ -52,7 +53,7 @@ public abstract class BaseParameterAcceptStrategy implements Strategi *

* @return the accepted parameter. */ - protected abstract Parameter acceptParameter(Object object, java.lang.reflect.Parameter type, + protected abstract Parameter acceptParameter(Object object, Type type, Map, Set>> strategiesMap) throws Throwable; /** @@ -64,9 +65,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 implements Strategizable, Set>> strategiesMap) throws Throwable { // Do real call the printOutput() method. return printOutput((Output) object, strategiesMap); diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java index b0d0889..db36cce 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java @@ -20,6 +20,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.utils.ContainerCheckUtil; import javax.lang.model.type.NullType; +import java.lang.reflect.Type; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -113,7 +114,7 @@ default Set findStrategySet(Object object, final Map, Set, Set> strategiesMap) throws Throwable { + default Output accept(Type classType, Object object, Map, Set> strategiesMap) throws Throwable { // By default, a runtime exception is thrown here. throw new RuntimeException("Stub!"); } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java index 9cc6a6e..a05c161 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java @@ -23,6 +23,7 @@ import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; +import java.lang.reflect.Type; import java.util.*; import java.util.stream.Collectors; @@ -112,8 +113,8 @@ public ParameterAcceptResult accept(Parameter invokerParameterType, Object objec for (BaseParameterAcceptStrategy acceptStrategy : strategySet) { try { // Try to accept the parameter and return the accepted result. - return ParameterAcceptResult.accept(acceptStrategy.accept(invokerParameterType, object, - builtinAcceptStrategyMap)); + return ParameterAcceptResult.accept(acceptStrategy.accept(invokerParameterType.getParameterizedType(), + object, builtinAcceptStrategyMap)); } catch (Throwable e) { // Push the throwable with the object tracer into stack. tracerStack.push(new ParameterAcceptStrategyTracer(acceptStrategy.getClass().getName(), e)); @@ -142,7 +143,7 @@ public ParameterAcceptResult accept(Parameter invokerParameterType, Object objec * @return the accepted parameter. */ @Override - protected Object acceptParameter(Object object, Parameter type, + protected Object acceptParameter(Object object, Type type, Map, Set>> strategiesMap) throws Throwable { // This method is not supported in ParameterAcceptor. throw new RuntimeException("Unsupported!"); 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..503204a 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 @@ -22,7 +22,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.struct.TreeNode; 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,7 +55,7 @@ public final class BinaryTreeParameterAcceptStrategy extends BaseParameterAccept * @return the accepted parameter. */ @Override - protected TreeNode acceptParameter(Object object, Parameter type, + protected TreeNode acceptParameter(Object object, Type type, Map, Set>> strategiesMap) throws Throwable { AssertUtil.nonNull(object, "The object cannot be null."); AssertUtil.isTrue((object instanceof List), "The object is not a List."); 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..955cd90 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, + protected Object acceptParameter(Object object, Type type, Map, Set>> strategiesMap) throws Throwable { // 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..fe4f742 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 @@ -22,7 +22,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.struct.ListNode; 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,7 +55,7 @@ public final class SinglyLinkedListParameterAcceptStrategy extends BaseParameter * @return the accepted parameter. */ @Override - protected ListNode acceptParameter(Object object, Parameter type, + protected ListNode acceptParameter(Object object, Type type, Map, Set>> strategiesMap) throws Throwable { AssertUtil.nonNull(object, "The object cannot be null."); AssertUtil.isTrue((object instanceof List), "The object is not a List."); From 3a78b9c8e66c166bd64e916f68aa0fd7e8714049 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 22 Mar 2025 16:48:17 +0800 Subject: [PATCH 14/32] fix bug. --- src/LICENSE | 2 +- .../pipeline/DataStructureDesignScenePipelineRunner.java | 8 ++++++++ .../lcdb/enhancer/core/proxy/EnhancerProxyFactory.java | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/LICENSE b/src/LICENSE index 2d1e392..5116f81 100644 --- a/src/LICENSE +++ b/src/LICENSE @@ -1,4 +1,4 @@ -Jidoo LeetcodeJavaDebugEnhancer +Jidcoo LeetcodeJavaDebugEnhancer Apache License Version 2.0, January 2004 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 b73c558..2f3d19f 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 @@ -16,12 +16,14 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.pipeline; +import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer; import io.github.jidcoo.opto.lcdb.enhancer.base.LeetcodeInvoker; import io.github.jidcoo.opto.lcdb.enhancer.base.Require; import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeExecutorFactory; 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.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.ReflectUtil; @@ -110,4 +112,10 @@ List processOnDataStructureDesignScene(List operations, List Date: Sat, 22 Mar 2025 18:15:50 +0800 Subject: [PATCH 15/32] merge test branch. --- .../io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 index 3046033..4d78f3d 100644 --- a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java @@ -47,7 +47,7 @@ * @see UnitTestDriver#ignoreTestResult() */ @RunWith(JUnit4.class) -public abstract class UnitTestDriver extends LeetcodeJavaDebugEnhancer { +public abstract class UnitTestDriver extends LeetcodeJavaDebugEnhancerQuickStarter { private static final UnitTestOutputCollector __GLOBAL__OC__ = new UnitTestOutputCollector(); @@ -87,7 +87,7 @@ public final void __PROCESS_AFTER_ON_DRIVER__() { @Test public final void __PROCESS_TEST_ON_DRIVER__() { Assert.assertTrue(__IS__REGISTERED__); - LeetcodeJavaDebugEnhancer.main(null); + LeetcodeJavaDebugEnhancerQuickStarter.main(new String[]{this.getClass().getName()}); if (__IS__IGNORED__OUTPUT__) { return; } @@ -142,7 +142,6 @@ protected final void expectString(String... expectedResult) { */ protected final void registerDriver() { if (!__IS__REGISTERED__) { - System.setProperty("sun.java.command", this.getClass().getName()); __IS__REGISTERED__ = true; } } From 95c3e49f6b5a472df09270228a8c41208d6842f9 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 22 Mar 2025 19:07:07 +0800 Subject: [PATCH 16/32] fix bug & add test. --- .../executor/ConstructorLeetcodeInvoker.java | 4 +- .../testset6/TestSet6_AddSolution.java | 24 ++++ .../enhancer/testset6/TestSet6_LRUCache.java | 101 ++++++++++++++ .../TestSet6_OuterSolutionWithAlias.java | 32 +++++ .../testset6/TestSet6_TestCase01.java | 54 ++++++++ .../testset6/TestSet6_TestCase02.java | 40 ++++++ .../testset6/TestSet6_TestCase03.java | 47 +++++++ .../testset6/TestSet6_TestCase04.java | 126 ++++++++++++++++++ .../testset6/TestSet6_TestCase05.java | 51 +++++++ 9 files changed, 477 insertions(+), 2 deletions(-) create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_AddSolution.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_LRUCache.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_OuterSolutionWithAlias.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase05.java diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java index c630c47..79b75d4 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/executor/ConstructorLeetcodeInvoker.java @@ -131,8 +131,8 @@ public int getParameterCount() { @Override public String getInvokerName() { String name = this.constructor.getName(); - if (matchingFriendly && isInnerClassConstructor) { - return name.substring(name.lastIndexOf('$') + 1); + if (matchingFriendly) { + return name.substring(name.lastIndexOf(isInnerClassConstructor ? '$' : '.') + 1); } return name; } 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..fbc53b8 --- /dev/null +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/TestSet6_TestCase05.java @@ -0,0 +1,51 @@ +/* + * 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; +import java.util.logging.Level; + +/** + * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()} + * + * @author Jidcoo + */ +public class TestSet6_TestCase05 extends UnitTestDriver { + + @Override + public Level getEnhancerLogLevel() { + return Level.INFO; + } + + @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; + } +} From b1ab9825e7e331c0ebd365eb7c7b8720dde42f34 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 22 Mar 2025 19:08:25 +0800 Subject: [PATCH 17/32] fix bug & add test. --- .../jidcoo/opto/lcdb/enhancer/testset6/package-info.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset6/package-info.java 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 From 6add2c4b3570b1c577dafedbdad71f58d7293168 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 22 Mar 2025 23:23:31 +0800 Subject: [PATCH 18/32] fix bug. --- .../opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java | 10 +++++++++- .../LeetcodeJavaDebugEnhancerQuickStarter.java | 3 --- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java index 4c956b4..6881195 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java @@ -19,9 +19,11 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.BasePrintingStrategy; import io.github.jidcoo.opto.lcdb.enhancer.base.EnhancerException; import io.github.jidcoo.opto.lcdb.enhancer.core.LeetcodeJavaDebugEnhanceProcessor; +import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.EnhancerLogUtil; 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.utils.ReflectUtil; import java.util.List; import java.util.logging.Level; @@ -128,12 +130,18 @@ static String getEnhancerVersion() { * * @param __AT__ the AT name. */ + @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) Class.forName(__AT__)); + LeetcodeJavaDebugEnhanceProcessor.process((Class) atClass); } catch (Exception | Error err) { EnhancerLogUtil.logE("LeetcodeJavaDebugEnhancer[%s] runtime error: %s: %s", VERSION, err.getClass().getName(), err.getMessage()); throw new EnhancerException("LeetcodeJavaDebugEnhancer runtime error: " + err.getMessage(), err); diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java index 9c98619..75658fc 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java @@ -40,9 +40,6 @@ public static void main(String[] args) { } private static String obtainATFromStartupArguments(String[] args) { - if (args.length == 0) { - return null; - } for (String arg : args) { if (!StringUtil.isBlank(arg)) { return arg; From 1f97581cd0ee5302abb12919c58352a9ed1d27b7 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 23 Mar 2025 21:11:38 +0800 Subject: [PATCH 19/32] Add Enhancer api: getParameterAcceptStrategies() --- .../enhancer/LeetcodeJavaDebugEnhancer.java | 17 +++++++--- .../enhancer/core/parser/InputParser.java | 29 ++++++++++++++-- .../core/parser/InputParserContext.java | 34 +++++++++++++++---- .../core/parser/InputParserFactory.java | 2 +- 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java index 6881195..6602d46 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancer.java @@ -16,13 +16,10 @@ package io.github.jidcoo.opto.lcdb.enhancer; -import io.github.jidcoo.opto.lcdb.enhancer.base.BasePrintingStrategy; -import io.github.jidcoo.opto.lcdb.enhancer.base.EnhancerException; +import io.github.jidcoo.opto.lcdb.enhancer.base.*; import io.github.jidcoo.opto.lcdb.enhancer.core.LeetcodeJavaDebugEnhanceProcessor; import io.github.jidcoo.opto.lcdb.enhancer.utils.AssertUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.EnhancerLogUtil; -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.utils.ReflectUtil; import java.util.List; @@ -116,6 +113,18 @@ 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. * diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java index ba428ba..c98e811 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java @@ -16,6 +16,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.parser; +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.utils.*; @@ -47,7 +48,14 @@ final class InputParser { /** * The InputParserChain in this parser. */ - private InputParserChain parserChain; + private final InputParserChain parserChain; + + /** + * The available custom parameter accepting strategies. + * + * @since 1.0.3 + */ + private List> availableParameterAcceptStrategies; /** * Create an InputParser instance. @@ -77,6 +85,17 @@ final class InputParser { parserChain = new InputParserChain(inputParserNodes); } + /** + * Create an InputParser instance with custom parameter accepting strategies. + * + * @param availableParameterAcceptStrategies the custom parameter accepting strategies. + * @since 1.0.3 + */ + InputParser(List> availableParameterAcceptStrategies) { + this(); + this.availableParameterAcceptStrategies = availableParameterAcceptStrategies; + } + /** * Parse an input from an InputParseTask instance. * @@ -103,7 +122,11 @@ private InputParserContext createParserContext(InputParseTask inputParseTask) { AssertUtil.nonNull(inputParseTask, "The inputParseTask cannot be null"); AssertUtil.nonNull(inputParseTask.getTargetInstance(), "The target cannot be null"); AssertUtil.nonNull(inputParseTask.getInput(), "The input cannot be null"); - return new InputParserContext(inputParseTask.getTargetInstance(), inputParseTask.getInput(), - inputParseTask.getCandidateInvokers()); + return new InputParserContext( + inputParseTask.getTargetInstance(), + inputParseTask.getInput(), + inputParseTask.getCandidateInvokers(), + availableParameterAcceptStrategies + ); } } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java index c438d6a..0ad17fc 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java @@ -16,6 +16,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.parser; +import io.github.jidcoo.opto.lcdb.enhancer.base.BaseParameterAcceptStrategy; import io.github.jidcoo.opto.lcdb.enhancer.base.LeetcodeInvoker; import java.util.EmptyStackException; @@ -50,7 +51,14 @@ final class InputParserContext { * * @since 1.0.1 */ - private List candidateInvokers; + private final List candidateInvokers; + + /** + * The available custom parameter accepting strategies. + * + * @since 1.0.3 + */ + private final List> availableParameterAcceptStrategies; /** * The input stack used for debug. @@ -60,18 +68,20 @@ final class InputParserContext { /** * Create a InputParserContext instance. * - * @param targetInstance the target instance used for debug. - * @param input the input used for debug. - * @param candidateInvokers the candidate leetcode invokers list for input - * parsing. - * @since 1.0.1 + * @param targetInstance the target instance used for debug. + * @param input the input used for debug. + * @param candidateInvokers the candidate leetcode invokers list for input parsing. + * @param parameterAcceptStrategies the available custom parameter accepting strategies. + * @since 1.0.3 */ - InputParserContext(Object targetInstance, Object input, List candidateInvokers) { + InputParserContext(Object targetInstance, Object input, List candidateInvokers, + List> parameterAcceptStrategies) { this.targetInstance = targetInstance; this.inputStack = new Stack<>(); // Add the first input to the inputStack this.inputStack.push(input); this.candidateInvokers = candidateInvokers; + this.availableParameterAcceptStrategies = parameterAcceptStrategies; } /** @@ -155,4 +165,14 @@ void setTargetInvoker(LeetcodeInvoker targetInvoker) { List getCandidateInvokers() { return candidateInvokers; } + + /** + * Get the available parameter accept strategies for input parsing. + * + * @return the available parameter accept strategies. + * @since 1.0.3 + */ + List> getAvailableParameterAcceptStrategies() { + return availableParameterAcceptStrategies; + } } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserFactory.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserFactory.java index 56c6ddb..3e17715 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserFactory.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserFactory.java @@ -38,6 +38,6 @@ public final class InputParserFactory { */ public static InputParser getInputParser(LeetcodeJavaDebugEnhancer enhancer) { AssertUtil.nonNull(enhancer, "The enhancer cannot be null."); - return new InputParser(); + return new InputParser(enhancer.getParameterAcceptStrategies()); } } From d7843ca28709f822816d1914c6a532d67390ea96 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 23 Mar 2025 21:18:47 +0800 Subject: [PATCH 20/32] fix bug. --- .../jidcoo/opto/lcdb/enhancer/core/parser/InputParseTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParseTask.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParseTask.java index a701b81..0c23dba 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParseTask.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParseTask.java @@ -49,7 +49,7 @@ final class InputParseTask { * * @since 1.0.1 */ - private List candidateInvokers; + private final List candidateInvokers; /** * The input used for debug. From cfbf8aeaac82b3ea8a0455f7cb99bda8635dddf3 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 23 Mar 2025 22:47:45 +0800 Subject: [PATCH 21/32] Support custom param accepting strategy. --- .../core/parser/IRMatchInputParserNode.java | 12 +- .../core/parser/InputParserContext.java | 12 +- .../core/parser/ParameterAcceptor.java | 127 ++++++++++++------ .../testset6/TestSet6_TestCase05.java | 9 -- 4 files changed, 103 insertions(+), 57 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java index 1091f40..5d9b054 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java @@ -16,6 +16,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.parser; +import io.github.jidcoo.opto.lcdb.enhancer.base.BaseParameterAcceptStrategy; import io.github.jidcoo.opto.lcdb.enhancer.base.LeetcodeInvoker; import io.github.jidcoo.opto.lcdb.enhancer.base.Require; import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeInvokerFactory; @@ -86,11 +87,16 @@ Object parse(InputParserContext context) { // Define the boss input. List bossInput = new ArrayList<>(); // Peek last input. - List input = (List) context.peekInput(); + List input = context.peekInput(); // Fetch all possible leetcode invokers. List leetcodeInvokers = fetchLeetcodeInvokers(context, input.size()); // Create an invoker-matching tracer map to record the invoker matching detail. Map>> matchTracer = new HashMap<>(); + + // Try to combine custom strategies if the availableParameterAcceptStrategies are not empty(sine 1.0.3). + Map, Set>> curParameterAcceptingStrategies = + parameterAcceptor.combineCustomStrategies(context.getAvailableParameterAcceptStrategies()); + if (!ContainerCheckUtil.isListEmpty(leetcodeInvokers)) { // Try to match all possible leetcode invokers. for (LeetcodeInvoker leetcodeInvoker : leetcodeInvokers) { @@ -108,7 +114,7 @@ Object parse(InputParserContext context) { // Copy the input parameter deeply. Object copiedObject = deepCopy(input.get(i)); // Try to accept the input parameter. - ParameterAcceptResult result = parameterAcceptor.accept(parameterType, copiedObject); + ParameterAcceptResult result = parameterAcceptor.accept(curParameterAcceptingStrategies, parameterType, copiedObject); // Add cur rejected result tracer to enable cur matching tracer if result is not accepted. if (!result.isAccepted()) { invokerMatchTracerMap.put(i, result.getTracer()); @@ -137,7 +143,7 @@ Object parse(InputParserContext context) { // Log parameter accepting tracer detail after IR-Matching if the bossInvoker is null. logDetailAfterIRMatching(bossInvoker, leetcodeInvokers, input, matchTracer); context.setTargetInvoker(bossInvoker); - return (bossInput.stream().toArray(Object[]::new)); + return bossInput.toArray(); } /** diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java index 0ad17fc..7a70236 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserContext.java @@ -99,6 +99,7 @@ Object getTargetInstance() { * @param input the input. * @return the input. */ + @SuppressWarnings("unchecked") T pushInput(T input) { return (T) this.inputStack.push(input); } @@ -111,9 +112,9 @@ T pushInput(T input) { * @return the input at the top of the input stack from this context. * @throws EmptyStackException if the input stack from this context is empty. */ - - Object peekInput() { - return this.inputStack.peek(); + @SuppressWarnings("unchecked") + T peekInput() { + return (T) this.inputStack.peek(); } /** @@ -123,8 +124,9 @@ Object peekInput() { * @return the input at the top of the input stack from this context. * @throws EmptyStackException if the input stack from this context is empty. */ - Object popInput() { - return this.inputStack.pop(); + @SuppressWarnings("unchecked") + T popInput() { + return (T) this.inputStack.pop(); } /** diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java index a05c161..c81d56a 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java @@ -37,7 +37,8 @@ *

ParameterAcceptor performs appropriate acceptance * of input objects based on built-in parameter * acceptance strategies and external acceptance - * strategies by {@link #accept(Parameter, Object)}. + * strategies by {@link #accept(Parameter, Object)} + * or {@link #accept(Map, Parameter, Object)}. *

* * @author Jidcoo @@ -51,7 +52,7 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy { /** * Builtin parameter acceptance strategy map. */ - private Map, Set>> builtinAcceptStrategyMap; + private final Map, Set>> builtinAcceptStrategyMap; /** * Built-in parameter acceptance strategy set package location. @@ -78,55 +79,32 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy { } /** - * Wrap the strategy add function. + * Accept an object with the parameter type. * - * @param type the accepted class type. - * @param strategy the acceptance strategy. - * @param strategyMap the acceptance strategy map. + * @param invokerParameterType the leetcode invoker parameter type. + * @param object the input object for accepting. + * @return the parameter acceptance result. */ - 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); + public ParameterAcceptResult accept(Parameter invokerParameterType, Object object) { + return parameterAccepting(this.builtinAcceptStrategyMap, invokerParameterType, object); } /** - * Accept an object with the parameter type. + * Accept an object with custom parameter accepting strategies + * and parameter type. * + * @param strategies the custom parameter accepting strategies. * @param invokerParameterType the leetcode invoker parameter type. * @param object the input object for accepting. * @return the parameter acceptance result. + * @since 1.0.3 */ - 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.getParameterizedType(), - 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)); + public ParameterAcceptResult accept(Map, Set>> strategies, + Parameter invokerParameterType, Object object) { + if (Objects.isNull(strategies)) { + return accept(invokerParameterType, object); } - - // Return the rejected result. - return ParameterAcceptResult.reject(object, tracerStack); + return parameterAccepting(strategies, invokerParameterType, object); } /** @@ -170,4 +148,73 @@ public Class getAcceptableType() { // This method is not supported in ParameterAcceptor. throw new RuntimeException("Unsupported!"); } + + /** + * 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 (ContainerCheckUtil.isListEmpty(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); + } + + private ParameterAcceptResult parameterAccepting(Map, Set>> strategies, + 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(), + strategies); + for (BaseParameterAcceptStrategy acceptStrategy : strategySet) { + try { + // Try to accept the parameter and return the accepted result. + return ParameterAcceptResult.accept(acceptStrategy.accept(invokerParameterType.getParameterizedType(), + 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); + } } 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 index fbc53b8..5a2729d 100644 --- 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 @@ -20,10 +20,6 @@ import io.github.jidcoo.opto.lcdb.enhancer.UnitTestDriver; import org.junit.Before; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - /** * Tests for {@link LeetcodeJavaDebugEnhancer#getEnhancerPayload()} * @@ -31,11 +27,6 @@ */ public class TestSet6_TestCase05 extends UnitTestDriver { - @Override - public Level getEnhancerLogLevel() { - return Level.INFO; - } - @Before public void onBefore() { registerDriverWithAutoCustomStdIn("[\"TestSet6_LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", " + From fa882b6ada4f03c5f90f4e7271bc34433a72770c Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 23 Mar 2025 23:04:00 +0800 Subject: [PATCH 22/32] Rename LeetcodeJavaDebugEnhancerQuickStarter to LJDEStarter. --- pom.xml | 2 +- ...avaDebugEnhancerQuickStarter.java => LJDEStarter.java} | 8 ++++---- .../github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/io/github/jidcoo/opto/lcdb/enhancer/{LeetcodeJavaDebugEnhancerQuickStarter.java => LJDEStarter.java} (84%) diff --git a/pom.xml b/pom.xml index a99a1dc..9b0c556 100644 --- a/pom.xml +++ b/pom.xml @@ -136,7 +136,7 @@ - io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancerQuickStarter + io.github.jidcoo.opto.lcdb.enhancer.LJDEStarter diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LJDEStarter.java similarity index 84% rename from src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java rename to src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LJDEStarter.java index 75658fc..78c6e2d 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LeetcodeJavaDebugEnhancerQuickStarter.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/LJDEStarter.java @@ -20,12 +20,12 @@ import io.github.jidcoo.opto.lcdb.enhancer.utils.StringUtil; /** - * LeetcodeJavaDebugEnhancer quick starter. + * LeetcodeJavaDebugEnhancer starter. * * @author Jidcoo * @since 1.0.3 */ -public abstract class LeetcodeJavaDebugEnhancerQuickStarter implements LeetcodeJavaDebugEnhancer { +public abstract class LJDEStarter implements LeetcodeJavaDebugEnhancer { public static void main(String[] args) { String AT = obtainATFromStartupArguments(args); @@ -33,8 +33,8 @@ public static void main(String[] args) { // Depend on java runtime feature. AT = System.getProperty("sun.java.command"); } - if (LeetcodeJavaDebugEnhancerQuickStarter.class.getName().equals(AT)) { - throw new EnhancerException("Cannot enhance from the abstract LeetcodeJavaDebugEnhancerQuickStarter."); + if (LJDEStarter.class.getName().equals(AT)) { + throw new EnhancerException("Cannot enhance from the abstract LJDEStarter."); } LeetcodeJavaDebugEnhancer.run(AT); } 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 index 4d78f3d..6e8f370 100644 --- a/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java +++ b/src/test/java/io/github/jidcoo/opto/lcdb/enhancer/UnitTestDriver.java @@ -47,7 +47,7 @@ * @see UnitTestDriver#ignoreTestResult() */ @RunWith(JUnit4.class) -public abstract class UnitTestDriver extends LeetcodeJavaDebugEnhancerQuickStarter { +public abstract class UnitTestDriver extends LJDEStarter { private static final UnitTestOutputCollector __GLOBAL__OC__ = new UnitTestOutputCollector(); @@ -87,7 +87,7 @@ public final void __PROCESS_AFTER_ON_DRIVER__() { @Test public final void __PROCESS_TEST_ON_DRIVER__() { Assert.assertTrue(__IS__REGISTERED__); - LeetcodeJavaDebugEnhancerQuickStarter.main(new String[]{this.getClass().getName()}); + LJDEStarter.main(new String[]{this.getClass().getName()}); if (__IS__IGNORED__OUTPUT__) { return; } From 8c763ef8f3a9b0e7432eaea2568a2f0b40e92bd1 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 23 Mar 2025 23:24:17 +0800 Subject: [PATCH 23/32] add .github/workflows/maven-ci.yml --- .github/workflows/maven-ci.yml | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/maven-ci.yml diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml new file mode 100644 index 0000000..7c7822a --- /dev/null +++ b/.github/workflows/maven-ci.yml @@ -0,0 +1,37 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Maven CI + +on: + push: + branches-ignore: + - 'history-feature_*' + paths-ignore: + - '**.md' + - 'LICENSE' + - '.gitignore' + - '.github/workflows/**.yml' + pull_request: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + + - name: Run CI with Maven + run: mvn -B test --file pom.xml From 82e36893e30de8a7a70ffa2e813defe6dfce6743 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sun, 23 Mar 2025 23:28:09 +0800 Subject: [PATCH 24/32] fix bug. --- .github/workflows/maven-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 7c7822a..7c388a7 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -20,7 +20,7 @@ on: pull_request: jobs: - build: + ci: runs-on: ubuntu-latest From 09a68cb12ec8f690cd7e3855a21a5591b72b934e Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Mon, 24 Mar 2025 22:48:28 +0800 Subject: [PATCH 25/32] reformat src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java --- .../lcdb/enhancer/core/parser/IRMatchInputParserNode.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java index 5d9b054..ef3ffa9 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java @@ -114,7 +114,11 @@ Object parse(InputParserContext context) { // Copy the input parameter deeply. Object copiedObject = deepCopy(input.get(i)); // Try to accept the input parameter. - ParameterAcceptResult result = parameterAcceptor.accept(curParameterAcceptingStrategies, parameterType, copiedObject); + ParameterAcceptResult result = parameterAcceptor.accept( + curParameterAcceptingStrategies, + parameterType, + copiedObject + ); // Add cur rejected result tracer to enable cur matching tracer if result is not accepted. if (!result.isAccepted()) { invokerMatchTracerMap.put(i, result.getTracer()); From ffca2c64107370bf4c6b665fe9701671eb5ac2be Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Wed, 26 Mar 2025 21:37:34 +0800 Subject: [PATCH 26/32] parser module optimization. --- .../base/BaseParameterAcceptStrategy.java | 46 +++++++++- .../core/parser/IRMatchInputParserNode.java | 8 +- .../core/parser/ParameterAcceptResult.java | 6 +- .../parser/ParameterAcceptStrategyTracer.java | 4 +- .../core/parser/ParameterAcceptor.java | 86 +++--------------- .../BinaryTreeParameterAcceptStrategy.java | 2 +- .../builtin/GodParameterAcceptStrategy.java | 2 +- ...nglyLinkedListParameterAcceptStrategy.java | 2 +- .../opto/lcdb/enhancer/utils/TypeUtil.java | 89 +++++++++++++++++++ 9 files changed, 160 insertions(+), 85 deletions(-) create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/TypeUtil.java 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 77382c9..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,9 +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 @@ -54,7 +59,46 @@ public abstract class BaseParameterAcceptStrategy implements Strategi * @return the accepted parameter. */ protected abstract Parameter acceptParameter(Object object, Type type, - Map, Set>> strategiesMap) throws Throwable; + 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. diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java index ef3ffa9..06f554a 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java @@ -114,10 +114,10 @@ Object parse(InputParserContext context) { // Copy the input parameter deeply. Object copiedObject = deepCopy(input.get(i)); // Try to accept the input parameter. - ParameterAcceptResult result = parameterAcceptor.accept( - curParameterAcceptingStrategies, - parameterType, - copiedObject + ParameterAcceptResult result = parameterAcceptor.acceptParameter( + copiedObject, + parameterType.getParameterizedType(), + curParameterAcceptingStrategies ); // Add cur rejected result tracer to enable cur matching tracer if result is not accepted. if (!result.isAccepted()) { diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java index 2d86bc0..e386508 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java @@ -41,7 +41,7 @@ * @see ParameterAcceptor * @since 1.0 */ -final class ParameterAcceptResult { +public final class ParameterAcceptResult { /** * Parameter accept result code. @@ -121,7 +121,7 @@ public Stack getTracer() { * @param object the accepted object. * @return the accepted result. */ - static ParameterAcceptResult accept(Object object) { + public static ParameterAcceptResult accept(Object object) { return new ParameterAcceptResult(object, Code.PASS, null); } @@ -132,7 +132,7 @@ static ParameterAcceptResult accept(Object object) { * @param tracerStack the parameter object acceptance exception tracker stack. * @return the rejected result. */ - static ParameterAcceptResult reject(Object object, Stack tracerStack) { + public static ParameterAcceptResult reject(Object object, Stack tracerStack) { return new ParameterAcceptResult(object, Code.REJECT, tracerStack); } } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptStrategyTracer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptStrategyTracer.java index 3c18e6f..2fb6f9b 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptStrategyTracer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptStrategyTracer.java @@ -36,7 +36,7 @@ * @author Jidcoo * @since 1.0 */ -final class ParameterAcceptStrategyTracer extends EnhancerException { +public final class ParameterAcceptStrategyTracer extends EnhancerException { /** * The ParameterAcceptStrategy name for throws. @@ -56,7 +56,7 @@ final class ParameterAcceptStrategyTracer extends EnhancerException { * permitted, and indicates that the cause is nonexistent or * unknown.) */ - ParameterAcceptStrategyTracer(String parameterAcceptStrategy, Throwable cause) { + public ParameterAcceptStrategyTracer(String parameterAcceptStrategy, Throwable cause) { super(cause); this.parameterAcceptStrategy = parameterAcceptStrategy; } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java index c81d56a..8292a50 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java @@ -22,7 +22,6 @@ import io.github.jidcoo.opto.lcdb.enhancer.utils.*; import java.lang.reflect.Modifier; -import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.util.*; import java.util.stream.Collectors; @@ -35,10 +34,8 @@ *

* *

ParameterAcceptor performs appropriate acceptance - * of input objects based on built-in parameter - * acceptance strategies and external acceptance - * strategies by {@link #accept(Parameter, Object)} - * or {@link #accept(Map, Parameter, Object)}. + * of input objects based on built-in or external parameter + * acceptance strategies by {@link #acceptParameter(Object, Type, Map)} *

* * @author Jidcoo @@ -47,7 +44,7 @@ * @see IRMatchInputParserNode * @since 1.0 */ -final class ParameterAcceptor extends BaseParameterAcceptStrategy { +final class ParameterAcceptor extends BaseParameterAcceptStrategy { /** * Builtin parameter acceptance strategy map. @@ -62,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. @@ -78,35 +76,6 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy { } } - /** - * 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) { - return parameterAccepting(this.builtinAcceptStrategyMap, invokerParameterType, object); - } - - /** - * Accept an object with custom parameter accepting strategies - * and parameter type. - * - * @param strategies the custom parameter accepting strategies. - * @param invokerParameterType the leetcode invoker parameter type. - * @param object the input object for accepting. - * @return the parameter acceptance result. - * @since 1.0.3 - */ - public ParameterAcceptResult accept(Map, Set>> strategies, - Parameter invokerParameterType, Object object) { - if (Objects.isNull(strategies)) { - return accept(invokerParameterType, object); - } - return parameterAccepting(strategies, invokerParameterType, object); - } - /** * Accept the object. * @@ -121,10 +90,13 @@ public ParameterAcceptResult accept(Map, Set, 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); } /** @@ -134,8 +106,7 @@ protected Object acceptParameter(Object object, Type type, */ @Override public int getOrder() { - // This method is not supported in ParameterAcceptor. - throw new RuntimeException("Unsupported!"); + return Integer.MAX_VALUE; } /** @@ -144,9 +115,8 @@ 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; } /** @@ -189,32 +159,4 @@ private void addParameterAcceptStrategy(Class type, BaseParameterAcceptStrate // Add the strategy to the set. strategySet.add(strategy); } - - private ParameterAcceptResult parameterAccepting(Map, Set>> strategies, - 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(), - strategies); - for (BaseParameterAcceptStrategy acceptStrategy : strategySet) { - try { - // Try to accept the parameter and return the accepted result. - return ParameterAcceptResult.accept(acceptStrategy.accept(invokerParameterType.getParameterizedType(), - 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); - } } 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 503204a..2f0a37f 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 @@ -56,7 +56,7 @@ public final class BinaryTreeParameterAcceptStrategy extends BaseParameterAccept */ @Override protected TreeNode acceptParameter(Object object, Type type, - Map, Set>> strategiesMap) throws Throwable { + 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); 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 955cd90..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 @@ -63,7 +63,7 @@ public final class GodParameterAcceptStrategy extends BaseParameterAcceptStrateg */ @Override protected Object acceptParameter(Object object, Type type, - Map, Set>> strategiesMap) throws Throwable { + Map, Set>> strategiesMap) { // This can handle most situations!!! // How magical!!! // How beautiful the world is!!! 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 fe4f742..55f754a 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 @@ -56,7 +56,7 @@ public final class SinglyLinkedListParameterAcceptStrategy extends BaseParameter */ @Override protected ListNode acceptParameter(Object object, Type type, - Map, Set>> strategiesMap) throws Throwable { + 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); 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); + } +} From 4690bac850f2565daa502993fe28b3a6e3a9c8e0 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Thu, 27 Mar 2025 22:35:41 +0800 Subject: [PATCH 27/32] Overwrite ParameterAcceptResult.toString(). --- .../core/parser/ParameterAcceptResult.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java index e386508..adcb3ff 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptResult.java @@ -93,8 +93,9 @@ private ParameterAcceptResult(Object object, Code code, Stack T getObject() { + return (T) object; } /** @@ -115,6 +116,29 @@ public Stack getTracer() { return tracer; } + /** + * Result to string. + * + * @return result string. + */ + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder("ParameterAcceptResult: "); + if (isAccepted()) { + stringBuilder.append("parameter has been accepted, accepted object: "); + stringBuilder.append(object); + } else { + stringBuilder.append("parameter cannot be accepted, parameter: "); + stringBuilder.append(object); + stringBuilder.append(", accepting tracer stack: "); + for (int i = tracer.size() - 1; i >= 0; i--) { + stringBuilder.append("\n"); + stringBuilder.append(tracer.elementAt(i).toString()); + } + } + return stringBuilder.toString(); + } + /** * Create a accepted result. * From 6b55f7a6da2863018efbd21e4ca5b15d290eb024 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Thu, 27 Mar 2025 22:50:23 +0800 Subject: [PATCH 28/32] fix bug on BinaryTreeParameterAcceptStrategy: cannot accept example case: [3.0,1,2]. --- .../BinaryTreeParameterAcceptStrategy.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 2f0a37f..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,10 +16,12 @@ 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.Type; @@ -58,8 +60,15 @@ public final class BinaryTreeParameterAcceptStrategy extends BaseParameterAccept 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, Type 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; From 48ba3a0551ac614af552050af4154beeefdd3289 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Thu, 27 Mar 2025 22:53:25 +0800 Subject: [PATCH 29/32] fix bug on SinglyLinkedListParameterAcceptStrategy: cannot accept example case: [3.0,1,2]. --- ...nglyLinkedListParameterAcceptStrategy.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 55f754a..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,10 +16,12 @@ 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.Type; @@ -58,12 +60,21 @@ public final class SinglyLinkedListParameterAcceptStrategy extends BaseParameter 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; From 4ac4b52350ea93d82b3f370a6895c5e1ae1af13f Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Fri, 28 Mar 2025 23:07:41 +0800 Subject: [PATCH 30/32] Add BasicListParameterAcceptStrategy to accept List param. --- .../BasicListParameterAcceptStrategy.java | 115 ++++++++++++++++++ .../testset7/TestSet7_TestCase01.java | 41 +++++++ .../testset7/TestSet7_TestCase02.java | 43 +++++++ .../testset7/TestSet7_TestCase03.java | 43 +++++++ .../testset7/TestSet7_TestCase04.java | 43 +++++++ .../lcdb/enhancer/testset7/package-info.java | 6 + 6 files changed, 291 insertions(+) create mode 100644 src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/builtin/BasicListParameterAcceptStrategy.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase01.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase02.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase03.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/TestSet7_TestCase04.java create mode 100644 src/test/java/io/github/jidcoo/opto/lcdb/enhancer/testset7/package-info.java 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 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/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 From 7b801bb2d6e71ac3b4d831a8526dd7318937a260 Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Fri, 28 Mar 2025 23:13:14 +0800 Subject: [PATCH 31/32] Add SuppressWarnings to ProxyPointInterceptorManager. --- .../lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5eb4ff6..738f9db 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 @@ -38,6 +38,7 @@ * @see EnhancerProxyHandler * @since 1.0.2 */ +@SuppressWarnings(value = {"rawtypes", "unchecked"}) final class ProxyPointInterceptorManager { /** @@ -85,7 +86,6 @@ 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."); From 05a2b0d6432a968ce731811527cdd9776d7fe63a Mon Sep 17 00:00:00 2001 From: Jidcoo <1337753396@qq.com> Date: Sat, 29 Mar 2025 18:39:35 +0800 Subject: [PATCH 32/32] Rename ContainerCheckUtil to ContainerUtil. --- .../lcdb/enhancer/base/Strategizable.java | 4 +- .../io/builtin/MultipleInputProvider.java | 4 +- .../io/builtin/MultipleOutputConsumer.java | 4 +- .../core/parser/IRMatchInputParserNode.java | 8 ++-- .../enhancer/core/parser/InputParser.java | 2 +- .../core/parser/InputParserChain.java | 4 +- .../core/parser/ParameterAcceptor.java | 4 +- ...ataStructureDesignScenePipelineRunner.java | 8 ++-- .../core/printer/OutputPrinterFactory.java | 4 +- .../proxy/ProxyPointInterceptorManager.java | 4 +- .../require/io/AbsIORequireSupporter.java | 6 +-- .../io/InputProviderRequireInterceptor.java | 4 +- .../io/OutputConsumerRequireInterceptor.java | 4 +- .../opto/lcdb/enhancer/utils/BeanUtil.java | 2 +- ...ainerCheckUtil.java => ContainerUtil.java} | 43 ++++++++++++++++--- 15 files changed, 69 insertions(+), 36 deletions(-) rename src/main/java/io/github/jidcoo/opto/lcdb/enhancer/utils/{ContainerCheckUtil.java => ContainerUtil.java} (58%) diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java index db36cce..1b80786 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/base/Strategizable.java @@ -17,7 +17,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.base; 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 javax.lang.model.type.NullType; import java.lang.reflect.Type; @@ -101,7 +101,7 @@ default void checkObjectAcceptable(Object object) { default Set findStrategySet(Object object, final Map, Set> strategiesMap) { Set strategySet = strategiesMap.getOrDefault(getObjectType(object), strategiesMap.getOrDefault(Void.class, null)); - AssertUtil.isTrue(!ContainerCheckUtil.isSetEmpty(strategySet), "Cannot find any appropriate accepted " + + AssertUtil.isTrue(ContainerUtil.isNotEmpty(strategySet), "Cannot find any appropriate accepted " + "strategy" + " set for the object: " + object); return strategySet; } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleInputProvider.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleInputProvider.java index 748f293..969c684 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleInputProvider.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleInputProvider.java @@ -18,7 +18,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider; 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 java.io.Closeable; import java.util.Collections; @@ -59,7 +59,7 @@ public final class MultipleInputProvider implements InputProvider { public MultipleInputProvider(List inputProviderList) { AssertUtil.nonNull(inputProviderList, "The inputProviderList cannot be null."); inputProviderList = inputProviderList.stream().filter(Objects::nonNull).collect(Collectors.toList()); - AssertUtil.isTrue(!ContainerCheckUtil.isListEmpty(inputProviderList), "The inputProviderList cannot be empty."); + AssertUtil.isTrue(ContainerUtil.isNotEmpty(inputProviderList), "The inputProviderList cannot be empty."); this.providers = Collections.unmodifiableList(inputProviderList); } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleOutputConsumer.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleOutputConsumer.java index 3f31d87..4ada607 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleOutputConsumer.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/io/builtin/MultipleOutputConsumer.java @@ -18,7 +18,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.OutputConsumer; 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 java.io.Closeable; import java.util.Collections; @@ -54,7 +54,7 @@ public final class MultipleOutputConsumer implements OutputConsumer { public MultipleOutputConsumer(List outputConsumerList) { AssertUtil.nonNull(outputConsumerList, "The outputConsumerList cannot be null."); outputConsumerList = outputConsumerList.stream().filter(Objects::nonNull).collect(Collectors.toList()); - AssertUtil.isTrue(!ContainerCheckUtil.isListEmpty(outputConsumerList), "The outputConsumerList cannot be empty."); + AssertUtil.isTrue(ContainerUtil.isNotEmpty(outputConsumerList), "The outputConsumerList cannot be empty."); this.consumers = Collections.unmodifiableList(outputConsumerList); } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java index 06f554a..9a38255 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/IRMatchInputParserNode.java @@ -20,7 +20,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.LeetcodeInvoker; import io.github.jidcoo.opto.lcdb.enhancer.base.Require; import io.github.jidcoo.opto.lcdb.enhancer.core.executor.LeetcodeInvokerFactory; -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 io.github.jidcoo.opto.lcdb.enhancer.utils.GsonUtil; import io.github.jidcoo.opto.lcdb.enhancer.utils.OrderUtil; @@ -97,7 +97,7 @@ Object parse(InputParserContext context) { Map, Set>> curParameterAcceptingStrategies = parameterAcceptor.combineCustomStrategies(context.getAvailableParameterAcceptStrategies()); - if (!ContainerCheckUtil.isListEmpty(leetcodeInvokers)) { + if (ContainerUtil.isNotEmpty(leetcodeInvokers)) { // Try to match all possible leetcode invokers. for (LeetcodeInvoker leetcodeInvoker : leetcodeInvokers) { // Filter out leetcodeInvoker with different numbers of parameters than the input parameters. @@ -163,7 +163,7 @@ private void logDetailAfterIRMatching(LeetcodeInvoker bossInvoker, List input, Map>> matchTracer) { if (Objects.isNull(bossInvoker)) { - if (ContainerCheckUtil.isListEmpty(invokers)) { + if (ContainerUtil.isEmpty(invokers)) { throw new RuntimeException("Cannot find any possible leetcode invoker. Because the candidate leetcode invoker list is empty."); } StringBuilder logBuffer = new StringBuilder(); @@ -253,7 +253,7 @@ private List fetchLeetcodeInvokers(InputParserContext context, // Here are the new features for version 1.0.0 and later. List leetcodeInvokers = new ArrayList<>(); // At first, we fetch the candidate invokers list from the context. - if (!ContainerCheckUtil.isListEmpty(context.getCandidateInvokers())) { + if (ContainerUtil.isNotEmpty(context.getCandidateInvokers())) { leetcodeInvokers.addAll(context.getCandidateInvokers()); } // Then, aware target class from context's target instance. diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java index c98e811..fd199be 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParser.java @@ -64,7 +64,7 @@ final class InputParser { List inputParserNodes = new ArrayList<>(); // Get all class in the INPUT_PARSER_NODE_PACKAGE. List> classesByPackage = PackageUtil.getClassesByPackage(INPUT_PARSER_NODE_PACKAGE); - if (!ContainerCheckUtil.isListEmpty(classesByPackage)) { + if (ContainerUtil.isNotEmpty(classesByPackage)) { for (Class clazz : classesByPackage) { if (ReflectUtil.isExtendsClass(clazz, InputParserNode.class)) { // Instantiate only nodes that contain the @Require annotation. diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserChain.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserChain.java index 0d4c52b..e9a172f 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserChain.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/InputParserChain.java @@ -17,7 +17,7 @@ package io.github.jidcoo.opto.lcdb.enhancer.core.parser; 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 java.util.List; @@ -46,7 +46,7 @@ class InputParserChain extends InputParserNode { * @param nodes the InputParserNode list. */ InputParserChain(List nodes) { - AssertUtil.isTrue(!ContainerCheckUtil.isListEmpty(nodes), "The InputParserNode list cannot be empty."); + AssertUtil.isTrue(ContainerUtil.isNotEmpty(nodes), "The InputParserNode list cannot be empty."); this.nodes = nodes; } diff --git a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java index 8292a50..cbb8500 100644 --- a/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java +++ b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/parser/ParameterAcceptor.java @@ -68,7 +68,7 @@ final class ParameterAcceptor extends BaseParameterAcceptStrategy type.isAnnotationPresent(Require.class) && ReflectUtil.isExtendsClass(type, BaseParameterAcceptStrategy.class) && !Modifier.isAbstract(type.getModifiers()), (Class 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); @@ -128,7 +128,7 @@ public Class getAcceptableType() { * @since 1.0.3 */ Map, Set>> combineCustomStrategies(List> strategies) { - if (ContainerCheckUtil.isListEmpty(strategies)) { + if (ContainerUtil.isEmpty(strategies)) { return null; } Map, Set>> combinedCustomStrategiesMap = new HashMap<>(); 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 2f3d19f..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 @@ -25,7 +25,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.core.parser.InputParserProcessor; 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, @@ -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() 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 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/ProxyPointInterceptorManager.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/core/proxy/ProxyPointInterceptorManager.java index 738f9db..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 @@ -91,7 +91,7 @@ public void doInterceptOnBefore(LeetcodeJavaDebugEnhancer leetcodeJavaDebugEnhan 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) { @@ -113,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/func/require/io/AbsIORequireSupporter.java b/src/main/java/io/github/jidcoo/opto/lcdb/enhancer/func/require/io/AbsIORequireSupporter.java index f5828be..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 @@ -22,7 +22,7 @@ import io.github.jidcoo.opto.lcdb.enhancer.base.Requires; 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.*; @@ -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 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) 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); + } }