1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-04 18:48:20 +08:00

feat(section): Implement more sections

This commit is contained in:
2025-02-21 03:07:43 +08:00
parent d8191b7c6d
commit 3f1ffadeff
5 changed files with 205 additions and 27 deletions
@@ -19,7 +19,7 @@ import java.util.stream.Stream;
* @since 4.0.0
*/
public interface ConfigureSection extends Cloneable {
/**
* Gets the parent section of this section.
* <p>
@@ -136,7 +136,9 @@ public interface ConfigureSection extends Cloneable {
* @param path The path to check.
* @return True if the value is present, false otherwise.
*/
boolean contains(@NotNull String path);
default boolean contains(@NotNull String path) {
return get(path) != null;
}
/**
* Predicate the value of given path is specific type.
@@ -166,7 +168,10 @@ public interface ConfigureSection extends Cloneable {
* @param path The path to get the {@link List}.
* @return The list if the path exists and is a list, otherwise null.
*/
@Nullable List<?> getList(@NotNull String path);
default @Nullable List<?> getList(@NotNull String path) {
Object val = get(path);
return (val instanceof List<?>) ? (List<?>) val : null;
}
/**
* Predicate the value of given path is a {@link ConfigureSection}.
@@ -7,7 +7,6 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
/**
@@ -104,21 +103,11 @@ public abstract class ConfigureSource<
section().set(path, value);
}
@Override
public boolean contains(@NotNull String path) {
return section().contains(path);
}
@Override
public void remove(@NotNull String path) {
section().remove(path);
}
@Override
public @Nullable List<?> getList(@NotNull String path) {
return section().getList(path);
}
@Override
public @Nullable ConfigureSection getSection(@NotNull String path) {
return section().getSection(path);