public class MicroProfileConfigProperties extends Properties
Properties implementation that wraps a Config and
is suitable for installing as System properties.
This class intentionally violates several tenets of the
Map interface and Properties class.
Deviations and oddities are noted below.
Hashtable.clear() method, while supported, cannot, and
therefore does not, remove any items from the Config that
is expressed by this class. It will remove all items manually
put into a MicroProfileConfigProperties instance directly.Config.getPropertyNames(), all iteration methods in this class
should be regarded as producing unmodifiable snapshots of a rough
estimate of the keys present in a MicroProfileConfigProperties instance.UnsupportedOperationException where appropriate.Config abstracts, it is possible, for
example, for the containsKey(Object) method to return
true, and then for get(Object) to be unable to
retrieve a value.This class is safe for concurrent use by multiple threads.
Config,
Serialized Formdefaults| Constructor and Description |
|---|
MicroProfileConfigProperties()
Creates a new
MicroProfileConfigProperties representing
the Config that results from ConfigProvider.getConfig(). |
MicroProfileConfigProperties(Config config)
Creates a new
MicroProfileConfigProperties wrapping the
supplied Config. |
MicroProfileConfigProperties(Config config,
Properties defaults)
Creates a new
MicroProfileConfigProperties using the
supplied Properties as its defaults and wrapping the supplied Config. |
MicroProfileConfigProperties(Properties defaults)
Creates a new
MicroProfileConfigProperties using the
supplied Properties as its defaults and wrapping the Config
that results from ConfigProvider.getConfig(). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(Object value)
Invokes the
containsValue(Object) method with the
supplied Object and returns the result. |
boolean |
containsKey(Object key)
Returns
true if this MicroProfileConfigProperties
directly contains the
supplied key, or if the supplied key is a String and is contained in the Set of configuration
property names returned by the Config.getPropertyNames()
method. |
boolean |
containsValue(Object value)
|
Enumeration<Object> |
elements()
Returns a non-
null Enumeration constructed atop
the Iterator supplied
by the Collection returned by an invocation of this
MicroProfileConfigProperties' values() method. |
Set<Map.Entry<Object,Object>> |
entrySet()
Returns a non-
null immutable Set of
immutable Entry
instances representing this MicroProfileConfigProperties'
entries. |
Object |
get(Object key)
Returns the value indexed under the supplied
key, or
null if the value does not exist. |
String |
getProperty(String key)
Returns the
String value indexed under the supplied
key. |
static void |
installAsSystemProperties()
Installs an instance of
MicroProfileConfigProperties
somewhat irrevocably as the system properties, with the
current system properties as
its defaults. |
boolean |
isEmpty()
Returns
true if this MicroProfileConfigProperties
is empty. |
Enumeration<Object> |
keys()
Invokes the
keySet() method and returns its return
value. |
Set<Object> |
keySet()
Returns a non-
null, immutable Set of
Objects that contains the keys stored directly by this
MicroProfileConfigProperties or that are contained in the
return value of a Config.getPropertyNames() invocation. |
int |
size()
Returns the size of this
MicroProfileConfigProperties as
expressed by the size of its key set. |
Collection<Object> |
values()
|
getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNamesclear, clone, compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, toStringpublic MicroProfileConfigProperties()
MicroProfileConfigProperties representing
the Config that results from ConfigProvider.getConfig().ConfigProvider.getConfig()public MicroProfileConfigProperties(Config config)
MicroProfileConfigProperties wrapping the
supplied Config.config - the Config to express; may be null
in which case the return value of ConfigProvider.getConfig() will be used insteadConfigProvider.getConfig()public MicroProfileConfigProperties(Properties defaults)
MicroProfileConfigProperties using the
supplied Properties as its defaults and wrapping the Config
that results from ConfigProvider.getConfig().defaults - the default Properties; may be nullProperties.defaults,
ConfigProvider.getConfig()public MicroProfileConfigProperties(Config config, Properties defaults)
MicroProfileConfigProperties using the
supplied Properties as its defaults and wrapping the supplied Config.config - the Config to express; may be null
in which case the return value of ConfigProvider.getConfig() will be used insteaddefaults - the default Properties; may be nullConfigProvider.getConfig()public final boolean containsKey(Object key)
true if this MicroProfileConfigProperties
directly contains the
supplied key, or if the supplied key is a String and is contained in the Set of configuration
property names returned by the Config.getPropertyNames()
method.
This method is safe for concurrent use by multiple threads.
containsKey in interface Map<Object,Object>containsKey in class Hashtable<Object,Object>key - the key to seek; may be nulltrue if this MicroProfileConfigProperties
directly contains the
supplied key, or if the supplied key is a String and is contained in the Set of configuration
property names returned by the Config.getPropertyNames()
method; false otherwisepublic final boolean contains(Object value)
containsValue(Object) method with the
supplied Object and returns the result.
This method is safe for concurrent use by multiple threads.
contains in class Hashtable<Object,Object>value - the value to seek; may be nulltrue if the containsValue(Object) method
returns true; false otherwisecontainsValue(Object)public final boolean containsValue(Object value)
true if this MicroProfileConfigProperties
contains the supplied value Object.
First the Hashtable.containsValue(Object) method is
invoked with the supplied Object. If that returns true, then true is returned.
Next, all known property
names in the Config wrapped by this
MicroProfileConfigProperties are acquired. This
set is iterated over and Config.getOptionalValue(String,
Class) is called for each one. If the resulting Optional is present, then
true is returned.
In all other cases false is returned.
This method is safe for concurrent use by multiple threads.
containsValue in interface Map<Object,Object>containsValue in class Hashtable<Object,Object>value - the value to seek; may be nulltrue if this MicroProfileConfigProperties
contains the supplied value; false otherwiseConfig.getPropertyNames(),
Hashtable.containsValue(Object)public final String getProperty(String key)
String value indexed under the supplied
key.
This method may return null.
This implementation first calls get(Object). If the
result is a non-null String, then it is returned.
Otherwise, if the Properties.defaults field is non-null,
then Properties.getProperty(String) is invoked on it with
the supplied key and the result is returned. In all
other cases null is returned.
This method is safe for concurrent use by multiple threads.
getProperty in class Propertieskey - the key of the value to return; may be nullnullget(Object),
Properties.defaults,
Properties.getProperty(String)public final Object get(Object key)
key, or
null if the value does not exist. Note that a null return value could result from a key's being explicitly
mapped to null, or from a key's absence.
This implementation first calls Hashtable.containsKey(Object) with the supplied key. If
that method invocation returns true, then the Hashtable.get(Object) method is invoked and its result is
returned.
Otherwise, the Config.getOptionalValue(String, Class)
method is called and its resulting Optional result
is acquired and returned, or, if it
is not present, null is
returned.
This method is safe for concurrent use by multiple threads.
get in interface Map<Object,Object>get in class Hashtable<Object,Object>key - the key of the value to return; may be nullnullHashtable.containsKey(Object),
Hashtable.get(Object),
Config.getOptionalValue(String, Class)public final boolean isEmpty()
true if this MicroProfileConfigProperties
is empty. In all normal cases, this method will return false, since normally Config instances expose at least
one configuration property value.
This implementation calls the Hashtable.isEmpty()
method. If that method returns false, then false
is returned.
Otherwise this method calls the Config.getPropertyNames() method, calls Iterable.iterator() on the resulting Iterable, and, if
it is non-null, calls the Iterator.hasNext()
method on it, returning its result.
In all other cases this method returns true.
This method is a much faster way of checking if this MicroProfileConfigProperties' size is 0.
This method is safe for concurrent use by multiple threads.
isEmpty in interface Map<Object,Object>isEmpty in class Hashtable<Object,Object>true, rarely, if this MicroProfileConfigProperties is empty; false otherwiseHashtable.isEmpty(),
Config.getPropertyNames()public final int size()
MicroProfileConfigProperties as
expressed by the size of its key set.
This method returns ints that are greater than or equal to zero.
This method rarely returns 0 given the fact that a
Config normally expresses at least one configuration
property value.
Use the isEmpty() method for a much, much faster way
to check for a size of 0.
This method is safe for concurrent use by multiple threads.
public final Enumeration<Object> keys()
keySet() method and returns its return
value.
This method never returns null.
This method is safe for concurrent use by multiple threads.
public final Set<Object> keySet()
null, immutable Set of
Objects that contains the keys stored directly by this
MicroProfileConfigProperties or that are contained in the
return value of a Config.getPropertyNames() invocation.
The Set of Objects returned by this method is
a disconnected snapshot in time of the keys that were thought to
be in this MicroProfileConfigProperties at the time the
snapshot was constructed. Changes to this MicroProfileConfigProperties are not reflected in the Set.
This method is safe for concurrent use by multiple threads.
The Set returned by this method is safe for concurrent
use by multiple threads.
keySet in interface Map<Object,Object>keySet in class Hashtable<Object,Object>null, immutable Set of
Objects that contains the keys stored directly by this
MicroProfileConfigProperties or that are contained in the
return value of a Config.getPropertyNames() invocationHashtable.keySet(),
Config.getPropertyNames()public final Enumeration<Object> elements()
null Enumeration constructed atop
the Iterator supplied
by the Collection returned by an invocation of this
MicroProfileConfigProperties' values() method.
This method is safe for concurrent use by multiple threads.
elements in class Hashtable<Object,Object>null Enumeration over the values
directly contained by this MicroProfileConfigProperties
or indirectly accessible via calls to Config.getOptionalValue(String, Class)values(),
Config.getPropertyNames(),
Config.getOptionalValue(String, Class)public final Collection<Object> values()
null, immutable
Collection of this MicroProfileConfigProperties' values.
The values returned are those stored directly (via calls to
Hashtable.put(Object, Object), for example) or stored implicitly
as configuration values accessible via calls to Config.getOptionalValue(String, Class).
Changes in this MicroProfileConfigProperties are not
reflected in the returned Collection.
This method is safe for concurrent use by multiple threads.
values in interface Map<Object,Object>values in class Hashtable<Object,Object>null, immutable
Collection of this MicroProfileConfigProperties' valuesConfig.getPropertyNames(),
Config.getOptionalValue(String, Class)public final Set<Map.Entry<Object,Object>> entrySet()
null immutable Set of
immutable Entry
instances representing this MicroProfileConfigProperties'
entries.
The entries returned are those that result from calls to
Hashtable.put(Object, Object) and similar methods, and from
configuration property values accessible via calls to Config.getOptionalValue(String, Class).
This method calls the keySet() and get(Object) methods.
Iteration order of the returned Set is not defined,
with the exception that entries stored directly come at the head
of the returned Set.
This method is safe for concurrent use by multiple threads.
entrySet in interface Map<Object,Object>entrySet in class Hashtable<Object,Object>null immutable Set of
immutable Entry
instances representing this MicroProfileConfigProperties'
entriesConfig.getPropertyNames(),
Config.getOptionalValue(String, Class)public static final void installAsSystemProperties()
MicroProfileConfigProperties
somewhat irrevocably as the system properties, with the
current system properties as
its defaults.
This method is safe for concurrent use by multiple threads.
SecurityException - if permission is not grantedCopyright © 2019–2021, microBean™. All rights reserved.