aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-05-11 17:44:57 +0200
committerPacien TRAN-GIRARD2016-05-11 17:44:57 +0200
commit4ca823eb709a00ff93c1fdeae7f2bab6865cb73f (patch)
treee75f2bd0e0075e7cf647d9b9b7c502e586f9c892
parenta43d1f0013c7f2cb7595a1fe1a5cfd99a441d0b4 (diff)
downloadxblast-4ca823eb709a00ff93c1fdeae7f2bab6865cb73f.tar.gz
Discard null keys and values on common map operations
-rw-r--r--src/ch/epfl/xblast/Lists.java4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java
index 7e3ba5e..9bd527b 100644
--- a/src/ch/epfl/xblast/Lists.java
+++ b/src/ch/epfl/xblast/Lists.java
@@ -250,6 +250,8 @@ public final class Lists {
250 */ 250 */
251 public static <K, IK, V> Map<K, V> traverseMaps(Map<K, IK> m1, Map<IK, V> m2) { 251 public static <K, IK, V> Map<K, V> traverseMaps(Map<K, IK> m1, Map<IK, V> m2) {
252 return Collections.unmodifiableMap(m1.entrySet().stream() 252 return Collections.unmodifiableMap(m1.entrySet().stream()
253 .filter(e -> Objects.nonNull(e.getValue()))
254 .filter(e -> Objects.nonNull(m2.get(e.getValue())))
253 .collect(Collectors.toMap(Map.Entry::getKey, e -> m2.get(e.getValue())))); 255 .collect(Collectors.toMap(Map.Entry::getKey, e -> m2.get(e.getValue()))));
254 } 256 }
255 257
@@ -263,6 +265,8 @@ public final class Lists {
263 */ 265 */
264 public static <K, V> Map<K, V> invertMap(Map<V, K> m) { 266 public static <K, V> Map<K, V> invertMap(Map<V, K> m) {
265 return Collections.unmodifiableMap(m.entrySet().stream() 267 return Collections.unmodifiableMap(m.entrySet().stream()
268 .filter(e -> Objects.nonNull(e.getKey()))
269 .filter(e -> Objects.nonNull(e.getValue()))
266 .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey))); 270 .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)));
267 } 271 }
268 272