-
Notifications
You must be signed in to change notification settings - Fork 25
Usage
Leonhard edited this page Jul 5, 2022
·
12 revisions
The usage is generic for every FileType.
You can either use the internal constructors of the FileTypes or the LightningBuilder
Valid constructors (For all FileTypes) are:
new FILETYPE-HERE(FILE)
new FILETYPE-HERE(NAME, PATH)
new FILETYPE-HERE(FILETYPE) //Copy-constructor
new FILETYPE-HERE(NAME, PATH, INPUTSTREAM)
Yaml yaml = new Yaml("Name", "Path");
Config config = new Config("Name", "Path"); //Special version of YAML
Json json = new Json("Name", "Path");
Toml toml = new Toml("Name", "Path");
// Or using the LightningBuilder:
Config configUsingBuilder = SimplixBuilder
.fromFile(FILE-HERE)
.addInputStreamFromResource() //Optional
.setDataType()
.setReloadSettings()
.createConfig(); // Building
Object anObject = yaml.get("Key"); // Default: null
String aString = yaml.getString("Key"); // Default: ""
int anInt = yaml.getInt("Key"); // Default: 0
double aDouble = yaml.getDouble("Key"); // Default: 0.0
float aFloat = yaml.getFloat("Key"); // Default: 0.0
long aLong = yaml.getLong("Key"); // Default: 0.0
List<String> aStringList = yaml.getStringList("Key");// Default: ArrayList<String>()
TimeUnit anEnum = yaml.getEnum("Key", TimeUnit.class);//Throws an LightningValidation / IllegalStateException
yaml.set("Key", "Value");
yaml.setDefault("Key", "Default-Value"); // Will only be set if key is not yet present in file
Optional<String> optionalString = yaml.find("Key", String.class); // If a key is not present an empty optional will be returned
String getOrDefault = yaml.getOrDefault("Key", "Default-Value");
String getOrSetDefault = yaml.getOrSetDefault("Key", "Default-Value-To-Be-Set-If-Not-Yet-Present");
File file = yaml.getFile();
String name = yaml.getName();
yaml.clear();
2020-2022 - SimplixSoftworks