Created
January 9, 2019 14:12
-
-
Save Adverte/32f74d3f5edbc5f2852566d97ef11bd3 to your computer and use it in GitHub Desktop.
Stream example
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
| list.stream() | |
| .collect(Collectors.collectingAndThen( | |
| Collectors.groupingBy(A::getId, Collector.of( | |
| () -> new A<>(null, 0d, null), (acc, a) -> { | |
| acc.setId(a.getId()); | |
| acc.setQuant(Double.sum(acc.getQuant(), a.getQuant())); | |
| acc.setType(a.getType()); | |
| }, (a1, a2) -> { | |
| a1.setQuant(Double.sum(a1.getQuant(), a2.getQuant())); | |
| return a1; | |
| }, a -> new B<>(a.getId(), new NewClass(a.getQuant(), a.getType()) ) | |
| )), Map::values | |
| )) | |
| // Set .forEach(System.out::println); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment