public class SettingsManager extends Object
The settings manager unites a property resource,
a migration service and the list of known properties
(typically gathered from SettingsHolder classes).
The settings manager allows to look up and modify properties. Thus, the settings manager fulfills the most typical operations on a configuration in an application. After initializing the settings manager, it is usually the only class from ConfigMe you interact with.
PropertyResource,
MigrationService,
SettingsHolder| Modifier and Type | Field and Description |
|---|---|
protected ConfigurationData |
configurationData |
protected MigrationService |
migrationService |
protected PropertyResource |
resource |
| Constructor and Description |
|---|
SettingsManager(PropertyResource resource,
MigrationService migrationService,
Class<? extends SettingsHolder>... settingsClasses)
Constructor.
|
SettingsManager(PropertyResource resource,
MigrationService migrationService,
ConfigurationData configurationData)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static SettingsManager |
createWithProperties(PropertyResource resource,
MigrationService migrationService,
Collection<? extends Property<?>> properties)
Convenience method for creating a settings manager for the given collection of properties.
|
static SettingsManager |
createWithYamlFile(File yamlFile,
Class<? extends SettingsHolder>... settingsClasses)
Convenience method for creating a settings manager for the provided YAML file with defaults.
|
<T> T |
getProperty(Property<T> property)
Gets the given property from the configuration.
|
void |
reload()
Reloads the configuration.
|
void |
save()
Saves the config file.
|
<T> void |
setProperty(Property<T> property,
T value)
Sets a new value for the given property.
|
protected void |
validateAndLoadOptions()
Checks with the migration service if the configuration is up to date.
|
protected final ConfigurationData configurationData
protected final PropertyResource resource
protected final MigrationService migrationService
@SafeVarargs public SettingsManager(PropertyResource resource, @Nullable MigrationService migrationService, Class<? extends SettingsHolder>... settingsClasses)
resource - the property resource to read and write properties tomigrationService - migration service to check the property resource withsettingsClasses - classes whose Property fields make up all known propertiespublic SettingsManager(PropertyResource resource, @Nullable MigrationService migrationService, ConfigurationData configurationData)
resource - the property resource to read and write properties tomigrationService - migration service to check the property resource withconfigurationData - the configuration datapublic static SettingsManager createWithProperties(PropertyResource resource, @Nullable MigrationService migrationService, Collection<? extends Property<?>> properties)
resource - the property resource to read and write frommigrationService - migration service or null to skip migration checkproperties - the properties@SafeVarargs public static SettingsManager createWithYamlFile(File yamlFile, Class<? extends SettingsHolder>... settingsClasses)
yamlFile - the file to read from and write tosettingsClasses - classes whose Property fields make up all known propertiespublic <T> T getProperty(Property<T> property)
T - The property's typeproperty - The property to retrievepublic <T> void setProperty(Property<T> property, T value)
T - The property's typeproperty - The property to modifyvalue - The new value to assign to the propertypublic void reload()
public void save()
protected void validateAndLoadOptions()
Copyright © 2016–2018 The AuthMe Team. All rights reserved.