Package me.a8kj.config
Class YamlSource
- All Implemented Interfaces:
CreatableConfig<String>,CRUDOperations<String>,DeletableConfig<String>,ReadableConfig<String>,UpdatableConfig<String>
- Direct Known Subclasses:
AutoReadYamlSource
A robust YAML implementation of
BaseConfig that supports hierarchical
data structures and persistent merging.
This class handles the conversion between flat in-memory data (used for easy access) and nested YAML structures (used for human-readable files). It implements a "Read-Modify-Write" pattern to ensure that existing data in the file is preserved unless explicitly overwritten by the application.
* @author a8kj7sea- Since:
- 0.3
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes the YAML source with standard block-style formatting. -
Method Summary
Methods inherited from class me.a8kj.config.file.BaseConfig
create, delete, getReader, getWriter, onPostCreate, onPostDelete, onPreCreate, onPreDelete
-
Constructor Details
-
YamlSource
public YamlSource()Initializes the YAML source with standard block-style formatting. Block style is used to ensure the generated YAML is clean and easy for users to edit.
-
-
Method Details
-
read
Reads the YAML file from disk and flattens it into the configuration memory. Existing memory data is cleared before loading to ensure state consistency with the disk.- Specified by:
readin interfaceReadableConfig<String>- Specified by:
readin classBaseConfig<String>- Returns:
- A
ConfigOperationrepresenting the read process.
-
update
Synchronizes the in-memory data with the physical file using a merge strategy.Logic flow: 1. Load the current file content into a temporary map. 2. Unflatten the in-memory storage into a nested map structure. 3. Merge the memory structure into the file structure (memory takes precedence). 4. Save the combined structure back to the disk.
- Specified by:
updatein interfaceUpdatableConfig<String>- Specified by:
updatein classBaseConfig<String>- Returns:
- A
ConfigOperationrepresenting the update and merge process.
-