mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2024-09-19 12:15:52 +00:00
docs(sample): Add sample codes. 🥚
This commit is contained in:
parent
814dae2278
commit
e42de0eee7
50
README.md
50
README.md
@ -51,25 +51,45 @@ For more examples, see the [Development Guide](.doc/README.md).
|
||||
```java
|
||||
public class Sample {
|
||||
|
||||
@HeaderComment("Configurations for sample")
|
||||
interface SampleConfig extends Configuration {
|
||||
@HeaderComment("Configure your name!") // Header comment
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
@InlineComment("Enabled?") // Inline comment
|
||||
ConfiguredValue<Boolean> ENABLED = ConfiguredValue.of(true);
|
||||
@HeaderComment("Configurations for sample")
|
||||
interface SampleConfig extends Configuration {
|
||||
|
||||
@InlineComment("Enabled?") // Inline comment
|
||||
ConfiguredValue<Boolean> ENABLED = ConfiguredValue.of(true);
|
||||
|
||||
interface INFO extends Configuration {
|
||||
@HeaderComment("Configure your name!") // Header comment
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
|
||||
ConfiguredValue<Integer> AGE = ConfiguredValue.of(24);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 1. Make a configuration provider from a file.
|
||||
ConfigurationProvider<?> provider = EasyConfiguration.from("config.yml");
|
||||
// 2. Initialize the configuration classes or instances.
|
||||
provider.initialize(SampleConfig.class);
|
||||
// 3. Enjoy using the configuration!
|
||||
SampleConfig.ENABLED.set(false);
|
||||
System.out.println("Your name is " + SampleConfig.NAME.getNotNull() + " !");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 1. Make a configuration provider from a file.
|
||||
ConfigurationProvider<?> provider = EasyConfiguration.from("config.yml");
|
||||
// 2. Initialize the configuration classes or instances.
|
||||
provider.initialize(SampleConfig.class);
|
||||
// 3. Enjoy using the configuration!
|
||||
SampleConfig.ENABLED.set(false);
|
||||
System.out.println("Your name is " + SampleConfig.INFO.NAME.getNotNull() + " !");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```yaml
|
||||
# Configurations for sample
|
||||
|
||||
# Enabled?
|
||||
enabled: true
|
||||
|
||||
info:
|
||||
# Configure your name!
|
||||
name: Joker
|
||||
age: 24
|
||||
```
|
||||
|
||||
### Dependencies
|
||||
|
25
README_CN.md
25
README_CN.md
@ -47,10 +47,17 @@ public class Sample {
|
||||
|
||||
@HeaderComment("Configurations for sample")
|
||||
interface SampleConfig extends Configuration {
|
||||
@HeaderComment("Configure your name!") // 头部注释
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
|
||||
@InlineComment("Enabled?") // 行内注释
|
||||
ConfiguredValue<Boolean> ENABLED = ConfiguredValue.of(true);
|
||||
|
||||
interface INFO extends Configuration {
|
||||
@HeaderComment("Configure your name!") // 头部注释
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
|
||||
ConfiguredValue<Integer> AGE = ConfiguredValue.of(24);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -60,12 +67,24 @@ public class Sample {
|
||||
provider.initialize(SampleConfig.class);
|
||||
// 3. 现在可以享受快捷方便的配置文件使用方式了~
|
||||
SampleConfig.ENABLED.set(false);
|
||||
System.out.println("Your name is " + SampleConfig.NAME.getNotNull() + " !");
|
||||
System.out.println("Your name is " + SampleConfig.INFO.NAME.getNotNull() + " !");
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
```yaml
|
||||
# Configurations for sample
|
||||
|
||||
# Enabled?
|
||||
enabled: true
|
||||
|
||||
info:
|
||||
# Configure your name!
|
||||
name: Joker
|
||||
age: 24
|
||||
```
|
||||
|
||||
### 依赖方式
|
||||
|
||||
#### Maven 依赖
|
||||
|
@ -11,10 +11,17 @@ public class Sample {
|
||||
|
||||
@HeaderComment("Configurations for sample")
|
||||
interface SampleConfig extends Configuration {
|
||||
@HeaderComment("Configure your name!") // Header comment
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
|
||||
@InlineComment("Enabled?") // Inline comment
|
||||
ConfiguredValue<Boolean> ENABLED = ConfiguredValue.of(true);
|
||||
|
||||
interface INFO extends Configuration {
|
||||
@HeaderComment("Configure your name!") // Header comment
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
|
||||
ConfiguredValue<Integer> AGE = ConfiguredValue.of(24);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -24,7 +31,7 @@ public class Sample {
|
||||
provider.initialize(SampleConfig.class);
|
||||
// 3. Enjoy using the configuration!
|
||||
SampleConfig.ENABLED.set(false);
|
||||
System.out.println("Your name is " + SampleConfig.NAME.getNotNull() + " !");
|
||||
System.out.println("Your name is " + SampleConfig.INFO.NAME.getNotNull() + " !");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user