mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat(loader): Refactor loaders and metadata.
This commit is contained in:
@@ -2,6 +2,9 @@ import cc.carm.lib.configuration.adapter.ValueAdapterRegistry;
|
||||
import cc.carm.lib.configuration.adapter.strandard.EnumAdapter;
|
||||
import cc.carm.lib.configuration.adapter.strandard.PrimitiveAdapters;
|
||||
import cc.carm.lib.configuration.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.loader.ConfigurationLoader;
|
||||
import cc.carm.lib.easyoptions.OptionHolder;
|
||||
import cc.carm.test.config.TestSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -12,7 +15,7 @@ public class AdaptTest {
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
ValueAdapterRegistry<ConfigurationProvider> registry = new ValueAdapterRegistry<>();
|
||||
ValueAdapterRegistry registry = new ValueAdapterRegistry();
|
||||
registry.register(Long.class, PrimitiveAdapters.ofLong());
|
||||
registry.register(long.class, PrimitiveAdapters.ofLong());
|
||||
registry.register(Integer.class, PrimitiveAdapters.ofInteger());
|
||||
@@ -30,7 +33,7 @@ public class AdaptTest {
|
||||
registry.register(Boolean.class, PrimitiveAdapters.ofBoolean());
|
||||
registry.register(boolean.class, PrimitiveAdapters.ofBoolean());
|
||||
registry.register(String.class, PrimitiveAdapters.ofString());
|
||||
registry.register(new EnumAdapter<>());
|
||||
registry.register(new EnumAdapter());
|
||||
|
||||
registry.register(Long.class, Duration.class, Duration::ofSeconds, Duration::getSeconds);
|
||||
registry.register(
|
||||
@@ -39,7 +42,7 @@ public class AdaptTest {
|
||||
data -> Duration.between(LocalTime.now(), data)
|
||||
);
|
||||
|
||||
ConfigurationProvider provider = new ConfigurationProvider();
|
||||
ConfigurationProvider<TestSource> provider = new ConfigurationProvider<>(new TestSource(), new ConfigurationLoader(), registry, new OptionHolder());
|
||||
|
||||
LocalTime v = registry.deserialize(provider, LocalTime.class, "600");
|
||||
Object d = registry.serialize(provider, v);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import cc.carm.lib.configuration.loader.PathGenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NameTest {
|
||||
@@ -6,10 +7,10 @@ public class NameTest {
|
||||
@Test
|
||||
public void onTest() {
|
||||
|
||||
System.out.println(ConfigInitializer.getPathFromName("LoveGames")); // -> love-games
|
||||
System.out.println(ConfigInitializer.getPathFromName("EASY_GAME")); // -> easy-game
|
||||
System.out.println(ConfigInitializer.getPathFromName("F")); //-? f
|
||||
System.out.println(ConfigInitializer.getPathFromName("Test123123")); // -? test123123123
|
||||
System.out.println(PathGenerator.covertPathName("LoveGames")); // -> love-games
|
||||
System.out.println(PathGenerator.covertPathName("EASY_GAME")); // -> easy-game
|
||||
System.out.println(PathGenerator.covertPathName("F")); //-? f
|
||||
System.out.println(PathGenerator.covertPathName("Test123123")); // -? test123123123
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package cc.carm.test.config;
|
||||
|
||||
import cc.carm.lib.configuration.adapter.ValueAdapterRegistry;
|
||||
import cc.carm.lib.configuration.annotation.ConfigPath;
|
||||
import cc.carm.lib.configuration.Configuration;
|
||||
import cc.carm.lib.configuration.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.loader.ConfigurationLoader;
|
||||
import cc.carm.lib.easyoptions.OptionHolder;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LoaderTest {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
ConfigurationProvider<TestSource> provider = new ConfigurationProvider<>(new TestSource(), new ConfigurationLoader(), new ValueAdapterRegistry(), new OptionHolder());
|
||||
|
||||
ConfigurationLoader loader = new ConfigurationLoader();
|
||||
loader.load(provider, ROOT.class);
|
||||
}
|
||||
|
||||
interface ROOT extends Configuration {
|
||||
|
||||
interface SUB extends Configuration {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ConfigPath(root = true)
|
||||
interface EXTERNAL extends Configuration {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ConfigPath("NO")
|
||||
interface YES extends Configuration {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package cc.carm.test.config;
|
||||
|
||||
import cc.carm.lib.configuration.source.ConfigurationSection;
|
||||
import cc.carm.lib.configuration.source.ConfigurationSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestSource extends ConfigurationSource<TestSource, Map<String, String>> {
|
||||
|
||||
public TestSource() {
|
||||
super(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestSource getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReload() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, String> original() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSection(@NotNull String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationSection getSection(@NotNull String path) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user