From 4ca823eb709a00ff93c1fdeae7f2bab6865cb73f Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 11 May 2016 17:44:57 +0200 Subject: Discard null keys and values on common map operations --- src/ch/epfl/xblast/Lists.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') 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 { */ public static Map traverseMaps(Map m1, Map m2) { return Collections.unmodifiableMap(m1.entrySet().stream() + .filter(e -> Objects.nonNull(e.getValue())) + .filter(e -> Objects.nonNull(m2.get(e.getValue()))) .collect(Collectors.toMap(Map.Entry::getKey, e -> m2.get(e.getValue())))); } @@ -263,6 +265,8 @@ public final class Lists { */ public static Map invertMap(Map m) { return Collections.unmodifiableMap(m.entrySet().stream() + .filter(e -> Objects.nonNull(e.getKey())) + .filter(e -> Objects.nonNull(e.getValue())) .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey))); } -- cgit v1.2.3