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 LoaderOptionSource
composite
(LoaderOptionSource... sources) Create an option source that will try the provided sources in order.static LoaderOptionSource
Retrieve loader options from environment variables.static LoaderOptionSource
environmentVariables
(String prefix) Retrieve loader options from environment variables.@Nullable String
Get the value at the provided path.default boolean
getBoolean
(boolean defaultValue, String... path) Get the value at the provided path as a boolean.default double
Get 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 int
Get the value at the provided path as an integer.default String
Get the value at the provided path.static LoaderOptionSource
node
(ConfigurationNode node) Create an option source that will read from an existing configuration node.static LoaderOptionSource
Retrieve loader options from system properties.static LoaderOptionSource
systemProperties
(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
null
if 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,
defaultValue
will be returned.- Parameters:
path
- the path for options.defaultValue
- the value to return if none is present- Returns:
- a value, or
defaultValue
if 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
null
if 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,
defaultValue
will 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
defaultValue
if 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,
defaultValue
will be returned.- Parameters:
path
- the path for options.defaultValue
- the value to return if none is available- Returns:
- a value, or
defaultValue
if 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,
defaultValue
will be returned.- Parameters:
path
- the path for options.defaultValue
- the value to return if none is available- Returns:
- a value, or
defaultValue
if 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,
defaultValue
will be returned.- Parameters:
path
- the path for options.defaultValue
- the value to return if none is available- Returns:
- a value, or
defaultValue
if none is present - Throws:
IllegalArgumentException
- if the provided path is an empty array- Since:
- 4.2.0
-