Package io.micronaut.core.convert.value
Interface ConvertibleValues<V>
-
- Type Parameters:
V
- The generic value
- All Superinterfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.String,V>>
,ValueResolver<java.lang.CharSequence>
- All Known Subinterfaces:
ConvertibleMultiValues<V>
,Headers
,MutableConvertibleMultiValues<V>
,MutableConvertibleValues<V>
,MutableHeaders
- All Known Implementing Classes:
ConvertibleMultiValuesMap
,ConvertibleValuesMap
,MutableConvertibleMultiValuesMap
,MutableConvertibleValuesMap
public interface ConvertibleValues<V> extends ValueResolver<java.lang.CharSequence>, java.lang.Iterable<java.util.Map.Entry<java.lang.String,V>>
An interface for classes that represent a map-like structure of values that can be converted.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static ConvertibleValues
EMPTY
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.Map<java.lang.String,V>
asMap()
Return thisConvertibleValues
as a map for the given key type and value type.default <KT,VT>
java.util.Map<KT,VT>asMap(java.lang.Class<KT> keyType, java.lang.Class<VT> valueType)
Return thisConvertibleValues
as a map for the given key type and value type.default java.util.Properties
asProperties()
Return thisConvertibleValues
as aProperties
object returning only keys and values that can be represented as a string.default boolean
contains(java.lang.String name)
Whether the given key is contained within these values.static <V> ConvertibleValues<V>
empty()
An emptyConvertibleValues
.default void
forEach(java.util.function.BiConsumer<java.lang.String,V> action)
Performs the given action for each value.default V
getValue(java.lang.CharSequence name)
Get a raw value without any conversion.default java.lang.Class<V>
getValueType()
default boolean
isEmpty()
default java.util.Iterator<java.util.Map.Entry<java.lang.String,V>>
iterator()
java.util.Set<java.lang.String>
names()
static <T> ConvertibleValues<T>
of(java.util.Map<? extends java.lang.CharSequence,T> values)
Creates a newConvertibleValues
for the values.default java.util.Map<java.lang.String,V>
subMap(java.lang.String prefix, ArgumentConversionContext<V> valueType)
Returns a submap for all the keys with the given prefix.default java.util.Map<java.lang.String,V>
subMap(java.lang.String prefix, Argument<V> valueType)
Returns a submap for all the keys with the given prefix.default java.util.Map<java.lang.String,V>
subMap(java.lang.String prefix, java.lang.Class<V> valueType)
Returns a submap for all the keys with the given prefix.java.util.Collection<V>
values()
-
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get, get
-
-
-
-
Field Detail
-
EMPTY
static final ConvertibleValues EMPTY
-
-
Method Detail
-
names
java.util.Set<java.lang.String> names()
- Returns:
- The names of the values
-
values
java.util.Collection<V> values()
- Returns:
- The values
-
isEmpty
default boolean isEmpty()
- Returns:
- Whether this values is empty
-
getValueType
default java.lang.Class<V> getValueType()
- Returns:
- The concrete type of the value
-
contains
default boolean contains(java.lang.String name)
Whether the given key is contained within these values.- Parameters:
name
- The key name- Returns:
- True if it is
-
getValue
@Nullable default V getValue(java.lang.CharSequence name)
Get a raw value without any conversion.- Parameters:
name
- The key name- Returns:
- True if it is
- Since:
- 2.0.0
-
forEach
default void forEach(java.util.function.BiConsumer<java.lang.String,V> action)
Performs the given action for each value. Note that in the case where multiple values exist for the same header then the consumer will be invoked multiple times for the same key.- Parameters:
action
- The action to be performed for each entry- Throws:
java.lang.NullPointerException
- if the specified action is null- Since:
- 1.0
-
asMap
default java.util.Map<java.lang.String,V> asMap()
Return thisConvertibleValues
as a map for the given key type and value type. The map represents a copy of the data held by this instance.- Returns:
- The values
-
asMap
default <KT,VT> java.util.Map<KT,VT> asMap(java.lang.Class<KT> keyType, java.lang.Class<VT> valueType)
Return thisConvertibleValues
as a map for the given key type and value type. If any entry cannot be converted to the target key/value type then the entry is simply excluded, hence the size of the map returned may not match the size of thisConvertibleValues
.- Type Parameters:
KT
- The key typeVT
- The value type- Parameters:
keyType
- The key typevalueType
- The value type- Returns:
- The values with the key converted to the given key type and the value to the given value type.
-
asProperties
default java.util.Properties asProperties()
Return thisConvertibleValues
as aProperties
object returning only keys and values that can be represented as a string.- Returns:
- The values with the key converted to the given key type and the value to the given value type.
- Since:
- 1.0.3
-
subMap
default java.util.Map<java.lang.String,V> subMap(java.lang.String prefix, java.lang.Class<V> valueType)
Returns a submap for all the keys with the given prefix.- Parameters:
prefix
- The prefixvalueType
- The value type- Returns:
- The submap
-
subMap
default java.util.Map<java.lang.String,V> subMap(java.lang.String prefix, Argument<V> valueType)
Returns a submap for all the keys with the given prefix.- Parameters:
prefix
- The prefixvalueType
- The value type- Returns:
- The submap
-
subMap
default java.util.Map<java.lang.String,V> subMap(java.lang.String prefix, ArgumentConversionContext<V> valueType)
Returns a submap for all the keys with the given prefix.- Parameters:
prefix
- The prefixvalueType
- The value type- Returns:
- The submap
-
iterator
default java.util.Iterator<java.util.Map.Entry<java.lang.String,V>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<V>
-
of
static <T> ConvertibleValues<T> of(java.util.Map<? extends java.lang.CharSequence,T> values)
Creates a newConvertibleValues
for the values.- Type Parameters:
T
- The target generic type- Parameters:
values
- A map of values- Returns:
- The values
-
empty
static <V> ConvertibleValues<V> empty()
An emptyConvertibleValues
.- Type Parameters:
V
- The generic type- Returns:
- The empty
ConvertibleValues
-
-