java – Grouping of articles by date

I have items on my list and the items have a field, which shows the creation date of the item.

enter image description here

and I need to group them based on a “squeeze”, which the user gives. The options are Dayname__, Weekname__, MonthAnd Yearname__.

If the user selects compression dayname__, I need to group my articles in such a way that the elements, which are created on the same day, will be filled. In my example above, only items 1 and 2 are created on the same day. The others are also groups but they will have only one object because in their day only one object is created.

{{item1, item2}, {item3}, {item4}, {item5}, {item6}, {item7}}

If the user selects weekname__:

{{item1, item2, item3, item4}, {item5}, {item6}, {item7}}

If the user selects monthname__:

{{item1, item2, item3, item4, item5}, {item6}, {item7}}

If the user selects yearname__:

{{item1, item2, item3, item4, item5, item6}, {item7}}

After the groups are created, the date of the articles is not important. I mean the key can be anything as long as groups are created.

In case of using Mapname__, I thought like the keys as follows:

day= day of the year
week= week of the year
month= month of the year
year= year

What would be the best solution to this problem? I couldn’t even start it and can’t think of a solution other than iteration.

Leave a comment