All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wizzdi.dynamic.properties.converter.DynamicPropertiesUtils Maven / Gradle / Ivy

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy