Java Utililty Methods Map Merge

List of utility methods to do Map Merge

Description

The list of methods to do Map Merge are organized into topic(s).

Method

voidmergeEnv(Map newEnv, Map env)
merge Env
if (env != null) {
    env.forEach((k, v) -> newEnv.put(k, v));
voidmergeEnvironmentVariables(Map environmentSource, Map environmentDestination, String environmentVariable)
merge Environment Variables
if (environmentSource == null) {
    return;
if (environmentSource.containsKey(environmentVariable)) {
    environmentDestination.put(environmentVariable, environmentDestination.get(environmentVariable) + ":"
            + environmentSource.get(environmentVariable));
voidmergeFamilies(Map familySource, Map familyTarget)
merge Families
if (familySource == null) {
    return;
for (K key : familySource.keySet()) {
    if (!familyTarget.containsKey(key)) {
        familyTarget.put(key, familySource.get(key));
    } else {
        if (familyTarget.get(key).getClass() == Integer.class) {
...
Map>mergeFixedValueConditions(Map> left, Map> right)
merge Fixed Value Conditions
right.keySet().forEach(columnName -> {
    Set<Object> newValues = right.get(columnName);
    if (newValues != null) {
        left.merge(columnName, newValues, (l, r) -> new HashSet<Object>() {
                addAll(l);
                addAll(r);
        });
});
return left;
voidmergeIfAbsent(Map map, Map toMerge)
Add all values of a map to another map, but onlfy if not already existing.
for (Map.Entry<String, String> entry : toMerge.entrySet()) {
    putIfAbsent(map, entry.getKey(), entry.getValue());
    ;
MapmergeImportedPermissionsWithExistingPermissions( Map> existingRoleIdsToActionIds, Map importedRoleIdsToActionIds)
merge Imported Permissions With Existing Permissions
Map<Long, String[]> mergedRoleIdsToActionIds = new HashMap<>();
for (Map.Entry<Long, Set<String>> roleIdsToActionIds : existingRoleIdsToActionIds.entrySet()) {
    long roleId = roleIdsToActionIds.getKey();
    if (importedRoleIdsToActionIds.containsKey(roleId)) {
        String[] actionIds = importedRoleIdsToActionIds.remove(roleId);
        mergedRoleIdsToActionIds.put(roleId, actionIds);
    } else {
        mergedRoleIdsToActionIds.put(roleId, new String[0]);
...
MapmergeListWithMap(List from, Map to)
merge List With Map
for (Integer value : from) {
    Integer count = to.get(value);
    to.put(value, (count != null ? count + 1 : 1));
return to;
MapmergeMap(Map map, Object[]... pairs)
Merges the map with the new value and returns a new map.
if (map == null) {
    map = new HashMap();
Map newMap = new HashMap(map);
for (Object[] pair : pairs) {
    newMap.put(pair[0], pair[1]);
return newMap;
...
PropertiesmergeMap(Map primaryValues, Map defaultValues)
Create a list of Properties containing all keys from two lists of given Propertiess.
Properties result = new Properties();
if (defaultValues != null) {
    result.putAll(defaultValues);
if (primaryValues != null) {
    result.putAll(primaryValues);
return result;
...
MapmergeMap(Map first, Map second)
Merge in one map to another -all entries in the second map are merged into the first -overwriting any duplicate keys.
first.putAll(second);
return first;