ConfigurationSnapshotpublic interface Configuration
A configuration models an aggregated setPropertyValue of 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 configurations in a 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 frozen by reading out its complete configuration mapProperties into a serializable and remotable structure. This helps significantly by simplifying the development of this interface, e.g. for being backed up by systems and stores that are not part of this library at all.
| Modifier and Type | Field | Description |
|---|---|---|
static Configuration |
EMPTY |
Immutable and reusable, thread-safe implementation of an empty propertySource.
|
| Modifier and Type | Method | Description |
|---|---|---|
default <T> T |
adapt(Function<Configuration,T> query) |
Query a configuration.
|
static ConfigurationBuilder |
createConfigurationBuilder() |
Access a new configuration builder initialized with the current thread's context classloader.
|
static Configuration |
current() |
Access the configuration instance for the current thread's context classloader.
|
static Configuration |
current(ClassLoader classloader) |
Accesses the configuration for a given classloader.
|
default String |
get(Iterable<String> keys) |
Access a property.
|
default <T> T |
get(Iterable<String> keys,
Class<T> type) |
Gets the property keys as type T.
|
default <T> T |
get(Iterable<String> keys,
TypeLiteral<T> type) |
Get the property keys as type T.
|
default String |
get(String key) |
Access a property.
|
default <T> T |
get(String key,
Class<T> type) |
Gets 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's context.
|
default Optional<String> |
getOptional(Iterable<String> keys) |
Access a String property, using an an
Optional instance. |
default <T> Optional<T> |
getOptional(Iterable<String> keys,
Class<T> type) |
Access a property, using an an
Optional instance. |
default <T> Optional<T> |
getOptional(Iterable<String> keys,
TypeLiteral<T> type) |
Access a property, using an an
Optional instance. |
default Optional<String> |
getOptional(String key) |
Access a String property, using an an
Optional instance. |
default <T> Optional<T> |
getOptional(String key,
Class<T> type) |
Access a property, using an an
Optional instance. |
default <T> Optional<T> |
getOptional(String key,
TypeLiteral<T> type) |
Access a property, using an an
Optional instance. |
default <T> T |
getOrDefault(Iterable<String> keys,
Class<T> type,
T defaultValue) |
Gets the property keys as type T.
|
default String |
getOrDefault(Iterable<String> keys,
String defaultValue) |
Access a property.
|
default <T> T |
getOrDefault(Iterable<String> keys,
TypeLiteral<T> type,
T defaultValue) |
Get the property keys as type T.
|
default <T> T |
getOrDefault(String key,
Class<T> type,
T defaultValue) |
Gets the property keys as type T.
|
default 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>. |
ConfigurationSnapshot |
getSnapshot(Iterable<String> keys) |
Create a snapshot, which contains the given keys.
|
default ConfigurationSnapshot |
getSnapshot(String... keys) |
Create a snapshot, which contains all known keys.
|
default Configuration |
map(UnaryOperator<Configuration> operator) |
Extension point for adjusting configuration.
|
default <T> T |
query(ConfigQuery<T> query) |
Deprecated.
Use
adapt(Function) |
static Configuration |
releaseConfiguration(ClassLoader classloader) |
Releases the configuration associated with the given classloader.
|
static void |
setCurrent(Configuration config) |
This method allows replacement of the current default
Configuration with a new
instance. |
static void |
setCurrent(Configuration config,
ClassLoader classLoader) |
This method allows replacement of the current default
Configuration with a new
instance. |
default ConfigurationBuilder |
toBuilder() |
Create a new builder using this instance as its base.
|
default Configuration |
with(ConfigOperator operator) |
Deprecated.
|
static final Configuration EMPTY
default String get(String key)
key - the property's key, not null.default String get(Iterable<String> keys)
keys - the property's keys, in order of evaluation, not null.default String getOrDefault(String key, String defaultValue)
key - the property's key, not null.defaultValue - value to be returned, if no value is present, not nulldefault String getOrDefault(Iterable<String> keys, String defaultValue)
keys - the property's keys, in order of evaluation, not null.defaultValue - value to be returned, if no value is present, not nulldefault Optional<String> getOptional(String key)
Optional instance.key - the property's key, not null.default Optional<String> getOptional(Iterable<String> keys)
Optional instance.keys - the property's keys, in evaluation order, not null.default <T> Optional<T> getOptional(String key, Class<T> type)
Optional instance.T - the type of the class modeled by the type parameterkey - the property's key, not null.type - the target type, not null.default <T> Optional<T> getOptional(Iterable<String> keys, Class<T> type)
Optional instance.T - the type of the class modeled by the type parameterkeys - the property's keys, in evaluation order, not null.type - the target type, not null.default <T> Optional<T> getOptional(String key, TypeLiteral<T> type)
Optional instance.T - the type of the class modeled by the type parameterkey - the property's key, not null.type - the target type, not null.default <T> Optional<T> getOptional(Iterable<String> keys, TypeLiteral<T> type)
Optional instance.T - the type of the class modeled by the type parameterkeys - the property's keys, in evaluation order, not null.type - the target type, not null.default <T> T getOrDefault(String key, Class<T> type, T defaultValue)
PropertyConverter to be available that is capable of providing type T
fromMap for the given String keys.T - the type of the class modeled by the type parameterkey - the property's absolute, or relative path, e.g.
a/b/c/d.myProperty, not null.type - The target type required, not null.defaultValue - value to be used, if no value is present, not nullnull.ConfigException - if the keys could not be converted to the required target type.default <T> T getOrDefault(Iterable<String> keys, Class<T> type, T defaultValue)
PropertyConverter to be available that is capable of providing type T
fromMap for the given String keys.T - the type of the class modeled by the type parameterkeys - the property's keys, in evaluation order, not null.type - The target type required, not null.defaultValue - value to be used, if no value is present, not nullnull.ConfigException - if the keys could not be converted to the required target type.default <T> T get(String key, Class<T> type)
PropertyConverter to be available that is capable of providing type T
fromMap for 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.default <T> T get(Iterable<String> keys, Class<T> type)
PropertyConverter to be available that is capable of providing type T
fromMap for the given String keys.T - the type of the class modeled by the type parameterkeys - the property's keys, in evaluation order, not null.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 of providing type T
literals for the given key.T - the type of the type literalkey - the property's absolute, or relative path, e.g. @code
a/b/c/d.myProperty}, not null.type - The target type required, not null.null.ConfigException - if the keys could not be converted to the required target type.default <T> T get(Iterable<String> keys, TypeLiteral<T> type)
PropertyConverter to be available that is capable of providing type T
literals for the given key.T - the type of the type literalkeys - the property's keys, in evaluation order, not null.type - The target type required, not null.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 of providing type T
literals for the given key.T - the type of the type literalkey - the property's absolute, or relative path, e.g.
a/b/c/d.myProperty, not null.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.default <T> T getOrDefault(Iterable<String> keys, TypeLiteral<T> type, T defaultValue)
PropertyConverter to be available that is capable of providing type T
literals for the given key.T - the type of the type literalkeys - the property's keys, in evaluation order, not null.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 by calling one of the
current(...) methods.@Deprecated default Configuration with(ConfigOperator operator)
map(UnaryOperator)operator - A configuration operator, e.g. a filter, or an adjuster
combining configurations, never null.operator, never null.default Configuration map(UnaryOperator<Configuration> operator)
operator - A configuration operator, e.g. a filter, or an adjuster
combining configurations, never null.operator, never null.@Deprecated default <T> T query(ConfigQuery<T> query)
adapt(Function)T - the type of the configuration.query - the query, not null.query.default <T> T adapt(Function<Configuration,T> query)
T - the type of the configuration.query - the query, not null.query.ConfigurationContext getContext()
ConfigurationSnapshot getSnapshot(Iterable<String> keys)
keys - the keys, not null. If empty a full snapshot with all known keys is returned.default ConfigurationSnapshot getSnapshot(String... keys)
keys - the target key. If empty a full snapshot with all known keys is returned.default ConfigurationBuilder toBuilder()
static void setCurrent(Configuration config)
Configuration with a new
instance. It is the responsibility of the ConfigurationProvider to trigger
corresponding update events for the current Configuration, so observing
listeners can do whatever is appropriate to react to any given configuration change.config - the new Configuration to be applied, not nullUnsupportedOperationException - if the current provider is read-only and
does not support
applying a new Configuration.static void setCurrent(Configuration config, ClassLoader classLoader)
Configuration with a new
instance. It is the responsibility of the ConfigurationProvider to trigger
corresponding update events for the current Configuration, so observing
listeners can do whatever is appropriate to react to any given configuration change.config - the new Configuration to be applied, not nullclassLoader - the target classloader, not null.UnsupportedOperationException - if the current provider is read-only and
does not support
applying a new Configuration.static Configuration current()
static Configuration current(ClassLoader classloader)
classloader - the classloader, not null.static Configuration releaseConfiguration(ClassLoader classloader)
classloader - the classloader, not null.static ConfigurationBuilder createConfigurationBuilder()
Copyright © 2014–2019 Apache Software Foundation. All rights reserved.