title: java8 stream grouping aggregate
body: <p>Given a java class <code>Something</code></p>
  
  <pre><code>class Something {
       String parent;
       String parentName;
       String child;
       Date at;
       int noThings;
  
       Something(String parent, String parentName, String child, Date at, int noThings) {
            this.parent = parent;
            this.parentName = parentName;
            this.child = child;
            this.at = at;
            this.noThings = noThings;
        }
  
        String getParent() { return parent; }
        String getChild() { return child; }
        int getNoThings() { return noThings; }
  }
  </code></pre>
  
  <p>I have a list of something objects, </p>
  
  <pre><code>List&lt;Something&gt; hrlySomethings = Arrays.asList(
      new Something("parent1", "pname1", "child1", new Date("01-May-2015 10:00:00"), 4),
      new Something("parent1", "pname1", "child1", new Date("01-May-2015 12:00:00"), 2),
      new Something("parent1", "pname1", "child1", new Date("01-May-2015 17:00:00"), 8),
      new Something("parent1", "pname1", "child2", new Date("01-May-2015 07:00:00"), 12),
      new Something("parent1", "pname1", "child2", new Date("01-May-2015 17:00:00"), 14),
      new Something("parent2", "pname2", "child3", new Date("01-May-2015 11:00:00"), 3),
      new Something("parent2", "pname2", "child3", new Date("01-May-2015 16:00:00"), 2));
  </code></pre>
  
  <p>I want to group the objects by parent and children and then find the total/sum of the "noThings" field for the last 24 hours.</p>
  
  <pre><code>List&lt;Something&gt; dailySomethings = Arrays.asList(
      new Something("parent1", "pname1", "child1", new Date("01-May-2015 00:00:00"), 14),
      new Something("parent1", "pname1", "child2", new Date("01-May-2015 00:00:00"), 26),
      new Something("parent2", "pname2", "child3", new Date("01-May-2015 00:00:00"), 5))
  </code></pre>
  
  <p>I'm trying to use the streams to do this</p>
  
  <p>I can figure out how to use the grouping to get a map of maps, and the total</p>
  
  <pre><code>    Map&lt;String,Map&lt;String,IntSummaryStatistics&gt;&gt; daily =
          hrlySomethings.stream().collect(
      Collectors.groupingBy(Something ::getParent, 
      Collectors.groupingBy(ClientCollectionsReceived::getChild,
      Collectors.summarizingInt(ClientCollectionsReceived::getNoThings))));
  </code></pre>
  
  <p>I can figure out how to get a distinct list based on parent and child,</p>
  
  <pre><code>    Date startHour = "01-May-2015 00:00:00";
      int totalNoThings = 0; // don't know how to put sum in here
      List&lt;Something&gt; newList 
        = hrlySomethings.stream()
              .map((Something other) -&gt; {
                      return new Something(other.getParent(),
                      other.getChild(), startHour, totalNoThings);
                  })
              .distinct()
              .collect(Collectors.toList());
  </code></pre>
  
  <p>But I don't know how to combine the two to get the distinct list, with the totals.  Is this possible?</p>