Package org.ametys.core.util
Class MapUtils
java.lang.Object
org.ametys.core.util.MapUtils
Utility methods for
Map
s-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Function to merge deeply two maps.static <K,
V> Map<K, V> merge
(BinaryOperator<V> mergeFunction, Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2) Merges the entries of two maps into one map.static <K,
V> Map<K, V> merge
(BinaryOperator<V> mergeFunction, Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2, Map<? extends K, ? extends V>... others) Merges the entries of several maps into one map.static <K,
V> Map<K, V> Merges the entries of two maps into one map.static <K,
V> Map<K, V> merge
(Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2, Map<? extends K, ? extends V>... others) Merges the entries of several maps into one map.
-
Method Details
-
merge
public static <K,V> Map<K,V> merge(Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2) Merges the entries of two maps into one map. Entries of the first one have the priority (i.e. kept if same keys) over ones of the second one.- Type Parameters:
K
- The type of the keysV
- The type of the values- Parameters:
map1
- The first map (not modified)map2
- The second map (not modified)- Returns:
- The merged map
-
merge
@SafeVarargs public static <K,V> Map<K,V> merge(Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2, Map<? extends K, ? extends V>... others) Merges the entries of several maps into one map. Entries of any input map one have the priority (i.e. kept if same keys) over ones of any following map.- Type Parameters:
K
- The type of the keysV
- The type of the values- Parameters:
map1
- The first map (not modified)map2
- The second map (not modified)others
- The other maps (not modified)- Returns:
- The merged map
-
merge
public static <K,V> Map<K,V> merge(BinaryOperator<V> mergeFunction, Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2) Merges the entries of two maps into one map.- Type Parameters:
K
- The type of the keysV
- The type of the values- Parameters:
mergeFunction
- The merging function, to determine which value of the entry to keep when same keys are encountered.map1
- The first map (not modified)map2
- The second map (not modified)- Returns:
- The merged map
-
merge
@SafeVarargs public static <K,V> Map<K,V> merge(BinaryOperator<V> mergeFunction, Map<? extends K, ? extends V> map1, Map<? extends K, ? extends V> map2, Map<? extends K, ? extends V>... others) Merges the entries of several maps into one map. Entries of any input map one have the priority (i.e. kept if same keys) over ones of any following map.- Type Parameters:
K
- The type of the keysV
- The type of the values- Parameters:
mergeFunction
- The merging function, to determine which value of the entry to keep when same keys are encountered.map1
- The first map (not modified)map2
- The second map (not modified)others
- The other maps (not modified)- Returns:
- The merged map
-
deepMerge
Function to merge deeply two maps. If the two values are maps, they are merged, but if not, value1 is returned. This operation is done recursively.- Parameters:
value1
- First value to mergevalue2
- Second value to merge- Returns:
- Both values merged if they are maps.
-