-
- All Implemented Interfaces:
public class ConfigHandler<Config>Config handler for easy managing of config files with the json format.
-
-
Constructor Summary
Constructors Constructor Description ConfigHandler(Config defaultConfig, String path)Create a config handler. ConfigHandler(Config defaultConfig, String path, Boolean writeDefaultConfigAutomatically)Create a config handler.
-
Method Summary
Modifier and Type Method Description StringgetPath()Get the path to the config file. FilegetFile()Get the config file as an File object. ConfiggetDefaultConfig()Get the default config object. booleancheckIfExists()Check if the config file is already existing. booleandelete()Delete the file. voidsaveDefaultConfig()Save the default config in the config file. ConfigloadConfig()Load the config. voidstoreConfig(Config config)Save the config object as an JSON string in the config file. static StringgetUserConfigFolder()Get an path to an folder where you can store user configurations. static StringgetUserConfigFolder(String projectName)Get an path to an folder where you can store user configurations. static StringgetSystemConfigFolder(String projectName)Get an path to an folder where you can store system wide configurations. -
-
Constructor Detail
-
ConfigHandler
ConfigHandler(Config defaultConfig, String path)
Create a config handler.- Parameters:
defaultConfig- The default config.path- The path to the file with the file name and extension.
-
ConfigHandler
ConfigHandler(Config defaultConfig, String path, Boolean writeDefaultConfigAutomatically)
Create a config handler.- Parameters:
defaultConfig- The default config.path- The path to the file with the file name and extension.writeDefaultConfigAutomatically- If true the default config will be written automatically if no config exists.
-
-
Method Detail
-
getDefaultConfig
Config getDefaultConfig()
Get the default config object.
-
checkIfExists
boolean checkIfExists()
Check if the config file is already existing.
-
delete
boolean delete()
Delete the file.
-
saveDefaultConfig
void saveDefaultConfig()
Save the default config in the config file. WARNING: this also overrides normal configs. You should check before this if the config exists.
-
loadConfig
Config loadConfig()
Load the config.
-
storeConfig
void storeConfig(Config config)
Save the config object as an JSON string in the config file.
- Parameters:
config- Config object to save.
-
getUserConfigFolder
static String getUserConfigFolder()
Get an path to an folder where you can store user configurations. This function is OS optimized for Windows, Linux and Mac.
-
getUserConfigFolder
static String getUserConfigFolder(String projectName)
Get an path to an folder where you can store user configurations. This function is OS optimized for Windows, Linux and Mac.
- Parameters:
projectName- The project name.
-
getSystemConfigFolder
static String getSystemConfigFolder(String projectName)
Get an path to an folder where you can store system wide configurations. This function is OS optimized for Windows, Linux and Mac.
- Parameters:
projectName- The project name.
-
-
-
-