-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [U] 基于 tchristofferson/ConfigUpdater 项目重写YAML相关配置文件的注释部分。 - [A] 为 @ConfigComment 注解添加 ”statWrap“ 与 "endWrap" 两个选项,用于实现不同样式的注释。
- Loading branch information
Showing
30 changed files
with
358 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
core/src/main/java/cc/carm/lib/configuration/core/builder/CommonConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,12 @@ | ||
package cc.carm.lib.configuration.core.builder; | ||
|
||
import cc.carm.lib.configuration.core.source.ConfigurationProvider; | ||
import cc.carm.lib.configuration.core.value.ConfigValue; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public abstract class CommonConfigBuilder<T, B extends CommonConfigBuilder<T, B>> | ||
extends AbstractConfigBuilder<T, B, ConfigurationProvider<?>> { | ||
|
||
protected @Nullable ConfigurationProvider<?> provider; | ||
protected @Nullable String path; | ||
|
||
protected @NotNull String[] comments = new String[0]; | ||
protected @Nullable T defaultValue; | ||
|
||
public CommonConfigBuilder() { | ||
super(ConfigurationProvider.class); | ||
} | ||
|
||
protected abstract @NotNull B getThis(); | ||
|
||
public abstract @NotNull ConfigValue<?> build(); | ||
|
||
public @NotNull B from(@Nullable ConfigurationProvider<?> provider) { | ||
this.provider = provider; | ||
return getThis(); | ||
} | ||
|
||
public @NotNull B path(@Nullable String path) { | ||
this.path = path; | ||
return getThis(); | ||
} | ||
|
||
public @NotNull B comments(@NotNull String... comments) { | ||
this.comments = comments; | ||
return getThis(); | ||
} | ||
|
||
public @NotNull B defaults(@Nullable T defaultValue) { | ||
this.defaultValue = defaultValue; | ||
return getThis(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
core/src/main/java/cc/carm/lib/configuration/core/source/ConfigCommentInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cc.carm.lib.configuration.core.source; | ||
|
||
import cc.carm.lib.configuration.core.annotation.ConfigComment; | ||
import cc.carm.lib.configuration.core.value.ConfigValue; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class ConfigCommentInfo { | ||
|
||
public static @NotNull ConfigCommentInfo DEFAULT_INFO = of(new String[0], true, false); | ||
|
||
protected final @NotNull String[] comments; | ||
protected final boolean startWrap; | ||
protected final boolean endWrap; | ||
|
||
public ConfigCommentInfo(@NotNull String[] comments, boolean startWrap, boolean endWrap) { | ||
this.comments = comments; | ||
this.startWrap = startWrap; | ||
this.endWrap = endWrap; | ||
} | ||
|
||
public @NotNull String[] getComments() { | ||
return comments; | ||
} | ||
|
||
public boolean endWrap() { | ||
return endWrap; | ||
} | ||
|
||
public boolean startWrap() { | ||
return startWrap; | ||
} | ||
|
||
public static @NotNull ConfigCommentInfo of(@NotNull String[] comments, boolean startWrap, boolean endWrap) { | ||
return new ConfigCommentInfo(comments, startWrap, endWrap); | ||
} | ||
|
||
public static @NotNull ConfigCommentInfo defaults() { | ||
return DEFAULT_INFO; | ||
} | ||
|
||
@Contract("!null->!null") | ||
public static @Nullable ConfigCommentInfo fromAnnotation(@Nullable ConfigComment comment) { | ||
if (comment == null) return null; | ||
else return new ConfigCommentInfo(comment.value(), comment.startWrap(), comment.endWrap()); | ||
} | ||
|
||
public static @NotNull ConfigCommentInfo fromValue(@NotNull ConfigValue<?> value) { | ||
return Optional.ofNullable(value.getComments()).orElse(defaults()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ConfigCommentInfo that = (ConfigCommentInfo) o; | ||
return startWrap == that.startWrap && endWrap == that.endWrap && Arrays.equals(getComments(), that.getComments()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(startWrap, endWrap); | ||
result = 31 * result + Arrays.hashCode(getComments()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ConfigCommentInfo{" + | ||
"comments=" + Arrays.toString(comments) + | ||
", startWrap=" + startWrap + | ||
", endWrap=" + endWrap + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.