Class MapUtils

java.lang.Object
org.ametys.core.util.MapUtils

public final class MapUtils extends Object
Utility methods for Maps
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    deepMerge(Object value1, Object value2)
    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>
    merge(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(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 keys
      V - 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 keys
      V - 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 keys
      V - 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 keys
      V - 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

      public static Object deepMerge(Object value1, Object value2)
      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 merge
      value2 - Second value to merge
      Returns:
      Both values merged if they are maps.