mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat: Simplify the ConfigureSection functions to support more different usages.
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.0.1</version>
|
||||
<version>4.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
|
||||
@@ -7,6 +7,7 @@ import cc.carm.lib.configuration.source.loader.ConfigurationInitializer;
|
||||
import cc.carm.lib.configuration.source.meta.ConfigurationMetaHolder;
|
||||
import cc.carm.lib.configuration.source.meta.ConfigurationMetadata;
|
||||
import cc.carm.lib.configuration.source.option.ConfigurationOptionHolder;
|
||||
import cc.carm.lib.configuration.source.option.StandardOptions;
|
||||
import cc.carm.lib.configuration.source.section.ConfigureSource;
|
||||
import cc.carm.lib.configuration.value.ValueManifest;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cc.carm.lib.configuration.source.section;
|
||||
|
||||
import cc.carm.lib.configuration.function.DataFunction;
|
||||
import cc.carm.lib.configuration.source.option.StandardOptions;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -14,14 +13,8 @@ import java.util.stream.Stream;
|
||||
|
||||
public interface ConfigureSection {
|
||||
|
||||
@NotNull ConfigureSource<?, ?, ?> source();
|
||||
|
||||
@Nullable ConfigureSection parent();
|
||||
|
||||
default char separator() {
|
||||
return source().holder().options().get(StandardOptions.PATH_SEPARATOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@UnmodifiableView
|
||||
default Set<String> getKeys(boolean deep) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cc.carm.lib.configuration.source.section;
|
||||
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.option.StandardOptions;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,28 +27,46 @@ public abstract class ConfigureSource<
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
||||
public void reload() throws Exception {
|
||||
onReload(); // 调用重写的Reload方法
|
||||
this.lastUpdateMillis = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
protected abstract SELF self();
|
||||
@Contract(pure = true)
|
||||
@ApiStatus.Internal
|
||||
protected abstract @NotNull SELF self();
|
||||
|
||||
/**
|
||||
* @return Original configuration object
|
||||
* @return The original configuration object.
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public abstract @NotNull ORIGINAL original();
|
||||
|
||||
/**
|
||||
* @return The root {@link ConfigureSection}
|
||||
* @return The root {@link ConfigureSection}, which represents the entire configuration.
|
||||
*/
|
||||
public abstract @NotNull SECTION section();
|
||||
|
||||
/**
|
||||
* Save the whole configuration.
|
||||
*
|
||||
* @throws Exception If any error occurs while saving.
|
||||
*/
|
||||
public abstract void save() throws Exception;
|
||||
|
||||
/**
|
||||
* Reload the configuration.
|
||||
* <br>This used for implementation, for external usage, use {@link #reload()}
|
||||
*
|
||||
* @throws Exception If any error occurs while reloading.
|
||||
*/
|
||||
@ApiStatus.OverrideOnly
|
||||
protected abstract void onReload() throws Exception;
|
||||
|
||||
public char pathSeparator() {
|
||||
return holder().options().get(StandardOptions.PATH_SEPARATOR);
|
||||
}
|
||||
|
||||
public long getLastUpdateMillis() {
|
||||
return this.lastUpdateMillis;
|
||||
}
|
||||
@@ -54,14 +75,15 @@ public abstract class ConfigureSource<
|
||||
return getLastUpdateMillis() > parsedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Source also represents the root section, so it has no parent
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
@Override
|
||||
@Contract(pure = true, value = "->null")
|
||||
public @Nullable ConfigureSection parent() {
|
||||
return null; // Source also represents the root section, so it has no parent
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigureSource<?, ?, ?> source() {
|
||||
return self();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,21 +101,11 @@ public abstract class ConfigureSource<
|
||||
return section().contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return section().isList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return section().getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSection(@NotNull String path) {
|
||||
return section().isSection(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigureSection getSection(@NotNull String path) {
|
||||
return section().getSection(path);
|
||||
|
||||
Reference in New Issue
Block a user