diff options
author | Jonathan Bauer | 2015-09-11 18:25:38 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-09-11 18:25:38 +0200 |
commit | db0cd92c5dd0b87c160f6b48370ce1f26896a5f6 (patch) | |
tree | 05604920e5026c255cb3fdbea93a48ad0222ae6f /dozentenmodul/src/main/java/org/openslx/dozmod/util/MapHelper.java | |
parent | [client] return a bool for success in UpdatePermissions for Images (diff) | |
download | tutor-module-db0cd92c5dd0b87c160f6b48370ce1f26896a5f6.tar.gz tutor-module-db0cd92c5dd0b87c160f6b48370ce1f26896a5f6.tar.xz tutor-module-db0cd92c5dd0b87c160f6b48370ce1f26896a5f6.zip |
[client] Image/Lectures: only push metadata/permissions if they were changed
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/MapHelper.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/MapHelper.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/MapHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/MapHelper.java new file mode 100644 index 00000000..e99b1aa6 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/MapHelper.java @@ -0,0 +1,41 @@ +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; + } +} |