YamlConfig
| Type | 🔵 Class |
| Package | io.github.mrtesz.teszcore.config |
| GitHub | YamlConfig.java |
| Implements | Copyable<YamlConfig> |
| Subclasses | YamlConfig.Builder |
Description
A class for managing YAML files
Building
Build a new YamlConfig by building a new YamlConfig.Builder instance and executing YamlConfig.Builder#build()
Methods
builder
static YamlConfig.Builder builder();
Generate a YamlConfig Builder
Returns: YamlConfig.Builder — A new Builder
load
void load();
Creates the file or directory if not existent and loads the data of the YAML file
Throws: YamlConfigException when an I/O error occurs
save
void save();
void save(Charset cs);
Saves the current data to the YAML file
| Parameter | Type | Annotations | Description |
|---|---|---|---|
cs | <abbr title=java.nio.charset.Charset>Charset</abbr> | @NotNull | (optional) cs of OutputStreamWriter(OutputStream, Charset) Default: StandardCharsets.UTF_8 |
Throws: YamlConfigException when an I/O error occurs
addDefault
void addDefault(String path, Object value);
Add a new entry to the defaults map
| Parameter | Type | Annotations | Description |
|---|---|---|---|
path | String | @NotNull | Path |
value | Object | - | Value |
setDefault
void setDefault(String path, Object value);
Saves a value to the YAML file if the path is empty
| Parameter | Type | Annotations | Description |
|---|---|---|---|
path | String | @NotNull | Path |
value | Object | - | Value |
set
void set(@NotNull String path, Object value);
Sets a value in the YAML file
| Parameter | Type | Annotations | Description |
|---|---|---|---|
path | String | @NotNull | Path |
value | Object | @Nullable | Value |
contains
boolean contains(@NotNull String path);
See if a path contains a value
| Parameter | Type | Annotations | Description |
|---|---|---|---|
path | String | @NotNull | Path |
Returns: boolean — true if the path contains a value
exists
boolean exists();
See if the YAML file exists
Returns: boolean — true if the YAML file exists
getRaw
Map<String, Object> getRaw();
Get the raw data of the YAML
Returns: Map<String, Object> — raw data of the YAML
setData
void setData(Map<String, Object> data);
Set the raw data (does not save automatically)
getAllPaths
public Set<String> getAllPaths();
Collect all paths of the YAML
Returns: Set<String> — all paths in the config (e.g. database.host, database.port)
getPaths
Set<String> getPaths(@NotNull String parent);
Return all paths under the given parent path
| Parameter | Type | Annotations | Description |
|---|---|---|---|
parent | String | @NotNull | Path to the parent section (e.g. database) |
Returns: Set<String> — all paths under the given parent path (e.g. database.host, database.port), or empty if the path does not exist or is not a section
copy
implemented from Copyable
T: YamlConfig
YAML Methods
| Parameter | Annotations | Description |
|---|---|---|
path | @NotNull | Path |
def | - | (optional) Default value, when no value is found |
| Method | Returns |
|---|---|
get(path) | Object value at path, or null if not found |
getString(path) | String value at path, or null if not found |
getString(path, def) | String value at path, or def if not found |
getInt(path) | int value at path, or 0 if not found or not a Number |
getInt(path, def) | int value at path, or def if not found or not a Number |
getIntOrNull(path) | Integer value at path, or null if not found or not a Number |
getLong(path) | long value at path, or 0 if not found or not a Number |
getLong(path, def) | long value at path, or def if not found or not a Number |
getLongOrNull(path) | Long value at path, or null if not found or not a Number |
getFloat(path) | float value at path, or 0 if not found or not a Number |
getFloat(path, def) | float value at path, or def if not found or not a Number |
getFloatOrNull(path) | Float value at path, or null if not found or not a Number |
getShort(path) | short value at path, or 0 if not found or not a Number |
getShort(path, def) | short value at path, or def if not found or not a Number |
getShortOrNull(path) | Short value at path, or null if not found or not a Number |
getDouble(path) | double value at path, or 0 if not found or not a Number |
getDouble(path, def) | double value at path, or def if not found or not a Number |
getDoubleOrNull(path) | Double value at path, or null if not found or not a Number |
getBoolean(path) | boolean value at path, or false if not found or not a Boolean |
getBoolean(path, def) | boolean value at path, or def if not found or not a Boolean |
getBooleanOrNull(path) | Boolean value at path, or null if not found or not a Boolean |
getStringList(path) | List<String> at path, or empty if not found or not a List |
getStringList(path, def) | List<String> at path, or def if not found or not a List |
getStringList(path) | List<String> at path, or null if not found or not a List |