Interface LoaderOptionSource
ConfigurationLoader options.
This allows initializing a loader from sources like system properties, environment variables, or an existing configuration node.
To allow working with primitive value sources, only scalar values are supported.
- Since:
- 4.2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic LoaderOptionSourcecomposite(LoaderOptionSource... sources) Create an option source that will try the provided sources in order.static LoaderOptionSourceRetrieve loader options from environment variables.static LoaderOptionSourceenvironmentVariables(String prefix) Retrieve loader options from environment variables.@Nullable StringGet the value at the provided path.default booleangetBoolean(boolean defaultValue, String... path) Get the value at the provided path as a boolean.default doubleGet the value at the provided path as a double.default <T extends Enum<T>>
@Nullable TGet the value at the provided path as an enum constant.default <T extends Enum<T>>
TGet the value at the provided path as an enum constant.default intGet the value at the provided path as an integer.default StringGet the value at the provided path.static LoaderOptionSourcenode(ConfigurationNode node) Create an option source that will read from an existing configuration node.static LoaderOptionSourceRetrieve loader options from system properties.static LoaderOptionSourcesystemProperties(String prefix) Retrieve loader options from system properties.
-
Method Details
-
environmentVariables
Retrieve loader options from environment variables.When reading environment variables, property keys will be converted to upper case and joined by '
_' (an underscore).This source will use a default prefix of
CONFIGURATE.- Returns:
- a source retrieving options from environment variables
- Since:
- 4.2.0
-
environmentVariables
Retrieve loader options from environment variables.When reading environment variables, property keys will be converted to upper case and joined by '
_' (an underscore).- Parameters:
prefix- the prefix to prepend to option paths- Returns:
- a source retrieving options from environment variables
- Since:
- 4.2.0
-
systemProperties
Retrieve loader options from system properties.When reading system properties, property keys will be joined by '
.' (a dot).This source will use a default prefix of
configurate.- Returns:
- a source retrieving options from system properties
- Since:
- 4.2.0
-
systemProperties
Retrieve loader options from system properties.When reading system properties, property keys will be joined by '
.' (a dot).- Parameters:
prefix- the prefix to prepend to option paths- Returns:
- a source retrieving options from system properties
- Since:
- 4.2.0
-
node
Create an option source that will read from an existing configuration node.Option paths will be converted directly to node paths.
- Parameters:
node- the node to read options from- Returns:
- a source retrieving options from the provided node
- Since:
- 4.2.0
-
composite
Create an option source that will try the provided sources in order.The first source with a present value will be used.
- Parameters:
sources- the option sources to delegate to- Returns:
- a new option source
- Since:
- 4.2.0
-
get
Get the value at the provided path.- Parameters:
path- the path for options.- Returns:
- a value, or
nullif none is present - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getOr
Get the value at the provided path.If no value is present,
defaultValuewill be returned.- Parameters:
path- the path for options.defaultValue- the value to return if none is present- Returns:
- a value, or
defaultValueif none is present - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getEnum
Get the value at the provided path as an enum constant.- Type Parameters:
T- enum type- Parameters:
enumClazz- the enum type's classpath- the path for options.- Returns:
- a value, or
nullif none is present or the provided value is not a member of the enum - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getEnum
Get the value at the provided path as an enum constant.If no value is present or the provided value is not a known enum constant,
defaultValuewill be returned.- Type Parameters:
T- enum type- Parameters:
enumClazz- the enum type's classpath- the path for options.defaultValue- the value to return if none is present- Returns:
- a value, or
defaultValueif none is present - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getInt
Get the value at the provided path as an integer.If no value is present or the value is not a valid integer,
defaultValuewill be returned.- Parameters:
path- the path for options.defaultValue- the value to return if none is available- Returns:
- a value, or
defaultValueif none is present - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getDouble
Get the value at the provided path as a double.If no value is present or the value is not a valid double,
defaultValuewill be returned.- Parameters:
path- the path for options.defaultValue- the value to return if none is available- Returns:
- a value, or
defaultValueif none is present - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getBoolean
Get the value at the provided path as a boolean.If no value is present or the value is not a valid boolean,
defaultValuewill be returned.- Parameters:
path- the path for options.defaultValue- the value to return if none is available- Returns:
- a value, or
defaultValueif none is present - Throws:
IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-