Package me.a8kj.config.file
Class BaseConfig<K>
java.lang.Object
me.a8kj.config.file.BaseConfig<K>
- Type Parameters:
K- The type of data keys used in the configuration.
- All Implemented Interfaces:
CreatableConfig<K>,CRUDOperations<K>,DeletableConfig<K>,ReadableConfig<K>,UpdatableConfig<K>
- Direct Known Subclasses:
BasicVelocityConfig,BukkitConfig,YamlSource
An abstract base implementation of
CRUDOperations providing core file management logic.
This class serves as the foundation for all configuration formats (YAML, JSON, etc.). It handles the physical file lifecycle on the disk, including creation, resource extraction, and deletion, while providing non-mandatory lifecycle hooks for extended logic.
- Since:
- 0.1
- Author:
- a8kj7sea
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates aConfigOperationfor initializing the configuration file.delete()Creates aConfigOperationfor deleting the file and clearing memory.protected ReaderProvides aReaderconfigured withUTF-8encoding.protected WriterProvides aWriterconfigured withUTF-8encoding.protected voidonPostCreate(ConfigFile<K> config) Optional hook triggered after the configuration file has been successfully written to disk, either from a resource or as a new empty file.protected voidonPostDelete(ConfigFile<K> config) Optional hook triggered after the configuration file and its memory buffer have been successfully cleared and removed.protected voidonPreCreate(ConfigFile<K> config) Optional hook triggered immediately before the configuration file is created.protected voidonPreDelete(ConfigFile<K> config) Optional hook triggered immediately before the configuration file is deleted from disk.abstract ConfigOperation<K> read()Provides the operation logic for reading the configuration data.abstract ConfigOperation<K> update()Provides the operation logic for updating (saving) the configuration data.
-
Constructor Details
-
BaseConfig
public BaseConfig()
-
-
Method Details
-
onPreCreate
Optional hook triggered immediately before the configuration file is created. * @param config The configuration file instance to be created. -
onPostCreate
Optional hook triggered after the configuration file has been successfully written to disk, either from a resource or as a new empty file. * @param config The created configuration file instance. -
onPreDelete
Optional hook triggered immediately before the configuration file is deleted from disk. * @param config The configuration file instance to be deleted. -
onPostDelete
Optional hook triggered after the configuration file and its memory buffer have been successfully cleared and removed. * @param config The deleted configuration file instance. -
create
Creates aConfigOperationfor initializing the configuration file.The process includes pre-hook execution, parent directory validation, resource extraction, and post-hook execution upon success.
- Specified by:
createin interfaceCreatableConfig<K>- Returns:
- A
ConfigOperationfor file creation and resource mapping.
-
getReader
Provides aReaderconfigured withUTF-8encoding.- Parameters:
file- The file to read from.- Returns:
- A UTF-8 encoded
Reader. - Throws:
IOException- If the file is inaccessible.
-
getWriter
Provides aWriterconfigured withUTF-8encoding.- Parameters:
file- The file to write to.- Returns:
- A UTF-8 encoded
Writer. - Throws:
IOException- If the file cannot be opened for writing.
-
delete
Creates aConfigOperationfor deleting the file and clearing memory.Includes pre/post hooks to allow for cleanup logic or event dispatching.
- Specified by:
deletein interfaceDeletableConfig<K>- Returns:
- A
ConfigOperationfor file deletion and memory cleanup.
-
read
Description copied from interface:ReadableConfigProvides the operation logic for reading the configuration data. This typically involves deserializing the file (e.g., YAML, JSON, Properties) and populating theDataMemory.- Specified by:
readin interfaceReadableConfig<K>- Returns:
- a
ConfigOperationrepresenting the reading/loading process.
-
update
Description copied from interface:UpdatableConfigProvides the operation logic for updating (saving) the configuration data. This typically involves taking the current state fromDataMemoryand writing it to the file, ensuring all changes are synchronized.- Specified by:
updatein interfaceUpdatableConfig<K>- Returns:
- a
ConfigOperationrepresenting the updating/saving process.
-