Class ConfigurationMerger
- java.lang.Object
-
- com.identityworksllc.iiq.common.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...).
-
-
Field Summary
Fields Modifier and Type Field Description static StringNULL_TOKENThe token used to indicate that a value should be removed from the result, rather than merged.static StringREPLACE_TOKENThe token used to replace a value in the target Map
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static sailpoint.object.Attributes<String,Object>mergeConfigurations(Map<String,Object>... inputs)Merges a series of Maps as non-destructively as possible.static List<Object>mergeLists(Object newValues, Object existingValue)Merges two values, one of which must be a Collection.static Map<String,Object>mergeMaps(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.static sailpoint.object.Attributes<String,Object>overlayConfigurations(boolean ignoreNulls, Map<String,Object>... sources)Overlays a series of Maps in a destructive way.
-
-
-
Field Detail
-
NULL_TOKEN
public static final String NULL_TOKEN
The token used to indicate that a value should be removed from the result, rather than merged.- See Also:
- Constant Field Values
-
REPLACE_TOKEN
public static final String REPLACE_TOKEN
The token used to replace a value in the target Map- See Also:
- Constant Field Values
-
-
Method Detail
-
mergeConfigurations
@SafeVarargs public static sailpoint.object.Attributes<String,Object> mergeConfigurations(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<Object> mergeLists(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 listexistingValue- The existing value(s) already in the list- Returns:
- A new List containing the two values merged
-
mergeMaps
public static Map<String,Object> mergeMaps(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 productexistingMap- The existing map, built from this or previous mergers- Returns:
- The merged Map
-
overlayConfigurations
@SafeVarargs public static sailpoint.object.Attributes<String,Object> overlayConfigurations(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 overwritingsources- The list of Map sources- Returns:
- A new Attributes object containing an overlay of each Map
-
-