1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-04 10:38:19 +08:00

feat(temp): Add a "temporary source" for Testing/FastDev cases. (Use default config in codes first.)

This commit is contained in:
2025-06-25 07:10:04 +08:00
parent 0eda8d8a0f
commit ad6ab9eb36
6 changed files with 148 additions and 6 deletions
@@ -169,15 +169,16 @@ public abstract class ValueType<T> {
* @return The raw type of the generic type
* @throws IllegalStateException if the type is not a Class or ParameterizedType
*/
public Class<?> getRawType() {
@SuppressWarnings("unchecked")
public Class<T> getRawType() {
if (type instanceof Class<?>) {
return (Class<?>) type;
return (Class<T>) type;
}
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
Type raw = pt.getRawType();
if (raw instanceof Class<?>) {
return (Class<?>) raw;
return (Class<T>) raw;
}
}
throw new IllegalStateException("Unsupported type: " + type);
@@ -9,7 +9,6 @@ import cc.carm.lib.configuration.source.meta.ConfigurationMetadata;
import cc.carm.lib.configuration.value.ConfigValue;
import cc.carm.lib.configuration.value.ValueManifest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.NotNullByDefault;
import org.jetbrains.annotations.Nullable;
import java.util.function.BiConsumer;
@@ -17,7 +16,6 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
@NotNullByDefault
public abstract class AbstractConfigBuilder<
TYPE, UNIT, RESULT extends ConfigValue<TYPE, UNIT>, HOLDER extends ConfigurationHolder<?>,
SELF extends AbstractConfigBuilder<TYPE, UNIT, RESULT, HOLDER, SELF>
+3 -1
View File
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<project.jdk.version>1.8</project.jdk.version>
<project.jdk.version>8</project.jdk.version>
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -26,7 +26,9 @@
<module>features/validators</module>
<module>features/text</module>
<module>features/kotlin</module>
<module>features/record</module>
<module>providers/temp</module>
<module>providers/yaml</module>
<module>providers/gson</module>
<module>providers/hocon</module>
+62
View File
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>configured-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>4.1.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<artifactId>configured-temp</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>configured-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>configured-feature-section</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,33 @@
package cc.carm.lib.configuration.source.temp;
import cc.carm.lib.configuration.source.ConfigurationFactory;
import cc.carm.lib.configuration.source.ConfigurationHolder;
import org.jetbrains.annotations.NotNull;
public class TempConfigFactory
extends ConfigurationFactory<TempSource, ConfigurationHolder<TempSource>, TempConfigFactory> {
public static @NotNull TempConfigFactory create() {
return new TempConfigFactory();
}
@Override
protected TempConfigFactory self() {
return this;
}
@Override
public @NotNull ConfigurationHolder<TempSource> build() {
return new ConfigurationHolder<TempSource>(this.adapters, this.options, this.metadata, this.initializer) {
final @NotNull TempSource source = new TempSource(this);
@Override
public @NotNull TempSource config() {
return this.source;
}
};
}
}
@@ -0,0 +1,46 @@
package cc.carm.lib.configuration.source.temp;
import cc.carm.lib.configuration.source.ConfigurationHolder;
import cc.carm.lib.configuration.source.section.ConfigureSource;
import cc.carm.lib.configuration.source.section.SourcedSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Objects;
public class TempSource extends ConfigureSource<SourcedSection, Map<String, Object>, TempSource> {
protected @Nullable SourcedSection rootSection;
protected TempSource(@NotNull ConfigurationHolder<? extends TempSource> holder) {
super(holder, 0);
this.rootSection = SourcedSection.root(this);
}
@Override
protected @NotNull TempSource self() {
return this;
}
@Override
public @NotNull Map<String, Object> original() {
return section().data();
}
@Override
public @NotNull SourcedSection section() {
return Objects.requireNonNull(this.rootSection, "Root section is not initialized.");
}
@Override
public void save() throws Exception {
// Nothing to do here.
}
@Override
protected void onReload() throws Exception {
// Also nothing to do, because this is a temporary source.
}
}