-
- 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 String
getPath()
Get the path to the config file. File
getFile()
Get the config file as an File object. Config
getDefaultConfig()
Get the default config object. boolean
checkIfExists()
Check if the config file is already existing. boolean
delete()
Delete the file. void
saveDefaultConfig()
Save the default config in the config file. Config
loadConfig()
Load the config. void
storeConfig(Config config)
Save the config object as an JSON string in the config file. static String
getUserConfigFolder()
Get an path to an folder where you can store user configurations. static String
getUserConfigFolder(String projectName)
Get an path to an folder where you can store user configurations. static String
getSystemConfigFolder(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.
-
-
-
-