/** * 把list转为map 方便查找 * * @param list 数据库有效数据列表 * @return map */ private <T extends TrendValue> Map<String, T> tomap(List<T> list) { Map<String, T> map = new LinkedHashMap<>(); for (T value : list) { map.put(value.getDate(), value); } return map; }
/** * 填充数据 * * @param list 数据库有效数据列表 * @return 填充的数据 */ private <T extends TrendValue> List<T> fulldata( List<T> list, DateFormat format, int field, Date start, Date end, Class<T> clazz) { Map<String, T> map = tomap(list); Calendar calendar = Calendar.getInstance(); calendar.setTime(start); List<T> nlist = new ArrayList<>(); while (calendar.getTime().before(end)) { String keytime = format.format(calendar.getTime()); T value = map.get(keytime); if (value == null) { value = AfReflecter.newInstance(clazz); value.setEmpty(); value.setDate(keytime); value.setTime(calendar.getTime()); nlist.add(value); } else { nlist.add(value); map.remove(keytime); } calendar.add(field, 1); } for (Map.Entry<String, T> entry : map.entrySet()) { nlist.add(entry.getValue()); } return nlist; }