Class ConfigurationMerger


  • public class ConfigurationMerger
    extends Object
    A utility for merging multiple Map objects into a single Attributes-equivalent object.

    This can be used to stack configurations, e.g., overlaying an Application level configuration onto a global system configuration.

    The utility offers two “modes”: overlay and merge. An overlay will simply overwrite values from the later inputs with values from the earlier inputs. Merge is more subtle and will combine values as needed.

    To overlay maps, invoke overlayConfigurations(boolean, Map...).

    To merge maps, invoke mergeConfigurations(Map...).

    • Method Detail

      • mergeConfigurations

        @SafeVarargs
        public static sailpoint.object.Attributes<String,​ObjectmergeConfigurations​(Map<String,​Object>... inputs)
        Merges a series of Maps as non-destructively as possible.

        See mergeMaps(Map, Map) for details on how the merge process works.

        Parameters:
        inputs - The list of Map sources
        Returns:
        A new Attributes object containing an overlay of each Map
      • mergeLists

        public static List<ObjectmergeLists​(Object newValues,
                                              Object existingValue)
        Merges two values, one of which must be a Collection.

        The result will be a merged view of the two values. Any input that is not already a Collection will be passed through toList(Object) for conversion.

        The output will always be a new non-null List. The existing values will be added first, followed by any new values that are not already in the existing values. Duplicate values will not be added.

        Parameters:
        newValues - The new value(s) to add to the merged list
        existingValue - The existing value(s) already in the list
        Returns:
        A new List containing the two values merged
      • mergeMaps

        public static Map<String,​ObjectmergeMaps​(Map<String,​Object> newMap,
                                                         Map<String,​Object> existingMap)
        Merges the ‘new’ Map into the ‘existing’ Map, returning a new Map is that is a merger of the two.

        Neither parameter Map will be modified.

        If both inputs are null, the output will be empty.

        If only the existing Map is null, the output will contain only the ‘new’ values.

        If only the new Map is null, the output will contain only the ‘existing’ values.

        If both Maps are non-null, the following procedure will be applied.

        If the new Map contains the special key ‘_replace’, it is expected to contain a list of field names. The values for those specific keys will be replaced rather than merged in the output, even if a merge would normally be possible.

        For each key:

        • If the new value is null, it will be ignored quietly.
        • If the new value is the string ‘(null)’, with the parens, the corresponding key will be removed from the result.
        • If the existing Map does not already contain that key, the value is inserted as-is.
        • If both new and existing values are Maps, they will be merged via a recursive call to this method
        • If either new or existing values are Collections, they will be merged via mergeLists(Object, Object)
        • Otherwise, the new value will overwrite the old value
        Parameters:
        newMap - The new map to merge into the final product
        existingMap - The existing map, built from this or previous mergers
        Returns:
        The merged Map
      • overlayConfigurations

        @SafeVarargs
        public static sailpoint.object.Attributes<String,​ObjectoverlayConfigurations​(boolean ignoreNulls,
                                                                                             Map<String,​Object>... sources)
        Overlays a series of Maps in a destructive way.

        For each key in each Map, the value in later Maps overlays the value in earlier maps.

        If the input is an empty string or the special value ‘(null)’, and ignoreNulls is false, the key will be removed from the resulting Map unless a later value in the series of Maps inserts a new one. If ignoreNulls is true, these values will be ignored as though they were a null input.

        If ‘ignoreNulls’ is true, null inputs will just be ignored.

        Unlike mergeConfigurations(Map...), collection data is not merged. Lists in later maps will obliterate the values in earlier maps.

        Parameters:
        ignoreNulls - If true, null values in any map will simply be ignored, rather than overwriting
        sources - The list of Map sources
        Returns:
        A new Attributes object containing an overlay of each Map