Interface StructuredConfigProperties
-
- All Known Implementing Classes:
EmptyStructuredConfigProperties
public interface StructuredConfigProperties
An interface for accessing structured configuration data.An instance of
StructuredConfigProperties
is equivalent to a YAML mapping node. It has accessors for reading scalar properties,getStructured(String)
for reading children which are themselves mappings, andgetStructuredList(String)
for reading children which are sequences of mappings.This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static StructuredConfigProperties
empty()
Return an emptyStructuredConfigProperties
instance.java.lang.Boolean
getBoolean(java.lang.String name)
Returns aBoolean
configuration property.default boolean
getBoolean(java.lang.String name, boolean defaultValue)
Returns aBoolean
configuration property.java.lang.Double
getDouble(java.lang.String name)
Returns aDouble
configuration property.default double
getDouble(java.lang.String name, double defaultValue)
Returns aDouble
configuration property.java.lang.Integer
getInt(java.lang.String name)
Returns aInteger
configuration property.default int
getInt(java.lang.String name, int defaultValue)
Returns aInteger
configuration property.java.lang.Long
getLong(java.lang.String name)
Returns aLong
configuration property.default long
getLong(java.lang.String name, long defaultValue)
Returns aLong
configuration property.java.util.Set<java.lang.String>
getPropertyKeys()
Returns a set of all configuration property keys.<T> java.util.List<T>
getScalarList(java.lang.String name, java.lang.Class<T> scalarType)
Returns aList
configuration property.default <T> java.util.List<T>
getScalarList(java.lang.String name, java.lang.Class<T> scalarType, java.util.List<T> defaultValue)
Returns aList
configuration property.java.lang.String
getString(java.lang.String name)
Returns aString
configuration property.default java.lang.String
getString(java.lang.String name, java.lang.String defaultValue)
Returns aString
configuration property.StructuredConfigProperties
getStructured(java.lang.String name)
Returns aStructuredConfigProperties
configuration property.default StructuredConfigProperties
getStructured(java.lang.String name, StructuredConfigProperties defaultValue)
Returns aStructuredConfigProperties
configuration property.java.util.List<StructuredConfigProperties>
getStructuredList(java.lang.String name)
Returns a list ofStructuredConfigProperties
configuration property.default java.util.List<StructuredConfigProperties>
getStructuredList(java.lang.String name, java.util.List<StructuredConfigProperties> defaultValue)
Returns a list ofStructuredConfigProperties
configuration property.
-
-
-
Method Detail
-
empty
static StructuredConfigProperties empty()
Return an emptyStructuredConfigProperties
instance.Useful for walking the tree without checking for null. For example, to access a string key nested at .foo.bar.baz, call:
config.getStructured("foo", empty()).getStructured("bar", empty()).getString("baz")
.
-
getString
@Nullable java.lang.String getString(java.lang.String name)
Returns aString
configuration property.- Returns:
- null if the property has not been configured
- Throws:
ConfigurationException
- if the property is not a valid scalar string
-
getString
default java.lang.String getString(java.lang.String name, java.lang.String defaultValue)
Returns aString
configuration property.- Returns:
- a
String
configuration property ordefaultValue
if a property withname
has not been configured - Throws:
ConfigurationException
- if the property is not a valid scalar string
-
getBoolean
@Nullable java.lang.Boolean getBoolean(java.lang.String name)
Returns aBoolean
configuration property. Implementations should use the same rules asBoolean.parseBoolean(String)
for handling the values.- Returns:
- null if the property has not been configured
- Throws:
ConfigurationException
- if the property is not a valid scalar boolean
-
getBoolean
default boolean getBoolean(java.lang.String name, boolean defaultValue)
Returns aBoolean
configuration property.- Returns:
- a
Boolean
configuration property ordefaultValue
if a property withname
has not been configured - Throws:
ConfigurationException
- if the property is not a valid scalar boolean
-
getInt
@Nullable java.lang.Integer getInt(java.lang.String name)
Returns aInteger
configuration property.If the underlying config property is
Long
, it is converted toInteger
withLong.intValue()
which may result in loss of precision.- Returns:
- null if the property has not been configured
- Throws:
ConfigurationException
- if the property is not a valid scalar integer
-
getInt
default int getInt(java.lang.String name, int defaultValue)
Returns aInteger
configuration property.If the underlying config property is
Long
, it is converted toInteger
withLong.intValue()
which may result in loss of precision.- Returns:
- a
Integer
configuration property ordefaultValue
if a property withname
has not been configured - Throws:
ConfigurationException
- if the property is not a valid scalar integer
-
getLong
@Nullable java.lang.Long getLong(java.lang.String name)
Returns aLong
configuration property.- Returns:
- null if the property has not been configured
- Throws:
ConfigurationException
- if the property is not a valid scalar long
-
getLong
default long getLong(java.lang.String name, long defaultValue)
Returns aLong
configuration property.- Returns:
- a
Long
configuration property ordefaultValue
if a property withname
has not been configured - Throws:
ConfigurationException
- if the property is not a valid scalar long
-
getDouble
@Nullable java.lang.Double getDouble(java.lang.String name)
Returns aDouble
configuration property.- Returns:
- null if the property has not been configured
- Throws:
ConfigurationException
- if the property is not a valid scalar double
-
getDouble
default double getDouble(java.lang.String name, double defaultValue)
Returns aDouble
configuration property.- Returns:
- a
Double
configuration property ordefaultValue
if a property withname
has not been configured - Throws:
ConfigurationException
- if the property is not a valid scalar double
-
getScalarList
@Nullable <T> java.util.List<T> getScalarList(java.lang.String name, java.lang.Class<T> scalarType)
Returns aList
configuration property. Empty values and values which do not map to thescalarType
will be removed.- Parameters:
name
- the property namescalarType
- the scalar type, one ofString
,Boolean
,Long
orDouble
- Returns:
- a
List
configuration property, or null if the property has not been configured - Throws:
ConfigurationException
- if the property is not a valid sequence of scalars, or ifscalarType
is not supported
-
getScalarList
default <T> java.util.List<T> getScalarList(java.lang.String name, java.lang.Class<T> scalarType, java.util.List<T> defaultValue)
Returns aList
configuration property. Entries which are not strings are converted to their string representation.- Returns:
- a
List
configuration property ordefaultValue
if a property withname
has not been configured - Throws:
ConfigurationException
- if the property is not a valid sequence of scalars- See Also:
ConfigProperties.getList(String name)
-
getStructured
@Nullable StructuredConfigProperties getStructured(java.lang.String name)
Returns aStructuredConfigProperties
configuration property.- Returns:
- a map-valued configuration property, or
null
ifname
has not been configured - Throws:
ConfigurationException
- if the property is not a mapping
-
getStructured
default StructuredConfigProperties getStructured(java.lang.String name, StructuredConfigProperties defaultValue)
Returns aStructuredConfigProperties
configuration property.- Returns:
- a map-valued configuration property, or
defaultValue
ifname
has not been configured - Throws:
ConfigurationException
- if the property is not a mapping
-
getStructuredList
@Nullable java.util.List<StructuredConfigProperties> getStructuredList(java.lang.String name)
Returns a list ofStructuredConfigProperties
configuration property.- Returns:
- a list of map-valued configuration property, or
null
ifname
has not been configured - Throws:
ConfigurationException
- if the property is not a sequence of mappings
-
getStructuredList
default java.util.List<StructuredConfigProperties> getStructuredList(java.lang.String name, java.util.List<StructuredConfigProperties> defaultValue)
Returns a list ofStructuredConfigProperties
configuration property.- Returns:
- a list of map-valued configuration property, or
defaultValue
ifname
has not been configured - Throws:
ConfigurationException
- if the property is not a sequence of mappings
-
getPropertyKeys
java.util.Set<java.lang.String> getPropertyKeys()
Returns a set of all configuration property keys.- Returns:
- the configuration property keys
-
-