1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-05 02:58:20 +08:00

feat: Split MapSection and MemorySection

This commit is contained in:
2025-02-20 02:50:00 +08:00
parent a4659c5c9f
commit 1c002ae535
14 changed files with 184 additions and 153 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>4.0.2</version>
<version>4.0.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -2,7 +2,7 @@ package cc.carm.lib.configuration.source.json;
import cc.carm.lib.configuration.source.ConfigurationHolder;
import cc.carm.lib.configuration.source.file.FileConfigSource;
import cc.carm.lib.configuration.source.section.MemorySection;
import cc.carm.lib.configuration.source.section.MapSection;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSerializer;
@@ -14,17 +14,17 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
public class JSONSource extends FileConfigSource<MemorySection, Map<String, Object>, JSONSource> {
public class JSONSource extends FileConfigSource<MapSection, Map<String, Object>, JSONSource> {
public static final @NotNull Gson DEFAULT_GSON = new GsonBuilder()
.serializeNulls().disableHtmlEscaping().setPrettyPrinting()
.registerTypeAdapter(
MemorySection.class,
(JsonSerializer<MemorySection>) (src, t, c) -> c.serialize(src.data())
MapSection.class,
(JsonSerializer<MapSection>) (src, t, c) -> c.serialize(src.data())
).create();
protected final @NotNull Gson gson;
protected @Nullable MemorySection rootSection;
protected @Nullable MapSection rootSection;
protected JSONSource(@NotNull ConfigurationHolder<? extends JSONSource> holder,
@NotNull File file, @Nullable String resourcePath) {
@@ -58,7 +58,7 @@ public class JSONSource extends FileConfigSource<MemorySection, Map<String, Obje
}
@Override
public @NotNull MemorySection section() {
public @NotNull MapSection section() {
return Objects.requireNonNull(this.rootSection, "Root section is not initialized");
}
@@ -70,7 +70,7 @@ public class JSONSource extends FileConfigSource<MemorySection, Map<String, Obje
@Override
protected void onReload() throws Exception {
Map<?, ?> data = fileReader(reader -> gson.fromJson(reader, LinkedHashMap.class));
this.rootSection = MemorySection.root(this, data);
this.rootSection = MapSection.root(this, data);
this.lastUpdateMillis = System.currentTimeMillis(); // 更新时间
}