@ConsumerType public interface ValueMap extends Map<String,Object>
ValueMap
is an easy way to access properties of a resource.
With resources you can use Resource.getValueMap()
to obtain the
value map of a resource. The various getter methods can be used to get the
properties of the resource.
In addition a value map returned by a resource supports getting of deep
values, like get("content/title") which is equivalent to call
getChild("content") on the resource, get the value map of that resource
and call get("title") - but without requiring to do all the checks.
Only the following methods support deep reads: Map.get(Object)
,
get(String, Class)
, get(String, Object)
and
Map.containsKey(Object)
.
A ValueMap
should be immutable.
Modifier and Type | Field and Description |
---|---|
static ValueMap |
EMPTY
Empty immutable value map.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
get(String name,
Class<T> type)
Get a named property and convert it into the given type.
|
<T> T |
get(String name,
T defaultValue)
Get a named property and convert it into the given type.
|
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
static final ValueMap EMPTY
@CheckForNull <T> T get(@Nonnull String name, @Nonnull Class<T> type)
null
in this
case.name
- The name of the propertytype
- The class of the typenull
if
non existing or can't be converted.<T> T get(@Nonnull String name, T defaultValue)
name
- The name of the propertydefaultValue
- The default value to use if the named property does
not exist or cannot be converted to the requested type. The
default value is also used to define the type to convert the
value to. If this is null
any existing property is
not converted.Copyright © 2015 The Apache Software Foundation. All rights reserved.