Commit 03c278e1 authored by yanzg's avatar yanzg

默认日期格式的支持

parent 68830845
......@@ -22,10 +22,9 @@ public class DataDaoVo<T> {
*
* @param hisitories 历史数据
* @param keyFunc  获取主键函数
* @param <T>
* @return
*/
private static <T> Map<String, T> getMapHistory(List<T> hisitories, DataDaoKey<T> keyFunc) {
private Map<String, T> getMapHistory(List<T> hisitories, DataDaoKey<T> keyFunc) {
// 定义缓存集合
Map<String, T> mapHistory = new HashMap<>(10);
// 历史数据处理
......@@ -44,33 +43,31 @@ public class DataDaoVo<T> {
* @param mapHistory 历史数据映射
* @param nows  当前数据
* @param keyFunc  获取主键函数
* @param <T>
* @return
*/
private static <T> DataDaoVo<T> getResult(Map<String, T> mapHistory, List<T> nows, DataDaoKey<T> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>();
private void addResult(Map<String, T> mapHistory, List<T> nows, DataDaoKey<T> keyFunc) {
// 返回集
if (nows != null) {
for (T now : nows) {
String key = keyFunc.getKey(now);
T his = mapHistory.get(key);
if (his == null) {
res.creates.add(now);
res.mapNow.put(key, now);
this.creates.add(now);
this.mapNow.put(key, now);
} else {
mapHistory.remove(key);
boolean isChange = keyFunc.set(his, now);
if (isChange) {
res.updates.add(his);
this.updates.add(his);
}
res.mapNow.put(key, his);
this.mapNow.put(key, his);
}
}
}
res.removes.addAll(mapHistory.values());
return res;
this.removes.addAll(mapHistory.values());
}
/**
* 初始话对象
*
......@@ -78,10 +75,9 @@ public class DataDaoVo<T> {
* @param nows
* @param keyFunc
*/
public static <T> DataDaoVo<T> init(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) {
public void add(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) {
Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc);
DataDaoVo<T> res = getResult(mapHistory, nows, keyFunc);
return res;
addResult(mapHistory, nows, keyFunc);
}
......@@ -92,7 +88,7 @@ public class DataDaoVo<T> {
* @param nows
* @param keyFunc
*/
public static <T, M> DataDaoVo<T> init(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) {
public <M> void add(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) {
Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc);
List<T> toNows = new ArrayList<>(10);
if (nows != null) {
......@@ -101,7 +97,33 @@ public class DataDaoVo<T> {
toNows.add(t);
}
}
DataDaoVo<T> res = getResult(mapHistory, toNows, keyFunc);
addResult(mapHistory, toNows, keyFunc);
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public static <T> DataDaoVo<T> init(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>();
res.add(hisitories, nows, keyFunc);
return res;
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public static <T, M> DataDaoVo<T> init(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>();
res.add(hisitories, nows, keyFunc);
return res;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment