title: Using Stream API to count stats
body: <p>I have following model representing a Snack bar
  SnackBarStat - This has a start date for a booking, number of customers in booking and number of Days(customer can set a start date and say for how many days they want to have table)</p>
  <pre><code>public class SnackBarStat {
    LocalDate startDate;
    int numberOfDays;
    int customers;
  }
  </code></pre>
  <p>Now given a list of such stats I am trying to find for each date how many customer are there in snack bar</p>
  <p><strong>For example if input is</strong></p>
  <pre><code>Start date 13-9-2021, Customers: 2 , numberOfDays: 3
  Start date 12-9-2021, Customers: 3 , numberOfDays: 2
  Start date 13-9-2021, Customers: 1 , numberOfDays: 1
  </code></pre>
  <p><strong>Expected output is</strong></p>
  <pre><code>{2021-09-12=3, 2021-09-13=6, 2021-09-14=2, 2021-09-15=2}
  </code></pre>
  <p>What I have tried so far.
  I have created a simple logic to iterate over each startDate, expand the dates based on numberOfDays and then for each date add them to a map with summing customers on that date</p>
  <pre><code>public class SnackBarOccupanceTest {
    public static void main(String args[]){
      SnackBarStat snackBarStat1 = new SnackBarStat();
      snackBarStat1.setStartDate(LocalDate.of(2021, 9, 13));
      snackBarStat1.setCustomers(2);
      snackBarStat1.setNumberOfDays(3);
  
      SnackBarStat snackBarStat2 = new SnackBarStat();
      snackBarStat2.setStartDate(LocalDate.of(2021, 9, 12));
      snackBarStat2.setCustomers(3);
      snackBarStat2.setNumberOfDays(2);
  
      SnackBarStat snackBarStat3 = new SnackBarStat();
      snackBarStat3.setStartDate(LocalDate.of(2021, 9, 13));
      snackBarStat3.setCustomers(1);
      snackBarStat3.setNumberOfDays(1);
  
      Map&lt;LocalDate, Integer&gt; occupancePerDate = new HashMap&lt;&gt;();
      List&lt;SnackBarStat&gt; snackBarStats = List.of(snackBarStat1, snackBarStat2, snackBarStat3);
      for(SnackBarStat snackBarStat:snackBarStats){
        var expandedDates = expandDates(snackBarStat.getStartDate(), snackBarStat.getNumberOfDays());
        for(LocalDate eachDate : expandedDates){
          if(occupancePerDate.get(eachDate) != null){
            var existingCustomers = occupancePerDate.get(eachDate);
            occupancePerDate.put(eachDate, existingCustomers + snackBarStat.getCustomers());
          }else{
            occupancePerDate.put(eachDate, snackBarStat.getCustomers());
          }
        }
      }
      System.out.println(occupancePerDate);
    }
  
    public static List&lt;LocalDate&gt; expandDates (LocalDate startDate, int numberOfDays){
      List&lt;LocalDate&gt; dateRanges = new ArrayList&lt;&gt;();
      for(int i = 0; i &lt; numberOfDays; i++){
        dateRanges.add(startDate.plusDays(i));
      }
      return dateRanges;
    }
  }
  </code></pre>
  <p>This code works. I was wondering if there was shorter way with stream api to do the same.
  Note the code is just for demo purpose and I have made use of better code practice in actual code.</p>