public class YamlFileResource extends Object implements PropertyResource
| Constructor and Description |
|---|
YamlFileResource(File file)
Constructor.
|
YamlFileResource(File file,
PropertyReader reader,
LeafPropertiesGenerator leafPropertiesGenerator)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(String path)
Returns whether a value is present for the given path.
|
protected List<Property<?>> |
convertPropertiesToExportableTypes(List<Property<?>> originalList)
Converts the property entries to exportable "leaf" properties.
|
void |
exportProperties(ConfigurationData configurationData)
Exports the properties (e.g.
|
Boolean |
getBoolean(String path)
Returns the value of the given path as a boolean if available.
|
Double |
getDouble(String path)
Returns the value of the given path as a double if available.
|
Integer |
getInt(String path)
Returns the value of the given path as an integer if available.
|
List<?> |
getList(String path)
Returns the value of the given path as a list if available.
|
Object |
getObject(String path)
Returns the object at the given path, or null if absent.
|
protected org.yaml.snakeyaml.Yaml |
getSimpleYaml()
Returns a YAML instance set to export values with the default style.
|
protected org.yaml.snakeyaml.Yaml |
getSingleQuoteYaml()
Returns a YAML instance set to export values with single quotes.
|
String |
getString(String path)
Returns the value of the given path as a String if available.
|
void |
reload()
Reloads the configuration, e.g.
|
void |
setValue(String path,
Object value)
Sets the value for the given path.
|
protected String |
transformValue(Property<?> property,
Object value)
Returns the YAML representation for the given value (belonging to the given value).
|
public YamlFileResource(File file)
file - the config filepublic YamlFileResource(File file, PropertyReader reader, LeafPropertiesGenerator leafPropertiesGenerator)
file - the config file (the YAML file to which properties get exported)reader - the reader from which the properties' values are readleafPropertiesGenerator - generator of property entries to export bean properties. Can be null
only if you do not use bean properties.public Object getObject(String path)
PropertyResourcegetObject in interface PropertyResourcepath - the path to retrieve the value forpublic String getString(String path)
PropertyResourcegetString in interface PropertyResourcepath - the path to retrieve a String forpublic Integer getInt(String path)
PropertyResourcegetInt in interface PropertyResourcepath - the path to retrieve an integer forpublic Double getDouble(String path)
PropertyResourcegetDouble in interface PropertyResourcepath - the path to retrieve a double forpublic Boolean getBoolean(String path)
PropertyResourcegetBoolean in interface PropertyResourcepath - the path to retrieve a boolean forpublic List<?> getList(String path)
PropertyResourcegetList in interface PropertyResourcepath - the path to retrieve a list forpublic boolean contains(String path)
PropertyResourceProperty.isPresent(PropertyResource) should be favored over
calling this method as it may make more type-aware checks. This method simply returns whether some value
exists under the given path.contains in interface PropertyResourcepath - the path to checkpublic void setValue(String path, Object value)
PropertyResourcePropertyResource.exportProperties(ConfigurationData) has been called.setValue in interface PropertyResourcepath - the path to set a new value forvalue - the value to setpublic void reload()
PropertyResourcereload in interface PropertyResourcepublic void exportProperties(ConfigurationData configurationData)
PropertyResourceexportProperties in interface PropertyResourceconfigurationData - the configuration dataprotected List<Property<?>> convertPropertiesToExportableTypes(List<Property<?>> originalList)
Properties of type BeanProperty are converted to multiple Property objects
that reflect all concrete values that need to be stored to properly, losslessly export the bean.
The property entries are essentially the "leaf nodes" of the bean if viewed as a tree.
OptionalProperty instances are skipped if they evaluate to an empty value; otherwise,
the Optional interface is stripped and the underlying property is used in the export.
originalList - the list of property entries to convertprotected String transformValue(@Nullable Property<?> property, Object value)
property - the associated propertyvalue - the value to transform as YAMLprotected org.yaml.snakeyaml.Yaml getSimpleYaml()
protected org.yaml.snakeyaml.Yaml getSingleQuoteYaml()
Copyright © 2016–2018 The AuthMe Team. All rights reserved.