Skip to content

Instantly share code, notes, and snippets.

@Adverte
Created January 9, 2019 14:12
Show Gist options
  • Select an option

  • Save Adverte/32f74d3f5edbc5f2852566d97ef11bd3 to your computer and use it in GitHub Desktop.

Select an option

Save Adverte/32f74d3f5edbc5f2852566d97ef11bd3 to your computer and use it in GitHub Desktop.

Revisions

  1. Adverte renamed this gist Jan 9, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Adverte created this gist Jan 9, 2019.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original 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);