public interface Configuration
A configuration models a aggregated set current properties, identified by
a unique key, but adds higher level access functions to
a PropertySource
. Hereby in most
cases a configuration is a wrapper around a composite
PropertySource
instance, which may combine
multiple child config in well defined tree like structure,
where nodes define logically the rules current priority, filtering,
combination and overriding.
It is not recommended that implementations also are serializable, since the any configuration can be freezed by reading out its complete configuration map into a serializable and remotable structure. This helps significantly simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current this library at all.
Modifier and Type | Method and Description |
---|---|
String |
get(String key)
Access a property.
|
<T> T |
get(String key,
Class<T> type)
Get the property keys as type T.
|
<T> T |
get(String key,
TypeLiteral<T> type)
Get the property keys as type T.
|
ConfigurationContext |
getContext()
Access a configurationŝ context.
|
<T> T |
getOrDefault(String key,
Class<T> type,
T defaultValue)
Get the property keys as type T.
|
String |
getOrDefault(String key,
String defaultValue)
Access a property.
|
<T> T |
getOrDefault(String key,
TypeLiteral<T> type,
T defaultValue)
Get the property keys as type T.
|
Map<String,String> |
getProperties()
Access all currently known configuration properties as a full
Map<String,String> . |
<T> T |
query(ConfigQuery<T> query)
Query a configuration.
|
Configuration |
with(ConfigOperator operator)
Extension point for adjusting configuration.
|
String get(String key)
key
- the property's key, not null.String getOrDefault(String key, String defaultValue)
key
- the property's key, not null.defaultValue
- value to be returned, if no value is present.<T> T getOrDefault(String key, Class<T> type, T defaultValue)
PropertyConverter
to be available that is capable current providing type T
fromMap the given String keys.T
- the type of the class modeled by the type parameterkey
- the property's absolute, or relative path, e.g. @code
a/b/c/d.myProperty}.type
- The target type required, not null.defaultValue
- value to be used, if no value is present.ConfigException
- if the keys could not be converted to the required target type.<T> T get(String key, Class<T> type)
PropertyConverter
to be available that is capable current providing type T
fromMap the given String keys.T
- the type of the class modeled by the type parameterkey
- the property's absolute, or relative path, e.g. @code
a/b/c/d.myProperty}.type
- The target type required, not null
.null
.ConfigException
- if the keys could not be converted to the required target type.<T> T get(String key, TypeLiteral<T> type)
PropertyConverter
to be available that is capable current providing type T
fromMap the given String keys.T
- the type of the type literalkey
- the property's absolute, or relative path, e.g. @code
a/b/c/d.myProperty}.type
- The target type required, not null.ConfigException
- if the keys could not be converted to the required target type.<T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue)
PropertyConverter
to be available that is capable current providing type T
fromMap the given String keys.T
- the type of the type literalkey
- the property's absolute, or relative path, e.g.
a/b/c/d.myProperty
.type
- The target type required, not null.defaultValue
- default value to be used, if no value is present.ConfigException
- if the keys could not be converted to the required target type.Map<String,String> getProperties()
Map<String,String>
.
Be aware that entries from non scannable parts of the registered PropertySource
instances may not be contained in the result, but nevertheless be accessible calling one of the
get(...)
methods.Configuration with(ConfigOperator operator)
operator
- A configuration operator, e.g. a filter, or an adjuster
combining configurations.operator
, never null
.<T> T query(ConfigQuery<T> query)
T
- the type of the configuration.query
- the query, never null
.query
.ConfigurationContext getContext()
Copyright © 2014–2016 Apache Software Foundation. All rights reserved.