Created
April 23, 2019 14:56
-
-
Save beall49/d96b4dfa6cc2c8e1782d808caf6ec55c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private static Map<String, List<SomeObject>> groupListToMapById(List<SomeObject> items) { | |
return items.stream() | |
.collect(groupingBy(SomeObject::getId, toList())) | |
.entrySet() | |
.stream() | |
.collect(toMap( | |
Map.Entry::getKey, | |
Map.Entry::getValue, | |
(a, b) -> {throw new AssertionError();}, | |
LinkedHashMap::new | |
)); | |
} | |
private static List<SomeObject> getListFromMap(Map<String, List<SomeObject>> items) { | |
return items.values().stream() | |
.filter(e -> !e.isEmpty()) | |
.flatMap(Collection::stream) | |
.collect(toList()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment