mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat(source): Update sources' original type
This commit is contained in:
@@ -14,7 +14,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JSONSource extends FileConfigSource<MemorySection, Map<?, ?>, JSONSource> {
|
||||
public class JSONSource extends FileConfigSource<MemorySection, Map<String, Object>, JSONSource> {
|
||||
|
||||
public static final @NotNull Gson DEFAULT_GSON = new GsonBuilder()
|
||||
.serializeNulls().disableHtmlEscaping().setPrettyPrinting()
|
||||
@@ -53,7 +53,7 @@ public class JSONSource extends FileConfigSource<MemorySection, Map<?, ?>, JSONS
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<?, ?> original() {
|
||||
public @NotNull Map<String, Object> original() {
|
||||
return section().data();
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyconfiguration-parent</artifactId>
|
||||
<version>3.9.1</version>
|
||||
<version>4.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
@@ -25,6 +25,24 @@
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-feature-commentable</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-feature-file</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-feature-section</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package cc.carm.lib.configuration.source.hocon;
|
||||
|
||||
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||
import com.typesafe.config.Config;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HOCONSection implements ConfigureSection {
|
||||
|
||||
protected final @NotNull HOCONSource source;
|
||||
protected final @Nullable HOCONSection parent;
|
||||
protected final @NotNull Config data;
|
||||
|
||||
public HOCONSection(@NotNull HOCONSource source, @Nullable HOCONSection parent,
|
||||
@NotNull Config data) {
|
||||
this.source = source;
|
||||
this.parent = parent;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public @NotNull Config data() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HOCONSource source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HOCONSection parent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull @UnmodifiableView Map<String, Object> getValues(boolean deep) {
|
||||
return data().root().unwrapped();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return data().hasPath(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return data().getAnyRefList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HOCONSection getSection(@NotNull String path) {
|
||||
return data().getConfig(path) == null ? null : new HOCONSection(source, this, data().getConfig(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return data().getAnyRef(path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cc.carm.lib.configuration.source.hocon;
|
||||
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.section.ConfigureSource;
|
||||
import com.typesafe.config.Config;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class HOCONSource extends ConfigureSource<HOCONSection, Config, HOCONSource> {
|
||||
|
||||
|
||||
private HOCONSection rootSection;
|
||||
|
||||
protected HOCONSource(@NotNull ConfigurationHolder<? extends HOCONSource> holder, long lastUpdateMillis) {
|
||||
super(holder, lastUpdateMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HOCONSource self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Config original() {
|
||||
return section().data();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HOCONSection section() {
|
||||
return Objects.requireNonNull(rootSection, "RootSection is not initialized");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReload() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+14
-21
@@ -1,25 +1,18 @@
|
||||
package online.flowerinsnow.test.easyconfiguration;
|
||||
|
||||
import cc.carm.lib.configuration.EasyConfiguration;
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.hocon.HOCONFileConfigProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class HOCONTest {
|
||||
@Test
|
||||
public void onTest() {
|
||||
HOCONFileConfigProvider provider = EasyConfiguration.from(new File("target/hocon.conf"));
|
||||
|
||||
ConfigurationTest.testDemo(provider);
|
||||
ConfigurationTest.testInner(provider);
|
||||
|
||||
try {
|
||||
provider.save();
|
||||
provider.reload();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// @Test
|
||||
// public void onTest() {
|
||||
// HOCONFileConfigProvider provider = EasyConfiguration.from(new File("target/hocon.conf"));
|
||||
//
|
||||
// ConfigurationTest.testDemo(provider);
|
||||
// ConfigurationTest.testInner(provider);
|
||||
//
|
||||
// try {
|
||||
// provider.save();
|
||||
// provider.reload();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class YAMLSource extends FileConfigSource<MemorySection, Map<?, ?>, YAMLSource> implements CommentedSection {
|
||||
public class YAMLSource extends FileConfigSource<MemorySection, Map<String, Object>, YAMLSource> implements CommentedSection {
|
||||
|
||||
protected final @NotNull YamlConstructor yamlConstructor;
|
||||
protected final @NotNull YamlRepresenter yamlRepresenter;
|
||||
@@ -60,7 +60,7 @@ public class YAMLSource extends FileConfigSource<MemorySection, Map<?, ?>, YAMLS
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<?, ?> original() {
|
||||
public @NotNull Map<String, Object> original() {
|
||||
return section().data();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user