0

I have a Map<String, BigDecimal> queryMap that is populated by JPA to list how many occurences of a database entry exists per day. JPA returns trunc(date) as Date - objects, and the String in the map is Key, added by Date.toString() The Map looks like this:

    String              BigDecimal
    ------------------- -------------- 
    1998-01-01 00:00:00 221            
    1998-05-24 00:00:00 2              
    1999-02-01 00:00:00 1              
    1999-06-01 00:00:00 2              
    1999-07-05 00:00:00 1              
    1999-08-02 00:00:00 1              
    2000-02-21 00:00:00 1              
    2000-02-28 00:00:00 1              
    2000-03-06 00:00:00 1              
    2000-06-19 00:00:00 1              
    2000-08-21 00:00:00 1              
    2000-10-12 00:00:00 1              
    2000-10-16 00:00:00 2              
    2000-10-30 00:00:00 1              
    2001-01-01 00:00:00 7              
    2001-06-30 00:00:00 1
    .....

The case is that the occurrences should be grouped by Week of year, so that I need to parse the String back to some form of Date, find out what week they are member of and then add the sum of value() back to another Map<String, Number> to get something like

String          Number
--------------- ----------
W1              15
W2              2
W3              17
W4              15
W5              2
W6              17
...
W52 (if exists) 11

The purpose of this is so that I can present a comparision by passing different date - ranges to the query,and get groupings of occurrences by Week of Year

(The objects in the Map are required by the chart implementation that is rendering the Map...)

I have searched for answers, but most involve using Lists and not Map, and to my understanding, Date - handling in Java is a mixed bag of tricks. I can utilize Java 8 - features and one can assume that all dates are belonging to the local timezone.

korgmatose
  • 265
  • 4
  • 17

0 Answers0