Created
July 10, 2020 16:55
-
-
Save Adverte/836d6592128028d6ad33256ac7a672b3 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
| 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