From 0d19dc236ee60b85d816f531bffa2dd8b95717ad Mon Sep 17 00:00:00 2001 From: carm Date: Thu, 4 Jan 2024 21:20:56 +0800 Subject: [PATCH] docs(sample): Add sample codes. :egg: --- README.md | 24 +++++----- README_CN.md | 52 +++++++++++----------- impl/yaml/src/test/java/config/Sample.java | 38 ++++++++-------- 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index dfd9e8a..895899e 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,8 @@ Check out all code demonstrations [HERE](demo/src/main/java/cc/carm/lib/configur For more examples, see the [Development Guide](.doc/README.md). ```java -public class Sample { - - @HeaderComment("Configurations for sample") - interface SampleConfig extends Configuration { +@HeaderComment("Configurations for sample") +interface SampleConfig extends Configuration { @InlineComment("Enabled?") // Inline comment ConfiguredValue ENABLED = ConfiguredValue.of(true); @@ -63,18 +61,21 @@ public class Sample { UUID.fromString("00000000-0000-0000-0000-000000000000"), UUID.fromString("00000000-0000-0000-0000-000000000001") ).build(); - + interface INFO extends Configuration { - @HeaderComment("Configure your name!") // Header comment - ConfiguredValue NAME = ConfiguredValue.of("Joker"); + @HeaderComment("Configure your name!") // Header comment + ConfiguredValue NAME = ConfiguredValue.of("Joker"); - @ConfigPath("year") // Custom path - ConfiguredValue AGE = ConfiguredValue.of(24); - + @ConfigPath("year") // Custom path + ConfiguredValue AGE = ConfiguredValue.of(24); + } - } +} +``` +```java +public class Sample { public static void main(String[] args) { // 1. Make a configuration provider from a file. ConfigurationProvider provider = EasyConfiguration.from("config.yml"); @@ -84,7 +85,6 @@ public class Sample { SampleConfig.ENABLED.set(false); System.out.println("Your name is " + SampleConfig.INFO.NAME.getNotNull() + " !"); } - } ``` diff --git a/README_CN.md b/README_CN.md index affeafa..49fd9ba 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,32 +42,35 @@ README LANGUAGES [ [English](README.md) | [**中文**](README_CN.md) ] 您可以 [点击这里](demo/src/main/java/cc/carm/lib/configuration/demo) 直接查看现有的代码演示,更多复杂情况演示详见 [开发介绍](.doc/README.md) 。 + +```java +@HeaderComment("Configurations for sample") +interface SampleConfig extends Configuration { + + @InlineComment("Enabled?") // 行内注释 + ConfiguredValue ENABLED = ConfiguredValue.of(true); + + ConfiguredList UUIDS = ConfiguredList.builderOf(UUID.class).fromString() + .parseValue(UUID::fromString).serializeValue(UUID::toString) + .defaults( + UUID.fromString("00000000-0000-0000-0000-000000000000"), + UUID.fromString("00000000-0000-0000-0000-000000000001") + ).build(); + + interface INFO extends Configuration { + + @HeaderComment("Configure your name!") // 头部注释 + ConfiguredValue NAME = ConfiguredValue.of("Joker"); + + @ConfigPath("year") // 自定义配置路径,若不定义,则按照默认规则生成 + ConfiguredValue AGE = ConfiguredValue.of(24); + + } +} +``` + ```java public class Sample { - - @HeaderComment("Configurations for sample") - interface SampleConfig extends Configuration { - - @InlineComment("Enabled?") // 行内注释 - ConfiguredValue ENABLED = ConfiguredValue.of(true); - - ConfiguredList UUIDS = ConfiguredList.builderOf(UUID.class).fromString() - .parseValue(UUID::fromString).serializeValue(UUID::toString) - .defaults( - UUID.fromString("00000000-0000-0000-0000-000000000000"), - UUID.fromString("00000000-0000-0000-0000-000000000001") - ).build(); - - interface INFO extends Configuration { - - @HeaderComment("Configure your name!") // 头部注释 - ConfiguredValue NAME = ConfiguredValue.of("Joker"); - - @ConfigPath("year") // 自定义配置路径,若不定义,则按照默认规则生成 - ConfiguredValue AGE = ConfiguredValue.of(24); - } - } - public static void main(String[] args) { // 1. 生成一个 “Provider” 用于给配置类提供源配置的文件。 ConfigurationProvider provider = EasyConfiguration.from("config.yml"); @@ -77,7 +80,6 @@ public class Sample { SampleConfig.ENABLED.set(false); System.out.println("Your name is " + SampleConfig.INFO.NAME.getNotNull() + " !"); } - } ``` diff --git a/impl/yaml/src/test/java/config/Sample.java b/impl/yaml/src/test/java/config/Sample.java index 5affdd4..5142fb4 100644 --- a/impl/yaml/src/test/java/config/Sample.java +++ b/impl/yaml/src/test/java/config/Sample.java @@ -11,31 +11,31 @@ import cc.carm.lib.configuration.core.value.type.ConfiguredValue; import java.util.UUID; -public class Sample { +@HeaderComment("Configurations for sample") +interface SampleConfig extends Configuration { - @HeaderComment("Configurations for sample") - interface SampleConfig extends Configuration { + @InlineComment("Enabled?") // Inline comment + ConfiguredValue ENABLED = ConfiguredValue.of(true); - @InlineComment("Enabled?") // Inline comment - ConfiguredValue ENABLED = ConfiguredValue.of(true); + ConfiguredList UUIDS = ConfiguredList.builderOf(UUID.class).fromString() + .parseValue(UUID::fromString).serializeValue(UUID::toString) + .defaults( + UUID.fromString("00000000-0000-0000-0000-000000000000"), + UUID.fromString("00000000-0000-0000-0000-000000000001") + ).build(); - ConfiguredList UUIDS = ConfiguredList.builderOf(UUID.class).fromString() - .parseValue(UUID::fromString).serializeValue(UUID::toString) - .defaults( - UUID.fromString("00000000-0000-0000-0000-000000000000"), - UUID.fromString("00000000-0000-0000-0000-000000000001") - ).build(); - - interface INFO extends Configuration { - @HeaderComment("Configure your name!") // Header comment - ConfiguredValue NAME = ConfiguredValue.of("Joker"); - - @ConfigPath("year") // Custom path - ConfiguredValue AGE = ConfiguredValue.of(24); - } + interface INFO extends Configuration { + @HeaderComment("Configure your name!") // Header comment + ConfiguredValue NAME = ConfiguredValue.of("Joker"); + @ConfigPath("year") // Custom path + ConfiguredValue AGE = ConfiguredValue.of(24); } +} + +public class Sample { + public static void main(String[] args) { // 1. Make a configuration provider from a file. ConfigurationProvider provider = EasyConfiguration.from("config.yml");