public List getForStatisticDayToTimeList(String day) {
List newList = new ArrayList(); //组建新的List
List list = this.getStatisticDao().getForStatisticDayToTimeList(day); //查询统计List;
Iterator iterator = list.iterator();
String time[] = new String[] { "0:00 - 1:00", "1:00 - 2:00",
"2:00 - 3:00", "3:00 - 4:00", "4:00 - 5:00", "5:00 - 6:00",
"6:00 - 7:00", "7:00 - 8:00", "8:00 - 9:00", "9:00 - 10:00",
"10:00 - 11:00", "11:00 - 12:00", "12:00 - 13:00",
"13:00 - 14:00", "14:00 - 15:00", "15:00 - 16:00",
"16:00 - 17:00", "17:00 - 18:00", "18:00 - 19:00",
"19:00 - 20:00", "20:00 - 21:00", "21:00 - 22:00",
"22:00 - 23:00", "23:00 - 24:00" }; //时间数组
int i = 0;
StatisticDayObj statisticTimeIsNull = null;
while (iterator.hasNext()) {
StatisticDayObj statisticTime = (StatisticDayObj) iterator.next(); // 每个时间段统计的数据
int TimeForClock = Integer.parseInt(statisticTime.getVisitTime()); // 统计时间
if (TimeForClock != i) {//填充空的时间段数据
while (true) {
if (TimeForClock == i) {
break;
} else {
statisticTimeIsNull = new StatisticDayObj();
statisticTimeIsNull.setVisitTime(time[i]);
statisticTimeIsNull.setVisiterAvgCount(0.0);
statisticTimeIsNull.setVisiterCount(0);
statisticTimeIsNull.setPageCount(0);
statisticTimeIsNull.setIpCount(0);
newList.add(statisticTimeIsNull);
i++;
}
}
}
if (statisticTime.getVisiterCount() != 0){ // 除数不能为0
statisticTime.setVisiterAvgCount(statisticTime.getPageCount()/ (double) statisticTime.getVisiterCount());
}
statisticTime.setVisitTime(time[TimeForClock]); //格式化时间
newList.add(statisticTime);
i++;
}
return newList;
}
测试,打印如下:
0:00 - 1:00
0
0.0
0
0
1:00 - 2:00
0
0.0
0
0
2:00 - 3:00
0
0.0
0
0
3:00 - 4:00
0
0.0
0
0
4:00 - 5:00
0
0.0
0
0
5:00 - 6:00
2
1.0
2
1
6:00 - 7:00
0
0.0
0
0
7:00 - 8:00
1
1.0
1
1
8:00 - 9:00
0
0.0
0
0
9:00 - 10:00
0
0.0
0
0
10:00 - 11:00
0
0.0
0
0
11:00 - 12:00
1
1.0
1
1
12:00 - 13:00
0
0.0
0
0
13:00 - 14:00
1
1.0
1
1
14:00 - 15:00
0
0.0
0
0
15:00 - 16:00
2
1.0
2
1
16:00 - 17:00
0
0.0
0
0
17:00 - 18:00
1
13.0
13
1
18:00 - 19:00
2
1.0
2
1
19:00 - 20:00
0
0.0
0
0
20:00 - 21:00
1
1.0
1
1
21:00 - 22:00
0
0.0
0
0
22:00 - 23:00
1
1.0
1
1