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

feat: Implement more sections functions

This commit is contained in:
2025-02-21 11:27:03 +08:00
parent 5c16e98f30
commit d81855697c
4 changed files with 48 additions and 23 deletions
@@ -18,7 +18,7 @@ import java.util.stream.Stream;
* @author Carm
* @since 4.0.0
*/
public interface ConfigureSection extends Cloneable {
public interface ConfigureSection {
/**
* Gets the parent section of this section.
@@ -30,6 +30,24 @@ public interface ConfigureSection extends Cloneable {
@Contract(pure = true)
@Nullable ConfigureSection parent();
/**
* Gets if this section is a root section.
*
* @return True if this section is a root section, false otherwise.
*/
default boolean isRoot() {
return parent() == null;
}
/**
* Gets if this section is empty.
*
* @return True if this section is empty, false otherwise.
*/
default boolean isEmpty() {
return getValues(false).isEmpty();
}
/**
* Gets a set containing all keys in this section.
* <p>
@@ -190,7 +208,10 @@ public interface ConfigureSection extends Cloneable {
* @return The section if the path exists and is a section, otherwise null.
*/
@Nullable
ConfigureSection getSection(@NotNull String path);
default ConfigureSection getSection(@NotNull String path) {
Object val = get(path);
return (val instanceof ConfigureSection) ? (ConfigureSection) val : null;
}
/**
* Get the origin value of the path.
@@ -686,7 +707,8 @@ public interface ConfigureSection extends Cloneable {
}
static <T, C extends Collection<T>> @NotNull C parseCollection(
@Nullable List<?> data, @NotNull Supplier<C> constructor,
@Nullable List<?> data,
@NotNull Supplier<C> constructor,
@NotNull DataFunction<Object, T> parser
) {
C values = constructor.get();
@@ -108,11 +108,6 @@ public abstract class ConfigureSource<
section().remove(path);
}
@Override
public @Nullable ConfigureSection getSection(@NotNull String path) {
return section().getSection(path);
}
@Override
public @Nullable Object get(@NotNull String path) {
return section().get(path);