Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit ac99e33

Browse files
authored
[R] Add example code
1 parent 17aa49b commit ac99e33

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

documentation/README.en-us.md

+61-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<h5 align="center">
99
<a href="#basics">Basic Info</a>&nbsp;&nbsp;
1010
<a href="#maven">Maven Import</a>&nbsp;&nbsp;
11-
<a href="#development">Development</a>&nbsp;&nbsp;
11+
<a href="#usage">Usage</a>&nbsp;&nbsp;
1212
<a href="#license">License</a>
1313
</h5>
1414
<br>
@@ -55,3 +55,63 @@ Then you can add this library as dependency:
5555
```
5656

5757
Make sure you reimport if you're using IntelliJ IDEA!
58+
59+
<br>
60+
61+
<a name="usage"></a>
62+
Usage:
63+
--------
64+
65+
#### 1. Create a HyConfig Object:
66+
67+
```java
68+
// Pass in only the java.io.File object that stores the config file path.
69+
// This will load automatically after the object is initialized.
70+
// Read only will be enabled by default, use config.setEnableWrite(true); to enable write.
71+
HyConfig config = new HyConfig(new File("./config.yml"));
72+
```
73+
74+
#### 2. Use it:
75+
76+
```yml
77+
# Example YML:
78+
Test:
79+
TestString: StringValue1
80+
TestInt: 2
81+
TestDouble: 3.5
82+
TestStringList:
83+
- hi
84+
- there
85+
```
86+
87+
```java
88+
// Code to read Example YML
89+
90+
// Read Config
91+
// Comment before each variable represents their value.
92+
93+
// "StringValue1"
94+
String testString = config.getString("Test.TestString");
95+
96+
// 2
97+
int testInt = config.getInt("Test.TestInt");
98+
99+
// ["hi", "there"]
100+
List<String> testList = config.getStringList("Test.TestStringList");
101+
102+
// ["TestString", "TestInt", "TestDouble", "TestStringList"]
103+
ArrayList<String> keysUnderTest = config.getKeys("Test");
104+
105+
106+
// Write Config
107+
// Set value requires enableWrite to be true, if not, calling save() won't do anything.
108+
// All comments will be removed when saving.
109+
config.setEnableWrite(true);
110+
config.set("Test.TestSetString", "TestValue");
111+
config.save();
112+
113+
114+
// Enable Auto Backup
115+
// This will take up a lot of space because it creates a new backup every time save() is called.
116+
config.setBackupDir(new File("./backups/"));
117+
```

0 commit comments

Comments
 (0)