I've the list in the following format:
int intervalInMinutes = 10;
String startTimeForGrouping = "2017-05-09T15:37:51.896+00:00";
List<MyObject> myObjList = Arrays.asList(
new MyObject("1","a","2017-05-09T15:38:51.896+00:00"),
new MyObject("1","a","2017-05-09T16:41:51.896+00:00"),
new MyObject("1","a","2017-05-09T16:49:51.896+00:00"),
new MyObject("1","a","2017-05-09T16:51:51.896+00:00"),
new MyObject("2","b","2017-05-09T17:38:51.896+00:00"),
new MyObject("2","b","2017-05-09T18:41:51.896+00:00")
);
I've got the list in the above format: I wanted to iterate through that and perform some grouping with an interval from given start time and achieve as follows: In the above list, the group id 1 should return 2 lists.
First 2 objects in the single list because its in the first interval from startTimeForGrouping ("2017-05-09T15:37:51.896+00:00" + intervalInMinutes (10)).
3rd and 4th in a different list because that comes in the next interval ("2017-05-09T15:47:51.896+00:00" + intervalInMinutes (10)). The same logic should repeat for id 2 as well
I have tried this
Map<String, Map<Long, List<MyObject>>> aggrResult =
myObjList.stream()
.collect(
Collectors.groupingBy(
MyObject::getId,
Collectors.groupingBy(eachQueueObj -> eachQueueObj.getIntervalStartTime()/interval)));
but this is wrong because I want to aggregate based on the interval from the given start time.
Please help me since am new to java streaming