Interface for meta-information similar to
Use
Properties
but more sophisticated. Implements
Iterable
allowing to iterate
the available meta-information keys.Use
empty()
to get the empty instance and then call any with
method to extended with real data.
Example to show usage:
@This will print the following output (order is undefined):MetaInfoValues
({"key1=value1", "key2=value2"}) public class AnnotatedClass { public static void main(String[] args) {MetaInfo
metaInfo =MetaInfo
.empty()
.with
(AnnotatedClass.class); metaInfo = metaInfo.with
(Map.of("key2", "two", "key3", "value3")); for (String key : metaInfo) { String value = metaInfo.get
(key); System.out.println(key + "=" + value); } } }
key1=value1 key2=two key3=value3ATTENTION: Typically the
with
methods will return a new instance of MetaInfo
with the invoked
MetaInfo
as parent
. However, this is not guaranteed. Especially immutable
implementations may return a MetaInfo
with a different parent
.- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionasMap()
default Properties
static MetaInfo
config()
static MetaInfo
empty()
default String
default String
default String
default Boolean
getAsBoolean
(boolean inherit, boolean required, String key) default boolean
getAsBoolean
(boolean inherit, String key, boolean defaultValue) default Boolean
getAsBoolean
(String key) default boolean
getAsBoolean
(String key, boolean defaultValue) default boolean
default Integer
getAsInteger
(boolean inherit, boolean required, String key) default int
getAsInteger
(boolean inherit, String key, int defaultValue) default Integer
getAsInteger
(String key) default int
getAsInteger
(String key, int defaultValue) default int
default Long
default long
default Long
default long
default long
getAsLongRequired
(String key) <T> T
getGeneric
(boolean inherit, boolean required, String key, ValueType<T> type) default String
default MetaInfo
default String
getRequired
(String key) default boolean
isEmpty()
int
size()
default MetaInfo
with
(AnnotatedElement annotatedElement) Adds or updates the specified meta-info.
ATTENTION: Please consider usingwith(Map)
and other related factory methods instead of sequentially using this method that may be inefficient.default MetaInfo
default MetaInfo
with
(Properties properties) ATTENTION: Due to the design ofProperties
(with ability for inheritance but no API to get access to the parent defaults) the result will be inefficient.with
(Properties properties, String keyPrefix) ATTENTION: Due to the design ofProperties
(with ability for inheritance but no API to get access to the parent defaults) the result will be inefficient.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
get
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
.
-
getRequired
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
. - Throws:
ObjectNotFoundException
- if the specified value is undefined.
-
get
- Parameters:
key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
.
-
get
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
.
-
get
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
.
-
get
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.required
- -true
if the requested value is required and an exception shall be raised if it is undefined,false
otherwise (returnnull
if undefined).key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
. - Throws:
ObjectNotFoundException
- if the specified value is undefined andrequired
wastrue
.
-
getGeneric
- Type Parameters:
T
- type of the requested value.- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.required
- -true
if the requested value is required and an exception shall be raised if it is undefined,false
otherwise (returnnull
if undefined).key
- the key of the requested meta-information.type
- theClass
reflecting the requested value.parser
- theFunction
toparse
the value from aString
to the expected value type.- Returns:
- the value of the meta-information for the given
key
. Will benull
if no value is defined for the givenkey
. - Throws:
ObjectNotFoundException
- if the specified value is undefined andrequired
wastrue
.
-
getAsInteger
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asInteger
. Will benull
if no value is defined for the givenkey
. - Throws:
IllegalArgumentException
- if the value cannot be parsed asInteger
.
-
getAsIntegerRequired
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asInteger
. - Throws:
ObjectNotFoundException
- if the specified value is undefined.IllegalArgumentException
- if the value cannot be parsed asInteger
.
-
getAsInteger
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.required
- -true
if the requested value is required and an exception shall be raised if it is undefined,false
otherwise (returnnull
if undefined).key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asLong
. Will benull
if no value is defined for the givenkey
. - Throws:
ObjectNotFoundException
- if the specified value is undefined andrequired
wastrue
.IllegalArgumentException
- if the value cannot be parsed asInteger
.
-
getAsInteger
- Parameters:
key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
parsed asinvalid reference
int
defaultValue
will be returned. - Throws:
IllegalArgumentException
- if the value cannot be parsed asinvalid reference
int
-
getAsInteger
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
parsed asinvalid reference
int
defaultValue
will be returned. - Throws:
IllegalArgumentException
- if the value cannot be parsed asinvalid reference
int
-
getAsLong
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asLong
. Will benull
if no value is defined for the givenkey
. - Throws:
IllegalArgumentException
- if the value cannot be parsed asLong
.
-
getAsLongRequired
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asLong
. - Throws:
ObjectNotFoundException
- if the specified value is undefined.IllegalArgumentException
- if the value cannot be parsed asLong
.
-
getAsLong
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.required
- -true
if the requested value is required and an exception shall be raised if it is undefined,false
otherwise (returnnull
if undefined).key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asLong
. Will benull
if no value is defined for the givenkey
. - Throws:
ObjectNotFoundException
- if the specified value is undefined andrequired
wastrue
.IllegalArgumentException
- if the value cannot be parsed asLong
.
-
getAsLong
- Parameters:
key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
parsed asinvalid reference
long
defaultValue
will be returned. - Throws:
IllegalArgumentException
- if the value cannot be parsed asinvalid reference
long
-
getAsLong
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
parsed asinvalid reference
long
defaultValue
will be returned. - Throws:
IllegalArgumentException
- if the value cannot be parsed asinvalid reference
long
-
getAsBoolean
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asBoolean
. Will benull
if no value is defined for the givenkey
. - Throws:
IllegalArgumentException
- if the value cannot be parsed asBoolean
.
-
getAsBooleanRequired
- Parameters:
key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asBoolean
. - Throws:
ObjectNotFoundException
- if the specified value is undefined.IllegalArgumentException
- if the value cannot be parsed asBoolean
.
-
getAsBoolean
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.required
- -true
if the requested value is required and an exception shall be raised if it is undefined,false
otherwise (returnnull
if undefined).key
- the key of the requested meta-information.- Returns:
- the value of the meta-information for the given
key
parsed asBoolean
. Will benull
if no value is defined for the givenkey
. - Throws:
ObjectNotFoundException
- if the specified value is undefined andrequired
wastrue
.IllegalArgumentException
- if the value cannot be parsed asBoolean
.
-
getAsBoolean
- Parameters:
key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
parsed asinvalid reference
boolean
defaultValue
will be returned. - Throws:
IllegalArgumentException
- if the value cannot be parsed asBoolean
.
-
getAsBoolean
- Parameters:
inherit
- -true
to inherit meta-information from theparent
,false
to only return plain meta-information defined in thisMetaInfo
itself.key
- the key of the requested meta-information.defaultValue
- the default value returned if the actual value is undefined.- Returns:
- the value of the meta-information for the given
key
parsed asinvalid reference
boolean
defaultValue
will be returned. - Throws:
IllegalArgumentException
- if the value cannot be parsed asBoolean
.
-
size
int size() -
isEmpty
default boolean isEmpty()- Returns:
true
if empty,false
otherwise.
-
getParent
- Returns:
- the potential parent
MetaInfo
to inherit from. Will benull
if nothing is inherited.
-
getKeyPrefix
- Returns:
- the prefix for the
keys
as namespace. E.g. if the key prefix is "spring.datasource." and you callget(String)
with "password" it will return the property for the key "spring.datasource.password" from the underlying mapping. The default key prefix is the emptyString
.
-
with
Adds or updates the specified meta-info.
ATTENTION: Please consider usingwith(Map)
and other related factory methods instead of sequentially using this method that may be inefficient. -
with
-
with
- Parameters:
map
- theMap
with the meta-information to wrap.keyPrefix
- thekey prefix
.- Returns:
- a new
MetaInfo
that extends thisMetaInfo
with the specified meta-information.
-
with
ATTENTION: Due to the design ofProperties
(with ability for inheritance but no API to get access to the parent defaults) the result will be inefficient.- Parameters:
properties
- theProperties
with the meta-information to wrap.- Returns:
- a new
MetaInfo
that extends thisMetaInfo
with the specified meta-information.
-
with
ATTENTION: Due to the design ofProperties
(with ability for inheritance but no API to get access to the parent defaults) the result will be inefficient.- Parameters:
properties
- theProperties
with the meta-information to wrap.keyPrefix
- thekey prefix
.- Returns:
- a new
MetaInfo
that extends thisMetaInfo
with the specified meta-information.
-
with
- Parameters:
annotatedElement
- theAnnotatedElement
(e.g.Class
) that is (potentially) annotated withMetaInfos
.- Returns:
- a new
MetaInfo
that extends thisMetaInfo
with the meta-information from the givenAnnotatedElement
. Will bethis
instance itself if the givenAnnotatedElement
has noMetaInfos
annotation.
-
with
-
with
- Parameters:
keyPrefix
- thekey prefix
.- Returns:
- a new
MetaInfo
that wraps thisMetaInfo
with all its parents using the givenkey prefix
. The resultingMetaInfo
will returnnull
asparent
.
-
asProperties
- Returns:
- a new
Properties
instance with all values from thisMetaInfo
.
-
asMap
-
empty
-
config
- Returns:
- the
MetaInfo
with the configuration for the running application.
-