com.wizzdi.dynamic.properties.converter.DynamicPropertiesUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamic-properties-database-converter Show documentation
Show all versions of dynamic-properties-database-converter Show documentation
Dynamic properties database converter
The newest version!
package com.wizzdi.dynamic.properties.converter;
import java.util.HashMap;
import java.util.Map;
public class DynamicPropertiesUtils {
/**
* returns a set of merged values from two maps if there was an update otherwise null
* @param newVals incoming values
* @param current existing values
* @return merged map or null
*/
public static Map updateDynamic(Map newVals, Map current) {
boolean update = false;
if (newVals != null && !newVals.isEmpty()) {
if (current == null) {
return newVals;
} else {
Map copy = new HashMap<>(current);
for (Map.Entry entry : newVals.entrySet()) {
String key = entry.getKey();
Object newVal = entry.getValue();
Object val = current.get(key);
if ((newVal==null&&val!=null)|| (newVal!=null&&!newVal.equals(val))) {
copy.put(key, newVal);
update = true;
}
}
if (update) {
return copy;
}
}
}
return null;
}
}