diff --git a/core/src/main/java/cc/carm/lib/configuration/core/source/ConfigurationComments.java b/core/src/main/java/cc/carm/lib/configuration/core/source/ConfigurationComments.java new file mode 100644 index 0000000..d7a1353 --- /dev/null +++ b/core/src/main/java/cc/carm/lib/configuration/core/source/ConfigurationComments.java @@ -0,0 +1,51 @@ +package cc.carm.lib.configuration.core.source; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.*; + +public abstract class ConfigurationComments { + + protected final @NotNull Map> headerComments = new HashMap<>(); + protected final @NotNull Map inlineComments = new HashMap<>(); + + protected @NotNull Map> getHeaderComments() { + return headerComments; + } + + protected @NotNull Map getInlineComments() { + return inlineComments; + } + + public void setHeaderComments(@Nullable String path, @Nullable List comments) { + + if (comments == null) { + getHeaderComments().remove(path); + } else { + getHeaderComments().put(path, comments); + } + } + + + public void setInlineComment(@NotNull String path, @Nullable String comment) { + if (comment == null) { + getInlineComments().remove(path); + } else { + getInlineComments().put(path, comment); + } + } + + @Nullable + @Unmodifiable + public List getHeaderComment(@Nullable String path) { + return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null); + } + + public @Nullable String getInlineComment(@NotNull String path) { + return getInlineComments().get(path); + } + + +} diff --git a/impl/sql/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java b/impl/sql/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java new file mode 100644 index 0000000..fc1246a --- /dev/null +++ b/impl/sql/src/main/java/cc/carm/lib/configuration/EasyConfiguration.java @@ -0,0 +1,6 @@ +package cc.carm.lib.configuration; + +public class EasyConfiguration { + + +} diff --git a/impl/yaml/src/main/java/cc/carm/lib/configuration/yaml/YAMLComments.java b/impl/yaml/src/main/java/cc/carm/lib/configuration/yaml/YAMLComments.java index ddf1f86..f30c343 100644 --- a/impl/yaml/src/main/java/cc/carm/lib/configuration/yaml/YAMLComments.java +++ b/impl/yaml/src/main/java/cc/carm/lib/configuration/yaml/YAMLComments.java @@ -1,60 +1,22 @@ package cc.carm.lib.configuration.yaml; +import cc.carm.lib.configuration.core.source.ConfigurationComments; import org.bspfsystems.yamlconfiguration.configuration.ConfigurationSection; import org.bspfsystems.yamlconfiguration.file.FileConfiguration; import org.bspfsystems.yamlconfiguration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.Unmodifiable; import java.io.BufferedWriter; import java.io.IOException; -import java.util.*; +import java.util.List; +import java.util.StringJoiner; import java.util.stream.Collectors; import java.util.stream.IntStream; import static cc.carm.lib.configuration.yaml.YAMLConfigProvider.SEPARATOR; -public class YAMLComments { - - protected final @NotNull Map> headerComments = new HashMap<>(); - protected final @NotNull Map inlineComments = new HashMap<>(); - - protected @NotNull Map> getHeaderComments() { - return headerComments; - } - - protected @NotNull Map getInlineComments() { - return inlineComments; - } - - public void setHeaderComments(@Nullable String path, @Nullable List comments) { - - if (comments == null) { - getHeaderComments().remove(path); - } else { - getHeaderComments().put(path, comments); - } - } - - - public void setInlineComment(@NotNull String path, @Nullable String comment) { - if (comment == null) { - getInlineComments().remove(path); - } else { - getInlineComments().put(path, comment); - } - } - - @Nullable - @Unmodifiable - public List getHeaderComment(@Nullable String path) { - return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null); - } - - public @Nullable String getInlineComment(@NotNull String path) { - return getInlineComments().get(path); - } +public class YAMLComments extends ConfigurationComments { public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) { List comments = getHeaderComment(path);