mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat!(core): Finished the design of core module
This commit is contained in:
+20
-3
@@ -2,8 +2,12 @@ package cc.carm.lib.configuration.commentable;
|
||||
|
||||
import cc.carm.lib.configuration.annotation.HeaderComment;
|
||||
import cc.carm.lib.configuration.annotation.InlineComment;
|
||||
import cc.carm.lib.configuration.meta.PathMetadata;
|
||||
import cc.carm.lib.configuration.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.source.loader.ConfigurationInitializer;
|
||||
import cc.carm.lib.configuration.source.meta.ConfigurationMetadata;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,11 +16,24 @@ public interface CommentableMetaTypes {
|
||||
/**
|
||||
* Configuration's {@link HeaderComment}
|
||||
*/
|
||||
PathMetadata<List<String>> HEADER_COMMENTS = PathMetadata.of(Collections.emptyList());
|
||||
ConfigurationMetadata<List<String>> HEADER_COMMENTS = ConfigurationMetadata.of(Collections.emptyList());
|
||||
|
||||
/**
|
||||
* Configuration's {@link InlineComment}
|
||||
*/
|
||||
PathMetadata<String> INLINE_COMMENT_VALUE = PathMetadata.of();
|
||||
ConfigurationMetadata<String> INLINE_COMMENT = ConfigurationMetadata.of();
|
||||
|
||||
|
||||
static void register(@NotNull ConfigurationProvider<?> provider) {
|
||||
register(provider.initializer());
|
||||
}
|
||||
|
||||
static void register(@NotNull ConfigurationInitializer initializer) {
|
||||
initializer.registerAnnotation(
|
||||
HeaderComment.class, HEADER_COMMENTS,
|
||||
a -> Arrays.asList(a.value())
|
||||
);
|
||||
initializer.registerAnnotation(InlineComment.class, INLINE_COMMENT, InlineComment::value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package cc.carm.lib.configuration.commentable;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ConfigurationComments {
|
||||
|
||||
protected final @NotNull Map<String, List<String>> headerComments = new HashMap<>();
|
||||
protected final @NotNull Map<String, String> inlineComments = new HashMap<>();
|
||||
|
||||
protected @NotNull Map<String, List<String>> getHeaderComments() {
|
||||
return headerComments;
|
||||
}
|
||||
|
||||
protected @NotNull Map<String, String> getInlineComments() {
|
||||
return inlineComments;
|
||||
}
|
||||
|
||||
public void setHeaderComments(@Nullable String path, @Nullable List<String> 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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user