java.lang.Object
io.jstach.kiwi.kvs.KeyValuesLoader.Builder
- All Implemented Interfaces:
KeyValuesLoader
- Enclosing interface:
KeyValuesLoader
A builder class for constructing instances of
KeyValuesLoader
. The builder
allows adding multiple sources from which key-values will be loaded, as well as
setting variables for interpolation. Note that the order of the "add" and
variables
methods does matter.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.jstach.kiwi.kvs.KeyValuesLoader
KeyValuesLoader.Builder
-
Method Summary
Modifier and TypeMethodDescriptionadd
(KeyValuesResource resource) Adds aKeyValuesResource
as a source to the loader.AddsVariables
for interpolation when loading key-values.Adds a URI specified as a string as a source to the loader.Adds a namedKeyValues
source to the loader.add
(String uri, Consumer<KeyValuesResource.Builder> builder) Add resource using callback on builder.Adds aURI
as a source by wrapping it in aKeyValuesResource
.build()
Builds and returns a newKeyValuesLoader
based on the current state of the builder.load()
Loads key-values using the current builder configuration.variables
(Function<KeyValuesEnvironment, Variables> variablesFactory) Adds variables that will be resolved based on the environment.
-
Method Details
-
add
Adds aKeyValuesResource
as a source to the loader.- Parameters:
resource
- the resource to add- Returns:
- this builder instance
-
add
Add resource using callback on builder.- Parameters:
uri
- uri of resourcebuilder
- builder to add additional properties.- Returns:
- this.
-
add
Adds a namedKeyValues
source to the loader.- Parameters:
name
- the name of the sourcekeyValues
- the key-values to add- Returns:
- this builder instance
-
add
Adds aURI
as a source by wrapping it in aKeyValuesResource
.- Parameters:
uri
- the URI to add- Returns:
- this builder instance
-
add
Adds a URI specified as a string as a source to the loader.- Parameters:
uri
- the URI string to add- Returns:
- this builder instance
-
add
AddsVariables
for interpolation when loading key-values.- Parameters:
variables
- the variables to use for interpolation- Returns:
- this builder instance
-
variables
Adds variables that will be resolved based on the environment. Variables resolution order is the opposite of KeyValues. Primacy takes precedence! This is useful if you want to use environment things for variables that are bound toKeyValuesEnvironment
. This is preferred instead of just creating Variables fromSystem.getProperties()
orSystem.getenv()
directly.- Parameters:
variablesFactory
- function to create variables from environment.- Returns:
- this
- See Also:
-
build
Builds and returns a newKeyValuesLoader
based on the current state of the builder.If no sources are specified, a default classpath resource
classpath:/system.properties
is used.- Returns:
- a new
KeyValuesLoader
instance
-
load
Loads key-values using the current builder configuration.- Specified by:
load
in interfaceKeyValuesLoader
- Returns:
- a
KeyValues
instance containing the loaded key-value pairs - Throws:
IOException
- if an I/O error occurs during loadingFileNotFoundException
- if a specified resource is not found
-