/**
* 数据集合list的中对象 每隔time时间分一组
* @param list 数据集
* @param time 时间戳 毫秒 60 * 60 * 1000
* @return
*/
public static Map<Integer,List<Ph>> get(List<Ph> list, Long time){
Map<Integer,List<Ph>> map=new HashMap<>();
long startTime = list.get(0).getLocalTime().toEpochSecond(ZoneOffset.of("+8"));
long endTime = list.get(list.size()-1).getLocalTime().toEpochSecond(ZoneOffset.of("+8"));
int i=0;
while (startTime < endTime) {
long finalStartTime = startTime;
List<Ph> valueDtoList = list.stream().filter(s -> s.getLocalTime().toEpochSecond(ZoneOffset.of("+8")) >= finalStartTime &&
s.getLocalTime().toEpochSecond(ZoneOffset.of("+8")) <= finalStartTime+time).collect(Collectors.toList());
System.err.println(String.format("开始时间戳:{} 结束时间戳:{}", startTime ,startTime+time));
map.put(i,valueDtoList);
i++;
startTime += time;
}
return map;
}
java list集合根据时间戳来分组(list集合中有1万数据等)
最新推荐文章于 2024-06-18 15:38:31 发布