日期:2014-05-19 浏览次数:20723 次
import java.util.Date; public class Disple { private Date time; private int number; public Date getTime() { return time; } public void setTime(Date time) { this.time = time; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } }
import java.util.ArrayList; import java.util.List; public class Silmpe { public List<Disple> disple_summary(List<Disple> list_ds) { List<Disple> list_dres = new ArrayList<Disple>(); for (int i = 0; i < list_ds.size(); i++) { Disple dis = list_ds.get(i); int _tmp = 0; boolean flag = false; Disple dis_res = new Disple(); if ((i + 1) != list_ds.size()) { if (dis.getTime() == list_ds.get(i + 1).getTime()) { _tmp += dis.getNumber(); flag = true; } else { dis_res.setTime(dis.getTime()); dis_res.setNumber(_tmp + dis.getNumber()); list_dres.add(dis_res); _tmp = 0; } } if ((i + 1) == list_ds.size() && flag == true) { dis_res.setTime(list_ds.get(list_ds.size() - 1).getTime()); dis_res.setNumber(_tmp + list_ds.get(list_ds.size() - 1).getNumber()); list_dres.add(dis_res); } } return list_dres; } }