Package org.apache.sling.api.wrappers

# Class ValueMapUtil

java.lang.Object
org.apache.sling.api.wrappers.ValueMapUtil

public final class ValueMapUtil extends Object
Factory methods to create `ValueMap`s.

Since:
  2.7

## Method Summary

Modifier and Type
Method
Description
`static @NotNull ValueMap`
`cache(@NotNull ValueMap valueMap)`
Decorates the given `ValueMap` with a caching layer.
`static @NotNull ValueMap`
`merge(@NotNull List<ValueMap> valueMaps)`
Merge provided `ValueMaps` into a single view `ValueMap` 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 a `Collection` and delegates to `merge(List)`.
`static @NotNull ValueMap`
`mergeAndCache(@NotNull List<ValueMap> valueMaps)`
Convenience method that allows creating a merged `ValueMap` where accessed mappings are cached to optimize repeated lookups.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### merge

@NotNull public static @NotNull ValueMap merge(@NotNull @NotNull ValueMap... valueMaps)
A convenience method that turns the var-args into a `Collection` and delegates to `merge(List)`.

Parameters:
  `valueMaps` - the `ValueMap` instances to merge
Returns:
  the merged `ValueMap` view
See Also:
  - `merge(List)`

### merge

@NotNull public static @NotNull ValueMap merge(@NotNull @NotNull List<ValueMap> valueMaps)
Merge provided `ValueMaps` into a single view `ValueMap` that aggregates all key-value pairs of the given maps. The value for a key-value pair is taken from the first `ValueMap` (in iteration order) that has a mapping for the given key.
E.g. assuming `merge(vm1, vm2, vm3` where all maps `vm1, vm2, vm3` have a value mapped to the key `k1`, then the value from `vm1` is returned.

Parameters:
  `valueMaps` - the `ValueMap` instances to merge
Returns:
  the merged `ValueMap` view

### mergeAndCache

@NotNull public static @NotNull ValueMap mergeAndCache(@NotNull @NotNull List<ValueMap> valueMaps)
Convenience method that allows creating a merged `ValueMap` where accessed mappings are cached to optimize repeated lookups.
This is equivalent to calling `cache(merge(valueMaps))`.

Parameters:
  `valueMaps` - the `ValueMap` instances to merge
Returns:
  the merged and cached `ValueMap` view

### cache

@NotNull public static @NotNull ValueMap cache(@NotNull @NotNull ValueMap valueMap)
Decorates the given `ValueMap` with a caching layer. Every key-value pair that is accessed is cached for subsequent accesses. Calls to `ValueMap#keySet()`, `ValueMap#values()` and `ValueMap#entrySet()` will cause all entries to be cached.
Note: if the underlying `ValueMap` is modified, the modification may not be reflected via the caching wrapper.

Parameters:
  `valueMap` - the `ValueMap` instance to cache
Returns:
  the cached `ValueMap` view