Package org.apache.sling.api.wrappers
Class ValueMapUtil
- java.lang.Object
-
- org.apache.sling.api.wrappers.ValueMapUtil
-
public final class ValueMapUtil extends java.lang.Object
Factory methods to createValueMap
s.- Since:
- 2.7
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull ValueMap
cache(@NotNull ValueMap valueMap)
Decorates the givenValueMap
with a caching layer.static @NotNull ValueMap
merge(@NotNull java.util.List<ValueMap> valueMaps)
Merge providedValueMaps
into a single viewValueMap
that aggregates all key-value pairs of the given maps.static @NotNull ValueMap
merge(@NotNull ValueMap... valueMaps)
A convenience method that turns the var-args into aCollection
and delegates tomerge(List)
.static @NotNull ValueMap
mergeAndCache(@NotNull java.util.List<ValueMap> valueMaps)
Convenience method that allows creating a mergedValueMap
where accessed mappings are cached to optimize repeated lookups.
-
-
-
Method Detail
-
merge
@NotNull public static @NotNull ValueMap merge(@NotNull @NotNull ValueMap... valueMaps)
A convenience method that turns the var-args into aCollection
and delegates tomerge(List)
.- Parameters:
valueMaps
- theValueMap
instances to merge- Returns:
- the merged
ValueMap
view - See Also:
merge(List)
-
merge
@NotNull public static @NotNull ValueMap merge(@NotNull @NotNull java.util.List<ValueMap> valueMaps)
Merge providedValueMaps
into a single viewValueMap
that aggregates all key-value pairs of the given maps. The value for a key-value pair is taken from the firstValueMap
(in iteration order) that has a mapping for the given key.
E.g. assumingmerge(vm1, vm2, vm3
where all mapsvm1, vm2, vm3
have a value mapped to the keyk1
, then the value fromvm1
is returned.- Parameters:
valueMaps
- theValueMap
instances to merge- Returns:
- the merged
ValueMap
view
-
mergeAndCache
@NotNull public static @NotNull ValueMap mergeAndCache(@NotNull @NotNull java.util.List<ValueMap> valueMaps)
Convenience method that allows creating a mergedValueMap
where accessed mappings are cached to optimize repeated lookups.
This is equivalent to callingcache(merge(valueMaps))
.- Parameters:
valueMaps
- theValueMap
instances to merge- Returns:
- the merged and cached
ValueMap
view
-
cache
@NotNull public static @NotNull ValueMap cache(@NotNull @NotNull ValueMap valueMap)
Decorates the givenValueMap
with a caching layer. Every key-value pair that is accessed is cached for subsequent accesses. Calls toValueMap#keySet()
,ValueMap#values()
andValueMap#entrySet()
will cause all entries to be cached.
Note: if the underlyingValueMap
is modified, the modification may not be reflected via the caching wrapper.- Parameters:
valueMap
- theValueMap
instance to cache- Returns:
- the cached
ValueMap
view
-
-