From 3473ef2247cfaf1ed455aa2d13e44e246027d049 Mon Sep 17 00:00:00 2001 From: Carm Date: Fri, 21 Feb 2025 16:17:12 +0800 Subject: [PATCH] feat: Implement more sections functions --- .../source/section/ConfigureSection.java | 14 ++++++++ .../source/section/MapSection.java | 13 ------- .../source/section/ShadedSection.java | 34 ++++++++++++++++++- .../src/test/java/test/section/ShadeTest.java | 1 - 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/cc/carm/lib/configuration/source/section/ConfigureSection.java b/core/src/main/java/cc/carm/lib/configuration/source/section/ConfigureSection.java index 2bd49e9..e77199b 100644 --- a/core/src/main/java/cc/carm/lib/configuration/source/section/ConfigureSection.java +++ b/core/src/main/java/cc/carm/lib/configuration/source/section/ConfigureSection.java @@ -30,6 +30,15 @@ public interface ConfigureSection { @Contract(pure = true) @Nullable ConfigureSection parent(); + /** + * Get the path separator for the section. + * + * @return The path separator + */ + default char pathSeparator() { + return '.'; + } + /** * Gets if this section is a root section. * @@ -706,6 +715,11 @@ public interface ConfigureSection { return stream(path).map(parser); } + default String childPath(String path) { + int index = path.indexOf(pathSeparator()); + return (index == -1) ? path : path.substring(index + 1); + } + static > @NotNull C parseCollection( @Nullable List data, @NotNull Supplier constructor, diff --git a/features/section/src/main/java/cc/carm/lib/configuration/source/section/MapSection.java b/features/section/src/main/java/cc/carm/lib/configuration/source/section/MapSection.java index 0b66c76..d73e4c6 100644 --- a/features/section/src/main/java/cc/carm/lib/configuration/source/section/MapSection.java +++ b/features/section/src/main/java/cc/carm/lib/configuration/source/section/MapSection.java @@ -71,14 +71,6 @@ public abstract class MapSection> implements ConfigureSe return this.parent; } - /** - * Get the path separator for the section. - * - * @return The path separator - */ - public char pathSeparator() { - return '.'; - } @Override public @NotNull Map getValues(boolean deep) { @@ -124,11 +116,6 @@ public abstract class MapSection> implements ConfigureSe return (R) data().computeIfAbsent(root, k -> createChild()); } - private String childPath(String path) { - int index = path.indexOf(pathSeparator()); - return (index == -1) ? path : path.substring(index + 1); - } - /** * Map the values of the children of the section to the output map. * diff --git a/features/section/src/main/java/cc/carm/lib/configuration/source/section/ShadedSection.java b/features/section/src/main/java/cc/carm/lib/configuration/source/section/ShadedSection.java index 8579e7d..9be4417 100644 --- a/features/section/src/main/java/cc/carm/lib/configuration/source/section/ShadedSection.java +++ b/features/section/src/main/java/cc/carm/lib/configuration/source/section/ShadedSection.java @@ -1,6 +1,38 @@ package cc.carm.lib.configuration.source.section; -public class ShadedSection { +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.Collections; +import java.util.Map; + +public class ShadedSection implements ConfigureSection { + @Override + public @Nullable ConfigureSection parent() { + return null; + } + + @Override + public @NotNull @UnmodifiableView Map getValues(boolean deep) { + return Collections.emptyMap(); + } + + @Override + public void set(@NotNull String path, @Nullable Object value) { + + } + + @Override + public void remove(@NotNull String path) { + + } + + @Override + public @Nullable Object get(@NotNull String path) { + return null; + } + } \ No newline at end of file diff --git a/features/section/src/test/java/test/section/ShadeTest.java b/features/section/src/test/java/test/section/ShadeTest.java index babf98d..1626846 100644 --- a/features/section/src/test/java/test/section/ShadeTest.java +++ b/features/section/src/test/java/test/section/ShadeTest.java @@ -35,7 +35,6 @@ public class ShadeTest { data.put("cards", Arrays.asList("33333", "55555")); // 应当直接覆盖原先的List }); - } }