mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat: Implement more sections functions
This commit is contained in:
@@ -30,6 +30,15 @@ public interface ConfigureSection {
|
|||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@Nullable ConfigureSection parent();
|
@Nullable ConfigureSection parent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path separator for the section.
|
||||||
|
*
|
||||||
|
* @return The path separator
|
||||||
|
*/
|
||||||
|
default char pathSeparator() {
|
||||||
|
return '.';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if this section is a root section.
|
* Gets if this section is a root section.
|
||||||
*
|
*
|
||||||
@@ -706,6 +715,11 @@ public interface ConfigureSection {
|
|||||||
return stream(path).map(parser);
|
return stream(path).map(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default String childPath(String path) {
|
||||||
|
int index = path.indexOf(pathSeparator());
|
||||||
|
return (index == -1) ? path : path.substring(index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static <T, C extends Collection<T>> @NotNull C parseCollection(
|
static <T, C extends Collection<T>> @NotNull C parseCollection(
|
||||||
@Nullable List<?> data,
|
@Nullable List<?> data,
|
||||||
@NotNull Supplier<C> constructor,
|
@NotNull Supplier<C> constructor,
|
||||||
|
|||||||
-13
@@ -71,14 +71,6 @@ public abstract class MapSection<R extends MapSection<R>> implements ConfigureSe
|
|||||||
return this.parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the path separator for the section.
|
|
||||||
*
|
|
||||||
* @return The path separator
|
|
||||||
*/
|
|
||||||
public char pathSeparator() {
|
|
||||||
return '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||||
@@ -124,11 +116,6 @@ public abstract class MapSection<R extends MapSection<R>> implements ConfigureSe
|
|||||||
return (R) data().computeIfAbsent(root, k -> createChild());
|
return (R) data().computeIfAbsent(root, k -> createChild());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String childPath(String path) {
|
|
||||||
int index = path.indexOf(pathSeparator());
|
|
||||||
return (index == -1) ? path : path.substring(index + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the values of the children of the section to the output map.
|
* Map the values of the children of the section to the output map.
|
||||||
*
|
*
|
||||||
|
|||||||
+33
-1
@@ -1,6 +1,38 @@
|
|||||||
package cc.carm.lib.configuration.source.section;
|
package cc.carm.lib.configuration.source.section;
|
||||||
|
|
||||||
public class ShadedSection {
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.UnmodifiableView;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ShadedSection implements ConfigureSection {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigureSection parent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull @UnmodifiableView Map<String, Object> getValues(boolean deep) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(@NotNull String path, @Nullable Object value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(@NotNull String path) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Object get(@NotNull String path) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,6 @@ public class ShadeTest {
|
|||||||
data.put("cards", Arrays.asList("33333", "55555")); // 应当直接覆盖原先的List
|
data.put("cards", Arrays.asList("33333", "55555")); // 应当直接覆盖原先的List
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user