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

io.quarkus.test.utils.MapUtils Maven / Gradle / Ivy

The newest version!
package io.quarkus.test.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.codec.binary.StringUtils;

public final class MapUtils {

    private MapUtils() {

    }

    public static Map difference(Map newMap, Map oldMap) {
        if (oldMap == null) {
            return newMap;
        }

        Map differences = new HashMap<>();
        // Add new or changed entries
        for (Entry newEntry : newMap.entrySet()) {
            String oldValue = oldMap.get(newEntry.getKey());
            if (oldValue == null || !StringUtils.equals(newEntry.getValue(), oldValue)) {
                differences.put(newEntry.getKey(), newEntry.getValue());
            }
        }

        // Add entries that are not in the new map
        for (Entry oldEntry : oldMap.entrySet()) {
            if (!newMap.containsKey(oldEntry.getKey())) {
                differences.put(oldEntry.getKey(), oldEntry.getValue());
            }
        }

        return differences;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy