Created
January 9, 2019 14:12
-
-
Save Adverte/32f74d3f5edbc5f2852566d97ef11bd3 to your computer and use it in GitHub Desktop.
Revisions
-
Adverte renamed this gist
Jan 9, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Adverte created this gist
Jan 9, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ 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);