public final class SettingsManager extends Object
XmlUtils class) or SettingsGroup file location changes should be done
before requesting any of the settings, preferably right at the application startup. Otherwise data might not be properly read and
settings will appear empty.XmlUtils| Constructor and Description |
|---|
SettingsManager() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addSettingsListener(SettingsListener listener)
Adds new global
SettingsListener. |
static void |
addSettingsListener(String key,
SettingsListener listener)
Adds new specific
SettingsListener. |
static void |
addSettingsListener(String group,
String key,
SettingsListener listener)
Adds new specific
SettingsListener. |
static void |
disableSave()
Disables saving settings into files.
|
static void |
enableSave()
Enables saving settings into files.
|
static <T> T |
get(String key)
Returns stored settings.
|
static <T> T |
get(String group,
String key,
Supplier<T> defaultValueSupplier)
Returns stored settings.
|
static <T> T |
get(String group,
String key,
T defaultValue)
Returns stored settings.
|
static <T> T |
get(String key,
Supplier<T> defaultValueSupplier)
Returns stored settings.
|
static <T> T |
get(String key,
T defaultValue)
Returns stored settings.
|
static String |
getBackupFilesExtension()
Returns backup files extension.
|
static String |
getDefaultSettingsDir()
Returns default settings directory.
|
static String |
getDefaultSettingsDirName()
Returns default settings directory name.
|
static String |
getDefaultSettingsGroup()
Returns default
SettingsGroup name. |
static String |
getGroupFilePath(String group)
Returns directory where settings group file is saved.
|
static List<SettingsGroup> |
getLoadedGroups()
Returns list of all loaded settings groups.
|
static Map<String,SettingsGroup> |
getLoadedGroupsMap()
Returns map of all loaded settings groups.
|
static long |
getSaveOnChangeDelay()
Returns save-on-change delay in milliseconds.
|
static Object |
getSettings(String fileName)
Returns value read from the settings file.
|
static <T> T |
getSettings(String fileName,
Supplier<T> defaultValue)
Returns value read from the settings file.
|
static <T> T |
getSettings(String fileName,
T defaultValue)
Returns value read from the settings file.
|
static String |
getSettingsFilesExtension()
Returns settings files extension.
|
static SettingsGroup |
getSettingsGroup(String group)
Returns settings group for the specified name.
|
SettingsGroupState |
getSettingsGroupState(String group)
Returns
SettingsGroupState for the SettingsGroup with the specified name. |
static void |
initialize()
Initializes
SettingsManager. |
static boolean |
isAllowSave()
Returns whether should allow saving settings into files or not.
|
static boolean |
isSaveDefaultValues()
Sets whether or not should save default value created as a result of
get(...) calls. |
static boolean |
isSaveLoggingEnabled()
Returns whether settings save log is enabled or not.
|
static boolean |
isSaveOnChange()
Returns whether should save settings right after any changes made or not.
|
static void |
removeSettingsListener(SettingsListener listener)
Removes global
SettingsListener. |
static void |
removeSettingsListener(String key,
SettingsListener listener)
Removes specific
SettingsListener. |
static void |
removeSettingsListener(String group,
String key,
SettingsListener listener)
Removes specific
SettingsListener. |
static void |
resetDefaultGroup()
Resets all settings within the default settings group.
|
static void |
resetGroup(String group)
Resets all settings within the specified settings group.
|
static <T> T |
resetValue(String key)
Resets settings under the key within the default settings group.
|
static <T> T |
resetValue(String group,
String key)
Resets settings under the key within the specified settings group.
|
static void |
saveSettings()
Saves all
SettingsGroups and settings files. |
static void |
saveSettingsGroup(SettingsGroup settingsGroup)
Saves specified
SettingsGroup. |
static void |
saveSettingsGroup(String group)
Saves
SettingsGroup with the specified name. |
static <T> T |
set(String group,
String key,
T object)
Sets value for the specified settings group and key.
|
static <T> T |
set(String key,
T object)
Sets value for the specified settings key.
|
static void |
setAllowSave(boolean allowSave)
Sets whether should allow saving settings into files or not.
|
static void |
setBackupFilesExtension(String backupFilesExtension)
Sets backup files extension
|
static void |
setDefaultSettingsDir(String defaultSettingsDir)
Sets default settings directory.
|
static void |
setDefaultSettingsDirName(String defaultSettingsDir)
Sets default settings directory name.
|
static void |
setDefaultSettingsGroup(String defaultSettingsGroup)
Sets default
SettingsGroup name. |
static void |
setGroupFilePath(String group,
String dir)
Sets custom directory where settings group file will be saved.
|
static void |
setSaveDefaultValues(boolean saveDefaultValues)
Sets whether or not should save default value created as a result of
get(...) calls. |
static void |
setSaveLoggingEnabled(boolean enabled)
Sets whether settings save log is enabled or not.
|
static void |
setSaveOnChange(boolean saveOnChange)
Sets whether should save settings right after any changes made or not.
|
static void |
setSaveOnChangeDelay(long saveOnChangeDelay)
Sets save-on-change delay in milliseconds.
|
static void |
setSettings(String fileName,
Object settings)
Sets and saves value into settings file with the specified name.
|
static void |
setSettingsFilesExtension(String settingsFilesExtension)
Sets settings files extension
|
static boolean |
settingsExists(String fileName)
Returns whether settings file with the specified name exists or not.
|
public static void initialize()
SettingsManager.public static List<SettingsGroup> getLoadedGroups()
public static Map<String,SettingsGroup> getLoadedGroupsMap()
public static <T> T get(String key)
ClassCastException.
Whenever a ClassCastException there will be a warning logged and default value will be used.T - settings typekey - settings keypublic static <T> T get(String key, T defaultValue)
ClassCastException.
Whenever a ClassCastException there will be a warning logged and default value will be used.T - settings typekey - settings keydefaultValue - default valuepublic static <T> T get(String key, Supplier<T> defaultValueSupplier)
ClassCastException.
Whenever a ClassCastException there will be a warning logged and default value will be used.T - settings typekey - settings keydefaultValueSupplier - Supplier for default valuepublic static <T> T get(String group, String key, T defaultValue)
ClassCastException.
Whenever a ClassCastException there will be a warning logged and default value will be used.T - settings typegroup - settings groupkey - settings keydefaultValue - default valuepublic static <T> T get(String group, String key, Supplier<T> defaultValueSupplier)
ClassCastException.
Whenever a ClassCastException there will be a warning logged and default value will be used.T - settings typegroup - settings groupkey - settings keydefaultValueSupplier - Supplier for default valuepublic static <T> T set(String key, T object)
T - new value typekey - settings keyobject - new valuepublic static <T> T set(String group, String key, T object)
T - new value typegroup - settings groupkey - settings keyobject - new valuepublic static void resetDefaultGroup()
public static void resetGroup(String group)
group - settings grouppublic static <T> T resetValue(String key)
T - value typekey - settings key to resetpublic static <T> T resetValue(String group, String key)
T - value typegroup - settings groupkey - settings key to resetpublic static SettingsGroup getSettingsGroup(String group)
group - settings group namepublic static void saveSettings()
SettingsGroups and settings files.public static void saveSettingsGroup(String group)
SettingsGroup with the specified name.group - name of the SettingsGroup to savepublic static void saveSettingsGroup(SettingsGroup settingsGroup)
SettingsGroup.settingsGroup - SettingsGroup to savepublic SettingsGroupState getSettingsGroupState(String group)
SettingsGroupState for the SettingsGroup with the specified name.group - SettingsGroup name to retrieve SettingsGroupState forSettingsGroupState for the SettingsGroup with the specified namepublic static Object getSettings(String fileName)
fileName - settings file namepublic static <T> T getSettings(String fileName, T defaultValue)
T - default value typefileName - settings file namedefaultValue - default valuepublic static <T> T getSettings(String fileName, Supplier<T> defaultValue)
T - default value typefileName - settings file namedefaultValue - default value supplierpublic static void setSettings(String fileName, Object settings)
fileName - settings file namesettings - valuepublic static boolean settingsExists(String fileName)
fileName - settings file nametrue if settings file with the specified name exists, false otherwisepublic static String getSettingsFilesExtension()
public static void setSettingsFilesExtension(String settingsFilesExtension)
settingsFilesExtension - new settings files extensionpublic static String getBackupFilesExtension()
public static void setBackupFilesExtension(String backupFilesExtension)
backupFilesExtension - new backup files extensionpublic static String getDefaultSettingsDir()
public static void setDefaultSettingsDir(String defaultSettingsDir)
defaultSettingsDir - new default settings directorypublic static String getDefaultSettingsDirName()
public static void setDefaultSettingsDirName(String defaultSettingsDir)
defaultSettingsDir - new default settings directory namepublic static String getDefaultSettingsGroup()
SettingsGroup name.SettingsGroup namepublic static void setDefaultSettingsGroup(String defaultSettingsGroup)
SettingsGroup name.defaultSettingsGroup - new default SettingsGroup namepublic static void setGroupFilePath(String group, String dir)
group - settings group namedir - settings group file directorypublic static String getGroupFilePath(String group)
group - settings group namepublic static boolean isSaveOnChange()
true if should save settings right after any changes made, false otherwisepublic static void setSaveOnChange(boolean saveOnChange)
saveOnChange - whether should save settings right after any changes made or notpublic static boolean isSaveDefaultValues()
get(...) calls.true if should save default value created as a result of get(...) calls, false otherwisepublic static void setSaveDefaultValues(boolean saveDefaultValues)
get(...) calls.saveDefaultValues - whether or not should save default value created as a result of get(...) callspublic static long getSaveOnChangeDelay()
public static void setSaveOnChangeDelay(long saveOnChangeDelay)
saveOnChangeDelay - new save-on-change delay in millisecondspublic static boolean isSaveLoggingEnabled()
true if settings save log is enabled, false otherwisepublic static void setSaveLoggingEnabled(boolean enabled)
enabled - whether settings save log is enabled or notpublic static boolean isAllowSave()
true if should allow saving settings into files, false otherwisepublic static void setAllowSave(boolean allowSave)
allowSave - whether should allow saving settings into files or notpublic static void disableSave()
public static void enableSave()
public static void addSettingsListener(SettingsListener listener)
SettingsListener.listener - SettingsListener to addpublic static void addSettingsListener(String key, SettingsListener listener)
SettingsListener.key - settings key to listen tolistener - SettingsListener to addpublic static void addSettingsListener(String group, String key, SettingsListener listener)
SettingsListener.group - name of the SettingsGroup to add SettingsListener forkey - settings key to listen tolistener - SettingsListener to addpublic static void removeSettingsListener(SettingsListener listener)
SettingsListener.listener - SettingsListener to removepublic static void removeSettingsListener(String key, SettingsListener listener)
SettingsListener.key - listened settings keylistener - SettingsListener to removepublic static void removeSettingsListener(String group, String key, SettingsListener listener)
SettingsListener.group - name of the SettingsGroup to remove SettingsListener fromkey - listened settings keylistener - SettingsListener to removeCopyright © 2020. All rights reserved.