From ac99e33e48173458e6d748c17057047b6e18858c Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Thu, 4 Oct 2018 18:41:08 -0400 Subject: [PATCH] [R] Add example code --- documentation/README.en-us.md | 62 ++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/documentation/README.en-us.md b/documentation/README.en-us.md index 5147ae4..a0f3c10 100644 --- a/documentation/README.en-us.md +++ b/documentation/README.en-us.md @@ -8,7 +8,7 @@
Basic Info   Maven Import   -Development   +Usage   License

@@ -55,3 +55,63 @@ Then you can add this library as dependency: ``` Make sure you reimport if you're using IntelliJ IDEA! + +
+ + +Usage: +-------- + +#### 1. Create a HyConfig Object: + +```java +// Pass in only the java.io.File object that stores the config file path. +// This will load automatically after the object is initialized. +// Read only will be enabled by default, use config.setEnableWrite(true); to enable write. +HyConfig config = new HyConfig(new File("./config.yml")); +``` + +#### 2. Use it: + +```yml +# Example YML: +Test: + TestString: StringValue1 + TestInt: 2 + TestDouble: 3.5 + TestStringList: + - hi + - there +``` + +```java +// Code to read Example YML + +// Read Config +// Comment before each variable represents their value. + +// "StringValue1" +String testString = config.getString("Test.TestString"); + +// 2 +int testInt = config.getInt("Test.TestInt"); + +// ["hi", "there"] +List testList = config.getStringList("Test.TestStringList"); + +// ["TestString", "TestInt", "TestDouble", "TestStringList"] +ArrayList keysUnderTest = config.getKeys("Test"); + + +// Write Config +// Set value requires enableWrite to be true, if not, calling save() won't do anything. +// All comments will be removed when saving. +config.setEnableWrite(true); +config.set("Test.TestSetString", "TestValue"); +config.save(); + + +// Enable Auto Backup +// This will take up a lot of space because it creates a new backup every time save() is called. +config.setBackupDir(new File("./backups/")); +```