Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>java.util.Date is a quite poor abstraction for your need; it is IMO fair to stick to strings if nothing better is around, HOWEVER <a href="http://joda-time.sourceforge.net/" rel="nofollow noreferrer">Joda-time</a> provides a good datatype for you: <a href="http://joda-time.sourceforge.net/api-release/org/joda/time/DateMidnight.html" rel="nofollow noreferrer">DateMidnight</a> or alternatively <a href="http://joda-time.sourceforge.net/api-release/org/joda/time/LocalDate.html" rel="nofollow noreferrer">LocalDate</a> if Activity is strictly timezome-independant.</p> <p>other than that, the code looks good to me, you might be able to shorten it a bit using an implementation of <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Multimap.html" rel="nofollow noreferrer">Multimap</a>, to avoid messy null-checking code. to be honest, it doesn't get much shorter than your solution:</p> <pre><code> public List&lt;Activity&gt; groupedByDate(List&lt;Activity&gt; input) { //group by day final Multimap&lt;DateMidnight, Activity&gt; activityByDay = Multimaps.index(input, new Function&lt;Activity, DateMidnight&gt;() { @Override public DateMidnight apply(Activity from) { return new DateMidnight(from.activityDate); } }); //for each day, sum up amount List&lt;Activity&gt; ret = Lists.newArrayList(); for (DateMidnight day : activityByDay.keySet()) { Activity ins = new Activity(); ins.activityDate = day.toDate(); for (Activity activity : activityByDay.get(day)) { ins.amount+=activity.amount; } } return ret; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload