Map<Long, ThroughputInfo> throughputInfos = new LinkedHashMap<Long, ThroughputInfo>();
List<ThroughputStatDO> throughputStatDOs = throughputDao.listTimelineThroughputStat(condition);
int size = throughputStatDOs.size();
int k = size - 1;
for (Long i = condition.getStart().getTime(); i <= condition.getEnd().getTime(); i += 60 * 1000) {
ThroughputInfo throughputInfo = new ThroughputInfo();
List<ThroughputStat> throughputStat = new ArrayList<ThroughputStat>();
// 取出每个时间点i以内的数据,k是一个游标,每次遍历时前面已经取过了的数据就不用再遍历了
for (int j = k; j >= 0; --j) {
if ((i - throughputStatDOs.get(j).getEndTime().getTime() <= 60 * 1000)
&& (i - throughputStatDOs.get(j).getEndTime().getTime() >= 0)) {
throughputStat.add(throughputStatDOToModel(throughputStatDOs.get(j)));
k = j - 1;
}// 如果不满足if条件,则后面的数据也不用再遍历
else {
break;
}
}
if (throughputStat.size() > 0) {
throughputInfo.setItems(throughputStat);
throughputInfo.setSeconds(1 * 60L);
throughputInfos.put(i, throughputInfo);
}
}
return throughputInfos;