Interface LoaderOptionSource
-
public interface LoaderOptionSource
A provider forConfigurationLoaderoptions.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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static LoaderOptionSourcecomposite(LoaderOptionSource... sources)Create an option source that will try the provided sources in order.static LoaderOptionSourceenvironmentVariables()Retrieve loader options from environment variables.static LoaderOptionSourceenvironmentVariables(java.lang.String prefix)Retrieve loader options from environment variables.@Nullable java.lang.Stringget(java.lang.String... path)Get the value at the provided path.default booleangetBoolean(boolean defaultValue, java.lang.String... path)Get the value at the provided path as a boolean.default doublegetDouble(double defaultValue, java.lang.String... path)Get the value at the provided path as a double.default <T extends java.lang.Enum<T>>
@Nullable TgetEnum(java.lang.Class<T> enumClazz, java.lang.String... path)Get the value at the provided path as an enum constant.default <T extends java.lang.Enum<T>>
TgetEnum(java.lang.Class<T> enumClazz, T defaultValue, java.lang.String... path)Get the value at the provided path as an enum constant.default intgetInt(int defaultValue, java.lang.String... path)Get the value at the provided path as an integer.default java.lang.StringgetOr(java.lang.String defaultValue, java.lang.String... path)Get the value at the provided path.static LoaderOptionSourcenode(ConfigurationNode node)Create an option source that will read from an existing configuration node.static LoaderOptionSourcesystemProperties()Retrieve loader options from system properties.static LoaderOptionSourcesystemProperties(java.lang.String prefix)Retrieve loader options from system properties.
-
-
-
Method Detail
-
environmentVariables
static LoaderOptionSource 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
static LoaderOptionSource environmentVariables(java.lang.String prefix)
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
static LoaderOptionSource 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
static LoaderOptionSource systemProperties(java.lang.String prefix)
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
static LoaderOptionSource node(ConfigurationNode 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
static LoaderOptionSource composite(LoaderOptionSource... sources)
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
@Nullable java.lang.String get(java.lang.String... path)
Get the value at the provided path.- Parameters:
path- the path for options.- Returns:
- a value, or
nullif none is present - Throws:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getOr
default java.lang.String getOr(java.lang.String defaultValue, java.lang.String... path)
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:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getEnum
default <T extends java.lang.Enum<T>> @Nullable T getEnum(java.lang.Class<T> enumClazz, java.lang.String... path)
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:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getEnum
default <T extends java.lang.Enum<T>> T getEnum(java.lang.Class<T> enumClazz, T defaultValue, java.lang.String... path)
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:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getInt
default int getInt(int defaultValue, java.lang.String... path)
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:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getDouble
default double getDouble(double defaultValue, java.lang.String... path)
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:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
getBoolean
default boolean getBoolean(boolean defaultValue, java.lang.String... path)
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:
java.lang.IllegalArgumentException- if the provided path is an empty array- Since:
- 4.2.0
-
-