blob: e99b1aa6f3bb033d3fb622e665c654c27c1574ed (
plain) (
tree)
|
|
package org.openslx.dozmod.util;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.log4j.Logger;
public class MapHelper {
private static final Logger LOGGER = Logger.getLogger(MapHelper.class);
private MapHelper() {}
public static <T> boolean hasChanged(final Map<String, T> oldMap, final Map<String, T> newMap) {
// build list of users that were added, if any return true
if (oldMap.size() != newMap.size())
return true;
// no changes in the users, lets check for changes in each users permissions
for (Entry<String, T> entry : oldMap.entrySet()) {
T current = entry.getValue();
T other = newMap.get(entry.getKey());
if (!current.equals(other))
return true;
}
// everything was the same if we are still here
return false;
}
private static <T> Set<String> getAddedUsers(final Map<String, T> oldMap, final Map<String, T> newMap) {
Set<String> addedUsers = new HashSet<String>(newMap.keySet());
addedUsers.removeAll(oldMap.keySet());
return addedUsers;
}
private static <T> Set<String> getRemovedUsers(final Map<String, T> oldMap, final Map<String, T> newMap) {
Set<String> removedUsers = new HashSet<String>(oldMap.keySet());
removedUsers.removeAll(newMap.keySet());
return removedUsers;
}
}
|