Created
July 2, 2015 10:05
-
-
Save dwursteisen/e8531e6407e8b7600e27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etl; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.stream.Collectors; | |
/** | |
* Created by david.wursteisen on 02/07/2015. | |
*/ | |
public class Etl { | |
public static Map<String, Integer> transform(Map<Integer, List<String>> old) { | |
return old.entrySet() | |
.stream() | |
.flatMap(e -> e.getValue().stream().flatMap(s -> { | |
HashMap<String, Integer> result = new HashMap<>(); | |
result.put(s, e.getKey()); | |
return result.entrySet().stream(); | |
})) | |
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | |
} | |
public static void main(String[] args) { | |
HashMap<Integer, List<String>> map = new HashMap<>(); | |
map.put(1, Arrays.asList("1", "2", "3")); | |
map.put(2, Arrays.asList("4", "5", "6")); | |
transform(map).entrySet().stream().forEach(System.out::println); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment