mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 10:38:19 +08:00
feat(section): Add #contains and #containsValue methods
This commit is contained in:
@@ -155,7 +155,7 @@ public interface ConfigureSection {
|
||||
void remove(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Check if the value of given path is present.
|
||||
* Check if the given path is present.
|
||||
* <p>
|
||||
* Path separator depends on holder's
|
||||
* {@link cc.carm.lib.configuration.source.option.StandardOptions#PATH_SEPARATOR}
|
||||
@@ -164,6 +164,19 @@ public interface ConfigureSection {
|
||||
* @return True if the value is present, false otherwise.
|
||||
*/
|
||||
default boolean contains(@NotNull String path) {
|
||||
return getKeys(true).contains(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value of given path is present.
|
||||
* <p>
|
||||
* Path separator depends on holder's
|
||||
* {@link cc.carm.lib.configuration.source.option.StandardOptions#PATH_SEPARATOR}
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the value is present, false otherwise.
|
||||
*/
|
||||
default boolean containsValue(@NotNull String path) {
|
||||
return get(path) != null;
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -45,6 +45,16 @@ public abstract class MapSection<R extends MapSection<R>> implements ConfigureSe
|
||||
return createChild(new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
R section = getSectionFor(path);
|
||||
if (section == this) {
|
||||
return this.data().containsKey(path);
|
||||
} else {
|
||||
return section.contains(childPath(path));
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Object> data() {
|
||||
return this.data;
|
||||
}
|
||||
@@ -136,4 +146,5 @@ public abstract class MapSection<R extends MapSection<R>> implements ConfigureSe
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user