package org.openslx.dozmod.util; import java.util.Map; import java.util.Map.Entry; import org.apache.log4j.Logger; public class MapHelper { private static final Logger LOGGER = Logger.getLogger(MapHelper.class); private MapHelper() { } public static boolean hasChanged(final Map oldMap, final Map newMap) { return compare(oldMap, newMap) != 0; } public static int compare(final Map oldMap, final Map newMap) { if (oldMap == null && newMap == null) return 0; if (oldMap == null) return -1; if (newMap == null) return 1; if (oldMap.size() != newMap.size()) return oldMap.size() - newMap.size(); // Same amount of entries, check if any entry changed int retval = 0; for (Entry entry : oldMap.entrySet()) { T current = entry.getValue(); T other = newMap.get(entry.getKey()); if (other == null) { retval -= 1; continue; } retval += current.hashCode() - other.hashCode(); } return retval; } }