Package io.helidon.microprofile.config
Class MpConfig
- java.lang.Object
-
- io.helidon.microprofile.config.MpConfig
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> List<T>asList(String propertyName, Class<T> typeArg)Return value as aListof values.Map<String,String>asMap()Get all properties of this config as a map.<T> Set<T>asSet(String propertyName, Class<T> typeArg)Return value as aSetof values.static MpConfigBuilderbuilder()Get a builder for config instances.<T> Tconvert(Class<T> type, String value)Try to coerce the value to the specific type.Iterable<ConfigSource>getConfigSources()<T> Optional<T>getOptionalValue(String propertyName, Class<T> propertyType)Iterable<String>getPropertyNames()<T> TgetValue(String propertyName, Class<T> propertyType)ConfighelidonConfig()Get an instance of Helidon config (a tree structure) rather than the microprofile config.StringtoString()<T> Tvalue(String propertyName, Class<T> propertyType, T defaultValue)Get value with a default if it does not exist.<T> TvalueWithDefault(String propertyName, Class<T> propertyType, String defaultValue)Get value with a default if it does not exist.
-
-
-
Method Detail
-
builder
public static MpConfigBuilder builder()
Get a builder for config instances.- Returns:
- a new builder
-
asSet
public <T> Set<T> asSet(String propertyName, Class<T> typeArg)
Return value as aSetof values.- Type Parameters:
T- type of elements- Parameters:
propertyName- name of propertytypeArg- type of elements in the set- Returns:
- set with elements found in properties
-
asList
public <T> List<T> asList(String propertyName, Class<T> typeArg)
Return value as aListof values.- Type Parameters:
T- type of elements- Parameters:
propertyName- name of propertytypeArg- type of elements in the list- Returns:
- list with elements found in properties
-
value
public <T> T value(String propertyName, Class<T> propertyType, T defaultValue)
Get value with a default if it does not exist.- Type Parameters:
T- type of the property- Parameters:
propertyName- name of the propertypropertyType- type of the propertydefaultValue- default value correctly typed- Returns:
- value from configuration or default value if not available
-
valueWithDefault
public <T> T valueWithDefault(String propertyName, Class<T> propertyType, String defaultValue)
Get value with a default if it does not exist.- Type Parameters:
T- type of the property- Parameters:
propertyName- name of the propertypropertyType- type of the propertydefaultValue- default value as String- Returns:
- value from configuration or default value coerced to correct type if not available
-
getOptionalValue
public <T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType)
- Specified by:
getOptionalValuein interfaceConfig
-
getPropertyNames
public Iterable<String> getPropertyNames()
- Specified by:
getPropertyNamesin interfaceConfig
-
getConfigSources
public Iterable<ConfigSource> getConfigSources()
- Specified by:
getConfigSourcesin interfaceConfig
-
convert
public <T> T convert(Class<T> type, String value)
Try to coerce the value to the specific type.- Type Parameters:
T- type we expect (e.g. String, Integer or a java bean)- Parameters:
type- type to returnvalue- string value to parse- Returns:
- null if value is null, transformed object otherwise
- Throws:
IllegalArgumentException- if the value cannot be converted to the specified type using.
-
helidonConfig
public Config helidonConfig()
Get an instance of Helidon config (a tree structure) rather than the microprofile config.- Returns:
- config instance that has the same properties as this instance
-
asMap
public Map<String,String> asMap()
Get all properties of this config as a map.- Returns:
- map where keys are configuration keys and values are associated string values
-
-