代码优化
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
package handler;
|
||||
|
||||
import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import util.MapUtil;
|
||||
import util.SetUtil;
|
||||
|
||||
@@ -25,8 +25,7 @@ public class MapHandler {
|
||||
public static boolean putValue(Object originChange, Object targetChange, Object originValue, Object targetValue,
|
||||
MethodAccess methodAccess, String setName) throws IllegalAccessException, InstantiationException {
|
||||
|
||||
//这边也只处理只有一个map可能为空的情况,全部为空在前面的方法做了处理
|
||||
if (SelfHandler.isOneNull(originChange, originChange, targetValue, originValue, methodAccess, setName)) {
|
||||
if (SelfHandler.isOneNull(originChange, targetChange, originValue, targetValue, methodAccess, setName)) {
|
||||
return true;
|
||||
}
|
||||
//参数前置
|
||||
@@ -52,25 +51,31 @@ public class MapHandler {
|
||||
|
||||
//得到不一致的key的集合.
|
||||
List<Map.Entry> originList = SetUtil.findUnLikeValue(originEntry, targetEntry);
|
||||
List<Map.Entry> changeList = SetUtil.findUnLikeValue(originEntry, targetEntry);
|
||||
List<Map.Entry> changeList = SetUtil.findUnLikeValue(targetEntry, originEntry);
|
||||
//计算changed的值
|
||||
changed = changed || !CollectionUtils.isEmpty(originList) || !CollectionUtils.isEmpty(changeList);
|
||||
//把不一致的值设置会新的Map中
|
||||
MapUtil.putIfNotEmpty(originMap, originList);
|
||||
MapUtil.putIfNotEmpty(targetMap, changeList);
|
||||
//对对象进行设值
|
||||
methodAccess.invoke(originChange, setName, originValue);
|
||||
methodAccess.invoke(targetChange, setName, targetValue);
|
||||
methodAccess.invoke(originChange, setName, originMap);
|
||||
methodAccess.invoke(targetChange, setName, targetMap);
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较Map中同一个key对应的两个value,如果不相等则将差异设入对应的Map
|
||||
*/
|
||||
private static boolean putValue(Object value, Object tValue, Map<Object, Object> originMap,
|
||||
Map<Object, Object> targetMap, Object key) {
|
||||
if (value.equals(tValue)) {
|
||||
if (value == null && tValue == null) {
|
||||
return false;
|
||||
}
|
||||
originMap.put(key, value);
|
||||
targetMap.put(key, tValue);
|
||||
return true;
|
||||
if (value == null || tValue == null || !value.equals(tValue)) {
|
||||
originMap.put(key, value);
|
||||
targetMap.put(key, tValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user