feat(Java_ConstractUtil):添加测试方法,修改bug(反射处理null出现空指针的问题比较多),创建抽象类和继承使用示例。添加readme修改记录
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
<javax.version>7.0</javax.version>
|
||||
<junit.version>4.11</junit.version>
|
||||
<javax.servlet.version>3.0</javax.servlet.version>
|
||||
<log4j.version>2.3</log4j.version>
|
||||
<slf4j.version>1.7.12</slf4j.version>
|
||||
<org.aspectj.version>1.6.2</org.aspectj.version>
|
||||
<net.sf.ehcache.version>2.3.2</net.sf.ehcache.version>
|
||||
@@ -61,14 +60,6 @@
|
||||
<version>28.2-jre</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--引入reflectASM包-->
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
import bean.ContrastObject;
|
||||
import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
import com.google.common.collect.Lists;
|
||||
import exception.NoSetMethodException;
|
||||
import exception.TypeMisMatchException;
|
||||
import util.CheckUtil;
|
||||
import util.ClassUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static constant.Constant.GET;
|
||||
import static constant.Constant.SET;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
* @description 简单的对象比较工具的实现示例
|
||||
*/
|
||||
public abstract class AbstractContrastUtil<T> {
|
||||
/**
|
||||
* get方法的缓存Map
|
||||
*/
|
||||
private static ConcurrentHashMap<String, List<String>> getMethodCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* set方法的缓存map
|
||||
*/
|
||||
private static ConcurrentHashMap<String, List<String>> setMethodCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 基本类型的比较方法
|
||||
*/
|
||||
abstract Boolean originContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName);
|
||||
|
||||
/**
|
||||
* 自定义类型的比较方法
|
||||
*/
|
||||
abstract boolean selfContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName);
|
||||
|
||||
/**
|
||||
* map类型的比较方法
|
||||
*/
|
||||
abstract boolean mapContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) throws InstantiationException, IllegalAccessException;
|
||||
|
||||
/**
|
||||
* 集合类型比较方法
|
||||
*/
|
||||
abstract boolean collectionContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) throws InstantiationException, IllegalAccessException;
|
||||
|
||||
/**
|
||||
* 特殊类型的处理规则
|
||||
*/
|
||||
abstract boolean specialContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName);
|
||||
|
||||
/**
|
||||
* 判断是不是特殊类型
|
||||
*/
|
||||
abstract boolean isSpecialType(Object originValue, Object targetValue);
|
||||
|
||||
|
||||
/**
|
||||
* 入参都为空的处理
|
||||
*/
|
||||
abstract <T> ContrastObject<T> nullProcessor(T origin, T target);
|
||||
|
||||
/**
|
||||
* 入参为基本类型的处理
|
||||
*/
|
||||
abstract <T> ContrastObject<T> originProcessor(T origin, T target);
|
||||
|
||||
/**
|
||||
* 组装对象比较出参
|
||||
*/
|
||||
abstract <T> ContrastObject<T> setContrastObject(T origin, T target, T originChange, T targetChange);
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ContrastObject<T> contrast(T origin, T target) throws Exception {
|
||||
//空的情况的判断
|
||||
if (origin == null || target == null) {
|
||||
return nullProcessor(origin, target);
|
||||
}
|
||||
//提前检查 - 接口或者抽象类
|
||||
if (!CheckUtil.commonCheck(origin.getClass())) {
|
||||
return null;
|
||||
}
|
||||
//检查类型是否一致
|
||||
if (!CheckUtil.checkType(origin, target)) {
|
||||
throw new TypeMisMatchException("类型不匹配");
|
||||
}
|
||||
|
||||
//因为可能传入的是基本类型,所以这边会直接去处理一下基本类型
|
||||
Class clazz = target.getClass();
|
||||
if (clazz.getClassLoader() == null) {
|
||||
return originProcessor(origin, target);
|
||||
}
|
||||
|
||||
//先检查get、set方法是否存在.
|
||||
CheckUtil.checkGetAndSetMethod(origin.getClass());
|
||||
|
||||
//初始所有参数
|
||||
Class<T> tClass = (Class<T>) origin.getClass();
|
||||
T originChange = tClass.newInstance();
|
||||
T targetChange = tClass.newInstance();
|
||||
MethodAccess methodAccess = MethodAccess.get(tClass);
|
||||
//获取get方法的值进行比较、正常情况下Field都会声明为private,reflectASM对static和private自动跳过,所以用MethodAccess进行处理
|
||||
List<String> getList = getGetMethod(methodAccess, tClass);
|
||||
List<String> setList = getSetMethod(methodAccess, tClass);
|
||||
|
||||
//循环所有的MethodAccess判断是否发生变化
|
||||
boolean changed = forContrast(getList, methodAccess, origin, target, setList, originChange, targetChange);
|
||||
|
||||
if (!changed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return setContrastObject(origin, target, originChange, targetChange);
|
||||
}
|
||||
|
||||
|
||||
private <T> boolean forContrast(List<String> getList, MethodAccess methodAccess, T origin, T target, List<String> setList,
|
||||
T originChange, T targetChange) throws Exception {
|
||||
boolean changed = false;
|
||||
for (String methodName : getList) {
|
||||
boolean nowResult;
|
||||
//reflectASM会对基本类型进行装箱(比如说int返回Integer),所以这里要考虑的就是自定义类型怎么比较的问题
|
||||
Object originValue = methodAccess.invoke(origin, methodName);
|
||||
Object targetValue = methodAccess.invoke(target, methodName);
|
||||
String setName = null;
|
||||
for (String setMethodName : setList) {
|
||||
if (setMethodName.substring(3).equals(methodName.substring(3))) {
|
||||
setName = setMethodName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (setName == null) {
|
||||
throw new NoSetMethodException();
|
||||
}
|
||||
if (originValue == null && targetValue == null) {
|
||||
continue;
|
||||
}
|
||||
//对比 + 设值
|
||||
nowResult = contrastValue(originValue, targetValue, originChange, targetChange, methodAccess, setName);
|
||||
changed = changed || nowResult;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
private boolean contrastValue(Object originValue, Object targetValue, Object originChange, Object targetChange,
|
||||
MethodAccess methodAccess, String setName) throws Exception {
|
||||
//特殊拦截类型的处理
|
||||
if (isSpecialType(originValue, targetValue)) {
|
||||
return specialContract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
//处理Collection
|
||||
if (originValue instanceof Collection || targetValue instanceof Collection) {
|
||||
return collectionContract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
//Map的处理
|
||||
if (originValue instanceof Map || targetValue instanceof Map) {
|
||||
return mapContract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
//非自定义类的处理
|
||||
Boolean result = originContract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
if (null != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//自定义类型的处理
|
||||
return selfContract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Set方法集合
|
||||
*
|
||||
* @param methodAccess MethodAccess
|
||||
* @param tClass 类.class
|
||||
* @param <T> T
|
||||
* @return 方法名
|
||||
*/
|
||||
private static <T> List<String> getGetMethod(MethodAccess methodAccess, Class<T> tClass) {
|
||||
if (getMethodCache.get(tClass.getName()) != null) {
|
||||
return getMethodCache.get(tClass.getName());
|
||||
}
|
||||
List<String> methodNameList = Lists.newArrayList();
|
||||
String[] methodNames = methodAccess.getMethodNames();
|
||||
List<Method> methods = ClassUtil.getAllMethodWithSuper(tClass);
|
||||
|
||||
return buildMethodList(GET, methodNames, methods, methodNameList, getMethodCache, tClass);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Get方法集合
|
||||
*
|
||||
* @param methodAccess MethodAccess
|
||||
* @param tClass 类.class
|
||||
* @param <T> T
|
||||
* @return 方法名
|
||||
*/
|
||||
private static <T> List<String> getSetMethod(MethodAccess methodAccess, Class<T> tClass) {
|
||||
if (setMethodCache.get(tClass.getName()) != null) {
|
||||
return setMethodCache.get(tClass.getName());
|
||||
}
|
||||
List<String> methodNameList = Lists.newArrayList();
|
||||
List<Method> methods = ClassUtil.getAllMethodWithSuper(tClass);
|
||||
String[] methodNames = methodAccess.getMethodNames();
|
||||
|
||||
return buildMethodList(SET, methodNames, methods, methodNameList, setMethodCache, tClass);
|
||||
}
|
||||
|
||||
|
||||
private static <T> List<String> buildMethodList(String type, String[] methodNames, List<Method> methods, List<String> methodNameList,
|
||||
ConcurrentHashMap<String, List<String>> methodCache, Class<T> tClass) {
|
||||
for (String methodName : methodNames) {
|
||||
if (methodName.startsWith(type)) {
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(methodName)) {
|
||||
methodNameList.add(methodName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
methodCache.put(tClass.getName(), methodNameList);
|
||||
return methodNameList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,16 +21,21 @@ import static constant.Constant.SET;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
* @description 通用的对象比较基本实现类
|
||||
* @date 2020-1-5 16:00:00
|
||||
*/
|
||||
public class ContrastUtil {
|
||||
class ContrastUtil {
|
||||
|
||||
|
||||
//get方法的缓存Map
|
||||
private static ConcurrentHashMap<String, List<String>> getMethodCache = new ConcurrentHashMap<String, List<String>>();
|
||||
/**
|
||||
* get方法的缓存Map
|
||||
*/
|
||||
private static ConcurrentHashMap<String, List<String>> getMethodCache = new ConcurrentHashMap<>();
|
||||
|
||||
//set方法的缓存map
|
||||
private static ConcurrentHashMap<String, List<String>> setMethodCache = new ConcurrentHashMap<String, List<String>>();
|
||||
/**
|
||||
* set方法的缓存map
|
||||
*/
|
||||
private static ConcurrentHashMap<String, List<String>> setMethodCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 单对象对比
|
||||
@@ -41,7 +46,7 @@ public class ContrastUtil {
|
||||
* @return 对比结果
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ContrastObject<T> contrast(T origin, T target) throws IllegalAccessException, InstantiationException {
|
||||
static <T> ContrastObject<T> contrast(T origin, T target) throws IllegalAccessException, InstantiationException {
|
||||
//空的情况的判断
|
||||
if (origin == null || target == null) {
|
||||
return nullProcessor(origin, target);
|
||||
@@ -51,9 +56,16 @@ public class ContrastUtil {
|
||||
return null;
|
||||
}
|
||||
//检查类型是否一致
|
||||
if (!CheckUtil.CheckType(origin, target)) {
|
||||
if (!CheckUtil.checkType(origin, target)) {
|
||||
throw new TypeMisMatchException("类型不匹配");
|
||||
}
|
||||
|
||||
//因为可能传入的是基本类型,所以这边会直接去处理一下基本类型
|
||||
Class clazz = target.getClass();
|
||||
if (clazz.getClassLoader() == null) {
|
||||
return originProcessor(origin, target);
|
||||
}
|
||||
|
||||
//先检查get、set方法是否存在.
|
||||
CheckUtil.checkGetAndSetMethod(origin.getClass());
|
||||
|
||||
@@ -76,6 +88,14 @@ public class ContrastUtil {
|
||||
return setContrastObject(origin, target, originChange, targetChange);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> ContrastObject<T> originProcessor(T origin, T target) {
|
||||
if (origin == target) {
|
||||
return null;
|
||||
}
|
||||
return new ContrastObject(origin, target, origin, target);
|
||||
}
|
||||
|
||||
private static <T> ContrastObject<T> nullProcessor(T origin, T target) {
|
||||
if (origin == null && target == null) {
|
||||
return null;
|
||||
@@ -94,6 +114,7 @@ public class ContrastUtil {
|
||||
|
||||
boolean changed = false;
|
||||
for (String methodName : getList) {
|
||||
boolean nowResult;
|
||||
//reflectASM会对基本类型进行装箱(比如说int返回Integer),所以这里要考虑的就是自定义类型怎么比较的问题
|
||||
Object originValue = methodAccess.invoke(origin, methodName);
|
||||
Object targetValue = methodAccess.invoke(target, methodName);
|
||||
@@ -111,7 +132,8 @@ public class ContrastUtil {
|
||||
continue;
|
||||
}
|
||||
//对比 + 设值
|
||||
changed = changed || contrastValue(originValue, targetValue, originChange, targetChange, methodAccess, setName);
|
||||
nowResult = contrastValue(originValue, targetValue, originChange, targetChange, methodAccess, setName);
|
||||
changed = changed || nowResult;
|
||||
}
|
||||
|
||||
return changed;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import bean.ContrastObject;
|
||||
import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
import handler.CollectionHandler;
|
||||
import handler.MapHandler;
|
||||
import handler.OriginHandler;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
*/
|
||||
public class ContrastUtilExample<T> extends AbstractContrastUtil<T> {
|
||||
@Override
|
||||
<T> ContrastObject<T> nullProcessor(T origin, T target) {
|
||||
if (origin == null && target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (origin == null) {
|
||||
return setContrastObject(null, target, null, target);
|
||||
}
|
||||
|
||||
return setContrastObject(origin, null, origin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
<T> ContrastObject<T> originProcessor(T origin, T target) {
|
||||
if (origin == target) {
|
||||
return null;
|
||||
}
|
||||
return new ContrastObject<T>(origin, target, origin, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
<T> ContrastObject<T> setContrastObject(T origin, T target, T originChange, T targetChange) {
|
||||
ContrastObject<T> contrastObject = new ContrastObject<>();
|
||||
contrastObject.setOrigin(origin);
|
||||
contrastObject.setTarget(target);
|
||||
contrastObject.setOriginChange(originChange);
|
||||
contrastObject.setTargetChange(targetChange);
|
||||
return contrastObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
Boolean originContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) {
|
||||
return OriginHandler.contract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean selfContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean mapContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) throws InstantiationException, IllegalAccessException {
|
||||
return MapHandler.putValue(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean collectionContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) throws InstantiationException, IllegalAccessException {
|
||||
return CollectionHandler.contract(originChange, targetChange, originValue, targetValue, methodAccess, setName);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean specialContract(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isSpecialType(Object originValue, Object targetValue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 返回的对比对象的包装
|
||||
*
|
||||
* @author 志军
|
||||
*/
|
||||
public class ContrastObject<T> {
|
||||
|
||||
@@ -30,6 +30,15 @@ public class ContrastObject<T> {
|
||||
*/
|
||||
private T targetChange;
|
||||
|
||||
public ContrastObject() {
|
||||
}
|
||||
|
||||
public ContrastObject(T origin, T target, T originChange, T targetChange) {
|
||||
this.origin = origin;
|
||||
this.target = target;
|
||||
this.originChange = originChange;
|
||||
this.targetChange = targetChange;
|
||||
}
|
||||
|
||||
public T getOrigin() {
|
||||
return origin;
|
||||
@@ -65,13 +74,17 @@ public class ContrastObject<T> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ContrastObject<?> that = (ContrastObject<?>) o;
|
||||
return getOrigin().equals(that.getOrigin()) &&
|
||||
getTarget().equals(that.getTarget()) &&
|
||||
getOriginChange().equals(that.getOriginChange()) &&
|
||||
getTargetChange().equals(that.getTargetChange());
|
||||
getTarget().equals(that.getTarget()) &&
|
||||
getOriginChange().equals(that.getOriginChange()) &&
|
||||
getTargetChange().equals(that.getTargetChange());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package constant;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
*/
|
||||
public class Constant {
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package exception;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
*/
|
||||
public class NoGetMethodException extends RuntimeException{
|
||||
|
||||
public NoGetMethodException() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package exception;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
*/
|
||||
public class NoSetMethodException extends RuntimeException {
|
||||
|
||||
public NoSetMethodException() {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package exception;
|
||||
|
||||
/**
|
||||
* @author 志军
|
||||
*/
|
||||
public class TypeMisMatchException extends RuntimeException {
|
||||
|
||||
public TypeMisMatchException() {
|
||||
|
||||
@@ -33,14 +33,17 @@ public class CollectionHandler {
|
||||
*/
|
||||
public static Boolean contract(Object originChange, Object targetChange, Object originValue, Object targetValue,
|
||||
MethodAccess methodAccess, String setName) throws IllegalAccessException, InstantiationException {
|
||||
|
||||
boolean changed;
|
||||
Class returnValue = originValue.getClass();
|
||||
|
||||
//判断Collection是否相等
|
||||
if (CollectionUtils.isEqualCollection((Collection) originValue, (Collection) targetValue)) {
|
||||
if (originValue == null && targetValue == null) {
|
||||
return false;
|
||||
}
|
||||
//判断Collection是否相等
|
||||
boolean isCollectionEquals = (originValue != null && targetValue != null) && CollectionUtils.isEqualCollection((Collection) originValue, (Collection) targetValue);
|
||||
if (isCollectionEquals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Class returnValue = originValue == null ? targetValue.getClass() : originValue.getClass();
|
||||
|
||||
Object originCollection = CollectionUtil.buildDiffCollection(originValue, targetValue, returnValue);
|
||||
Object changeCollection = CollectionUtil.buildDiffCollection(targetValue, originValue, returnValue);
|
||||
|
||||
@@ -24,6 +24,11 @@ public class MapHandler {
|
||||
@SuppressWarnings("unchecked")
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
//参数前置
|
||||
boolean changed = false;
|
||||
Set<Map.Entry> originEntry = ((Map) originValue).entrySet();
|
||||
@@ -35,9 +40,11 @@ public class MapHandler {
|
||||
for (Map.Entry entry : originEntry) {
|
||||
Object key = entry.getKey();
|
||||
for (Map.Entry tEntry : targetEntry) {
|
||||
boolean hasChange;
|
||||
if (tEntry.getKey().equals(key)) {
|
||||
//每一个key都进行比较,如果key相等则比较对应的value,这个value需要重写hashcode和equals方法
|
||||
changed = changed || MapHandler.putValue(originChange, targetChange, originMap, targetMap, key);
|
||||
hasChange = MapHandler.putValue(entry.getValue(), tEntry.getValue(), originMap, targetMap, key);
|
||||
changed = changed || hasChange;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -47,7 +54,7 @@ public class MapHandler {
|
||||
List<Map.Entry> originList = SetUtil.findUnLikeValue(originEntry, targetEntry);
|
||||
List<Map.Entry> changeList = SetUtil.findUnLikeValue(originEntry, targetEntry);
|
||||
//计算changed的值
|
||||
changed = changed || !CollectionUtils.isEmpty(originList) || CollectionUtils.isEmpty(changeList);
|
||||
changed = changed || !CollectionUtils.isEmpty(originList) || !CollectionUtils.isEmpty(changeList);
|
||||
//把不一致的值设置会新的Map中
|
||||
MapUtil.putIfNotEmpty(originMap, originList);
|
||||
MapUtil.putIfNotEmpty(targetMap, changeList);
|
||||
@@ -57,13 +64,13 @@ public class MapHandler {
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static boolean putValue(Object originChange, Object targetChange, Map<Object, Object> originMap,
|
||||
private static boolean putValue(Object value, Object tValue, Map<Object, Object> originMap,
|
||||
Map<Object, Object> targetMap, Object key) {
|
||||
if (originChange.equals(targetChange)) {
|
||||
if (value.equals(tValue)) {
|
||||
return false;
|
||||
}
|
||||
originMap.put(key, originChange);
|
||||
targetMap.put(key, targetChange);
|
||||
originMap.put(key, value);
|
||||
targetMap.put(key, tValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,17 @@ import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
|
||||
/**
|
||||
* 处理自定义的类,必须重写hashCode和equals方法,不然会出现对比偏差.<p>
|
||||
*
|
||||
* @author 志军
|
||||
*/
|
||||
public class SelfHandler {
|
||||
public static Boolean contract(Object originChange, Object targetChange, Object originValue, Object targetValue,
|
||||
MethodAccess methodAccess, String setName) {
|
||||
if (!originChange.equals(targetChange)) {
|
||||
//两个属性都为空情况前面已经处理过了
|
||||
if (isOneNull(originChange, targetChange, originValue, targetValue, methodAccess, setName)) {
|
||||
return true;
|
||||
}
|
||||
if (!originValue.equals(targetValue)) {
|
||||
methodAccess.invoke(originChange, setName, originValue);
|
||||
methodAccess.invoke(targetChange, setName, targetValue);
|
||||
return true;
|
||||
@@ -22,4 +27,15 @@ public class SelfHandler {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isOneNull(Object originChange, Object targetChange, Object originValue, Object targetValue, MethodAccess methodAccess, String setName) {
|
||||
if (originValue == null) {
|
||||
methodAccess.invoke(targetChange, setName, targetValue);
|
||||
return true;
|
||||
} else if (targetValue == null) {
|
||||
methodAccess.invoke(originChange, setName, originValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class CheckUtil {
|
||||
return !Modifier.isAbstract(aClass.getModifiers()) && !Modifier.isInterface(aClass.getModifiers());
|
||||
}
|
||||
|
||||
public static <T> boolean CheckType(T origin, T target) {
|
||||
public static <T> boolean checkType(T origin, T target) {
|
||||
return origin.getClass() == target.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Collection类型的处理工具
|
||||
*
|
||||
* @author 志军
|
||||
*/
|
||||
public class CollectionUtil {
|
||||
@@ -16,7 +17,14 @@ public class CollectionUtil {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Collection buildDiffCollection(Object originValue, Object targetValue, Class returnValue) throws IllegalAccessException,
|
||||
InstantiationException {
|
||||
InstantiationException {
|
||||
//数组为空的判断这边需要考虑的只有一个为空另一个不为空,因为在外面已经进行了其他两种情况的处理了
|
||||
if (null == targetValue) {
|
||||
return (Collection) originValue;
|
||||
}
|
||||
if (null == originValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object collection = returnValue.newInstance();
|
||||
|
||||
|
||||
+21
-1
@@ -1,4 +1,24 @@
|
||||
# 工具说明
|
||||
本工程提供ContrastUtil.java作为通用同类型对象处理工具类,处理规则如下(有没有测试到的bug,欢迎指教.qq:851516902):
|
||||
|
||||
1.Collection和Map的处理当前类只会处理一层,也就是说比如List<泛型>:这个泛型类型会直接调用equals进行处理,可能照成结果的不准确(可以通过Abstract类进行重写)
|
||||
2.如果比较的不是结构体而是基本类型,返回兼容结果
|
||||
3.比较的两个对象类型必须一致
|
||||
4.没有处理Collection的入参和Map的入参,后续会加上
|
||||
5.入参可以为空
|
||||
6.自定义类型没有Get、Set方法会进行报错。不会比较
|
||||
7、自定义类型必须重写equals和hashcode方法,否则不会比较值,而是比较对象地址(这边提供一种自处理的方式,可参考lombok的处理,直接修改AST,这样就算用户不重写equals也会直接比较对应值)
|
||||
8、
|
||||
|
||||
本工程提供AbstractContrastUtil.java作为对象对比抽象基类,提供isSpecialType的判断,可以在对象属性比较的时候进行对应类型的拦截处理,并使用者需要实现Collection、Map、基本类型、自定义类型的处理
|
||||
提供最大的自定义性,因为对应的类型太多,ContractUtil没办法一并处理,所以提供对应抽象类。抽象类的继承示例可参考:ContrastUtilExample.java。该类的实现主要参考ContractUtil.java。
|
||||
|
||||
本工程对于一些抽象类的方法没有非常详细的注释,可直接参考Contract.java的实现处理。
|
||||
|
||||
本工程比较通用而且直接使用反射的方式,在处理速度上面会有一定的限制,后期可修改为内省的方式处理,且处理情况过多,没有覆盖所有的测试场景,希望读者可以提出宝贵的意见和建议。
|
||||
|
||||
# 更新日志
|
||||
2020/4/30: 创建项目、单测,进行第一轮简单的测试
|
||||
2020/4/30: 创建项目、单测,进行第一轮简单的测试
|
||||
|
||||
|
||||
2020/5/9:添加测试方法,修改bug(反射处理null出现空指针的问题比较多),创建抽象类和继承使用示例。添加readme修改记录
|
||||
@@ -1,15 +1,615 @@
|
||||
import bean.ContrastObject;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ContractTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws InstantiationException, IllegalAccessException {
|
||||
// testSimple();
|
||||
// testObject();
|
||||
// testSimpleMap();
|
||||
// testSimpleList();
|
||||
// testListList();
|
||||
// testListObject();
|
||||
// testListObjectRewriteEqual();
|
||||
}
|
||||
|
||||
private static void testObject() throws InstantiationException, IllegalAccessException {
|
||||
SimpleObjectObj simpleObjectObj = new SimpleObjectObj();
|
||||
simpleObjectObj.setX(1);
|
||||
simpleObjectObj.setY("123");
|
||||
simpleObject s = new simpleObject();
|
||||
s.setXx(1111);
|
||||
s.setYy("1111");
|
||||
simpleObjectObj.setSimpleObject(s);
|
||||
|
||||
SimpleObjectObj simpleObjectObj1 = new SimpleObjectObj();
|
||||
simpleObjectObj1.setX(1);
|
||||
simpleObjectObj1.setY("123");
|
||||
simpleObject s2 = new simpleObject();
|
||||
s2.setXx(1111);
|
||||
s2.setYy("1111");
|
||||
simpleObjectObj1.setSimpleObject(s2);
|
||||
|
||||
|
||||
ContrastObject<SimpleObjectObj> sim1 = ContrastUtil.contrast(simpleObjectObj, simpleObjectObj1);
|
||||
System.out.println("不重写equal的对象的值一样,其他没差别 ");
|
||||
if (null != sim1) {
|
||||
System.out.println(sim1.getOriginChange().x + " " + sim1.getOriginChange().y + " " + sim1.getOriginChange().getSimpleObject() + " " + sim1.getOriginChange().getSimpleObjectRewrite());
|
||||
System.out.println(sim1.getTargetChange().x + " " + sim1.getTargetChange().y + " " + sim1.getTargetChange().getSimpleObject() + " " + sim1.getTargetChange().getSimpleObjectRewrite());
|
||||
}
|
||||
|
||||
|
||||
SimpleObjectObj simpleObjectObj2 = new SimpleObjectObj();
|
||||
simpleObjectObj.setX(1);
|
||||
simpleObjectObj.setY("123");
|
||||
simpleObjectRewrite s3 = new simpleObjectRewrite();
|
||||
simpleObject sx = new simpleObject();
|
||||
sx.setXx(1111);
|
||||
sx.setYy("1111");
|
||||
simpleObjectObj.setSimpleObject(sx);
|
||||
simpleObjectObj.setSimpleObjectRewrite(s3);
|
||||
|
||||
SimpleObjectObj simpleObjectObj3 = new SimpleObjectObj();
|
||||
simpleObjectObj1.setX(1);
|
||||
simpleObjectObj1.setY("123");
|
||||
simpleObjectRewrite s4 = new simpleObjectRewrite();
|
||||
s4.setXx(1111);
|
||||
s4.setYy("1111");
|
||||
simpleObject sx1 = new simpleObject();
|
||||
sx1.setXx(1111);
|
||||
sx1.setYy("1111");
|
||||
simpleObjectObj.setSimpleObject(sx1);
|
||||
simpleObjectObj1.setSimpleObjectRewrite(s4);
|
||||
|
||||
ContrastObject<SimpleObjectObj> sim2 = ContrastUtil.contrast(simpleObjectObj2, simpleObjectObj3);
|
||||
System.out.println("重写equal的对象的值一样,其他没差别 ");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getOriginChange().x + " " + sim2.getOriginChange().y + " " + sim2.getOriginChange().getSimpleObject() + " " + sim2.getOriginChange().getSimpleObjectRewrite());
|
||||
System.out.println(sim2.getTargetChange().x + " " + sim2.getTargetChange().y + " " + sim2.getTargetChange().getSimpleObject() + " " + sim2.getTargetChange().getSimpleObjectRewrite());
|
||||
}
|
||||
|
||||
SimpleObjectObj simpleObjectObj4 = new SimpleObjectObj();
|
||||
simpleObjectObj4.setX(1);
|
||||
simpleObjectObj4.setY("123");
|
||||
simpleObjectRewrite s5 = new simpleObjectRewrite();
|
||||
s5.setXx(1111);
|
||||
s5.setYy("1111");
|
||||
simpleObjectObj4.setSimpleObjectRewrite(s5);
|
||||
simpleObject sx11 = new simpleObject();
|
||||
sx11.setXx(1111);
|
||||
sx11.setYy("1111");
|
||||
simpleObjectObj4.setSimpleObject(sx11);
|
||||
|
||||
SimpleObjectObj simpleObjectObj5 = new SimpleObjectObj();
|
||||
simpleObjectObj5.setX(1);
|
||||
simpleObjectObj5.setY("123");
|
||||
simpleObjectRewrite s6 = new simpleObjectRewrite();
|
||||
s6.setXx(1111);
|
||||
s6.setYy("1111");
|
||||
simpleObjectObj5.setSimpleObjectRewrite(s6);
|
||||
simpleObject sx22 = new simpleObject();
|
||||
sx22.setXx(1111);
|
||||
sx22.setYy("1111");
|
||||
simpleObjectObj5.setSimpleObject(sx22);
|
||||
|
||||
ContrastObject<SimpleObjectObj> sim3 = ContrastUtil.contrast(simpleObjectObj4, simpleObjectObj5);
|
||||
System.out.println("重写equals的对象的值一样以及不重写equals的对象值一样,其他没差别 ");
|
||||
if (null != sim3) {
|
||||
System.out.println(sim3.getOriginChange().x + " " + sim3.getOriginChange().y + " " + sim3.getOriginChange().getSimpleObject() + " " + sim3.getOriginChange().getSimpleObjectRewrite());
|
||||
System.out.println(sim3.getTargetChange().x + " " + sim3.getTargetChange().y + " " + sim3.getTargetChange().getSimpleObject() + " " + sim3.getTargetChange().getSimpleObjectRewrite());
|
||||
}
|
||||
|
||||
|
||||
SimpleObjectObj simpleObjectObj7 = new SimpleObjectObj();
|
||||
simpleObjectObj7.setX(1);
|
||||
simpleObjectObj7.setY("123");
|
||||
simpleObjectRewrite s10 = new simpleObjectRewrite();
|
||||
s10.setXx(1111);
|
||||
s10.setYy("11113");
|
||||
simpleObjectObj7.setSimpleObjectRewrite(s10);
|
||||
simpleObject sx12 = new simpleObject();
|
||||
sx12.setXx(1111);
|
||||
sx12.setYy("1111");
|
||||
simpleObjectObj7.setSimpleObject(sx12);
|
||||
|
||||
SimpleObjectObj simpleObjectObj6 = new SimpleObjectObj();
|
||||
simpleObjectObj6.setX(1);
|
||||
simpleObjectObj6.setY("123");
|
||||
simpleObjectRewrite s11 = new simpleObjectRewrite();
|
||||
s11.setXx(1111);
|
||||
s11.setYy("1111");
|
||||
simpleObjectObj6.setSimpleObjectRewrite(s11);
|
||||
simpleObject sx13 = new simpleObject();
|
||||
sx13.setXx(1111);
|
||||
sx13.setYy("11112");
|
||||
simpleObjectObj6.setSimpleObject(sx13);
|
||||
|
||||
ContrastObject<SimpleObjectObj> sim4 = ContrastUtil.contrast(simpleObjectObj7, simpleObjectObj6);
|
||||
System.out.println("对象完全不一样 ");
|
||||
if (null != sim4) {
|
||||
System.out.println(sim4.getOriginChange().x + " " + sim4.getOriginChange().y + " " + sim4.getOriginChange().getSimpleObject() + " " + sim4.getOriginChange().getSimpleObjectRewrite());
|
||||
System.out.println(sim4.getTargetChange().x + " " + sim4.getTargetChange().y + " " + sim4.getTargetChange().getSimpleObject() + " " + sim4.getTargetChange().getSimpleObjectRewrite());
|
||||
}
|
||||
|
||||
|
||||
SimpleObjectObj simpleObjectObjx1 = new SimpleObjectObj();
|
||||
simpleObjectObjx1.setX(1);
|
||||
simpleObjectObjx1.setY("123");
|
||||
|
||||
SimpleObjectObj simpleObjectObjx2 = new SimpleObjectObj();
|
||||
simpleObjectObjx2.setX(1);
|
||||
simpleObjectObjx2.setY("123");
|
||||
simpleObjectObjx2.setSimpleObjectRewrite(s11);
|
||||
simpleObjectObjx2.setSimpleObject(sx13);
|
||||
|
||||
ContrastObject<SimpleObjectObj> sim5 = ContrastUtil.contrast(simpleObjectObjx1, simpleObjectObjx2);
|
||||
System.out.println("对象的自定义对象为空的情况 ");
|
||||
if (null != sim5) {
|
||||
System.out.println(sim5.getOriginChange().x + " " + sim5.getOriginChange().y + " " + sim5.getOriginChange().getSimpleObject() + " " + sim5.getOriginChange().getSimpleObjectRewrite());
|
||||
System.out.println(sim5.getTargetChange().x + " " + sim5.getTargetChange().y + " " + sim5.getTargetChange().getSimpleObject() + " " + sim5.getTargetChange().getSimpleObjectRewrite());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void testListObjectRewriteEqual() throws InstantiationException, IllegalAccessException {
|
||||
ListObjectObjRewriteEquals s1 = new ListObjectObjRewriteEquals();
|
||||
s1.setM((float) 2.2);
|
||||
s1.setY("55555");
|
||||
List<MyObjectRewrite> list = new ArrayList<>();
|
||||
MyObjectRewrite myObject = new MyObjectRewrite();
|
||||
myObject.setX("123");
|
||||
myObject.setY(1);
|
||||
myObject.setZ(true);
|
||||
list.add(myObject);
|
||||
s1.setList(list);
|
||||
|
||||
ListObjectObjRewriteEquals s2 = new ListObjectObjRewriteEquals();
|
||||
s2.setM((float) 2.2);
|
||||
s2.setY("55555");
|
||||
List<MyObjectRewrite> list1 = new ArrayList<>();
|
||||
MyObjectRewrite myObject1 = new MyObjectRewrite();
|
||||
myObject1.setX("123");
|
||||
myObject1.setY(1);
|
||||
myObject1.setZ(true);
|
||||
list1.add(myObject1);
|
||||
s2.setList(list1);
|
||||
|
||||
ListObjectObjRewriteEquals s3 = new ListObjectObjRewriteEquals();
|
||||
s3.setM((float) 2.2);
|
||||
s3.setY("55555");
|
||||
List<MyObjectRewrite> list2 = new ArrayList<>();
|
||||
MyObjectRewrite myObject2 = new MyObjectRewrite();
|
||||
myObject2.setX("234");
|
||||
myObject2.setY(2);
|
||||
myObject2.setZ(false);
|
||||
list2.add(myObject2);
|
||||
s3.setList(list2);
|
||||
|
||||
|
||||
ListObjectObjRewriteEquals s4 = new ListObjectObjRewriteEquals();
|
||||
s4.setM((float) 2.2);
|
||||
s4.setY("55555");
|
||||
List<MyObjectRewrite> list3 = new ArrayList<>();
|
||||
MyObjectRewrite myObject3 = new MyObjectRewrite();
|
||||
myObject3.setX("234");
|
||||
myObject3.setY(2);
|
||||
myObject3.setZ(false);
|
||||
MyObjectRewrite myObject4 = new MyObjectRewrite();
|
||||
myObject4.setX("999");
|
||||
myObject4.setY(23);
|
||||
myObject4.setZ(true);
|
||||
MyObjectRewrite myObject5 = new MyObjectRewrite();
|
||||
myObject5.setX("998");
|
||||
myObject5.setY(23);
|
||||
myObject5.setZ(true);
|
||||
|
||||
list3.add(myObject3);
|
||||
list3.add(myObject4);
|
||||
list3.add(myObject5);
|
||||
s4.setList(list3);
|
||||
|
||||
|
||||
ListObjectObjRewriteEquals s5 = new ListObjectObjRewriteEquals();
|
||||
s5.setM((float) 2.2);
|
||||
s5.setY("55555");
|
||||
|
||||
|
||||
ContrastObject<ListObjectObjRewriteEquals> sim = ContrastUtil.contrast(s1, s2);
|
||||
System.out.println("重写之后使用equal方法判断");
|
||||
if (null != sim) {
|
||||
System.out.println(sim.getOriginChange().m + " " + sim.getOriginChange().x + " " + sim.getOriginChange().y + " " + sim.getOriginChange().getList());
|
||||
System.out.println(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y + " " + sim.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListObjectObjRewriteEquals> sim2 = ContrastUtil.contrast(s1, s3);
|
||||
System.out.println("两个值不一样的对象 ");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getOriginChange().m + " " + sim2.getOriginChange().x + " " + sim2.getOriginChange().y + " " + sim2.getOriginChange().getList());
|
||||
System.out.println(sim2.getTargetChange().m + " " + sim2.getTargetChange().x + " " + sim2.getTargetChange().y + " " + sim2.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListObjectObjRewriteEquals> sim3 = ContrastUtil.contrast(s1, s4);
|
||||
System.out.println("一个对象对多个对象的List ");
|
||||
if (null != sim3) {
|
||||
System.out.println(sim3.getOriginChange().m + " " + sim3.getOriginChange().x + " " + sim3.getOriginChange().y + " " + sim3.getOriginChange().getList());
|
||||
System.out.println(sim3.getTargetChange().m + " " + sim3.getTargetChange().x + " " + sim3.getTargetChange().y + " " + sim3.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListObjectObjRewriteEquals> sim4 = ContrastUtil.contrast(s1, s5);
|
||||
System.out.println("空的List和非空List ");
|
||||
if (null != sim4) {
|
||||
System.out.println(sim4.getOriginChange().m + " " + sim4.getOriginChange().x + " " + sim4.getOriginChange().y + " " + sim4.getOriginChange().getList());
|
||||
System.out.println(sim4.getTargetChange().m + " " + sim4.getTargetChange().x + " " + sim4.getTargetChange().y + " " + sim4.getTargetChange().getList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void testListObject() throws InstantiationException, IllegalAccessException {
|
||||
ListObjectObj s1 = new ListObjectObj();
|
||||
s1.setM((float) 2.2);
|
||||
s1.setY("55555");
|
||||
List<MyObject> list = new ArrayList<>();
|
||||
MyObject myObject = new MyObject();
|
||||
myObject.setX("123");
|
||||
myObject.setY(1);
|
||||
myObject.setZ(true);
|
||||
myObject.setObj(myObject);
|
||||
list.add(myObject);
|
||||
s1.setList(list);
|
||||
|
||||
ListObjectObj s2 = new ListObjectObj();
|
||||
s2.setM((float) 2.2);
|
||||
s2.setY("55555");
|
||||
List<MyObject> list1 = new ArrayList<>();
|
||||
MyObject myObject1 = new MyObject();
|
||||
myObject1.setX("123");
|
||||
myObject1.setY(1);
|
||||
myObject1.setZ(true);
|
||||
myObject1.setObj(myObject1);
|
||||
list1.add(myObject1);
|
||||
s2.setList(list1);
|
||||
|
||||
ListObjectObj s3 = new ListObjectObj();
|
||||
s3.setM((float) 2.2);
|
||||
s3.setY("55555");
|
||||
List<MyObject> list2 = new ArrayList<>();
|
||||
MyObject myObject2 = new MyObject();
|
||||
myObject2.setX("234");
|
||||
myObject2.setY(2);
|
||||
myObject2.setZ(false);
|
||||
myObject2.setObj(myObject2);
|
||||
list2.add(myObject2);
|
||||
s3.setList(list2);
|
||||
|
||||
|
||||
ListObjectObj s4 = new ListObjectObj();
|
||||
s4.setM((float) 2.2);
|
||||
s4.setY("55555");
|
||||
List<MyObject> list3 = new ArrayList<>();
|
||||
MyObject myObject3 = new MyObject();
|
||||
myObject3.setX("234");
|
||||
myObject3.setY(2);
|
||||
myObject3.setZ(false);
|
||||
myObject3.setObj(myObject3);
|
||||
MyObject myObject4 = new MyObject();
|
||||
myObject4.setX("999");
|
||||
myObject4.setY(23);
|
||||
myObject4.setZ(true);
|
||||
myObject4.setObj(myObject4);
|
||||
MyObject myObject5 = new MyObject();
|
||||
myObject5.setX("998");
|
||||
myObject5.setY(23);
|
||||
myObject5.setZ(true);
|
||||
|
||||
myObject5.setObj(myObject5);
|
||||
list3.add(myObject3);
|
||||
list3.add(myObject4);
|
||||
s4.setList(list3);
|
||||
|
||||
|
||||
ListObjectObj s5 = new ListObjectObj();
|
||||
s5.setM((float) 2.2);
|
||||
s5.setY("55555");
|
||||
|
||||
|
||||
ContrastObject<ListObjectObj> sim = ContrastUtil.contrast(s1, s2);
|
||||
System.out.println("虽然对象值一样对象不同。因为没有重写equal,所以区分不出来 ");
|
||||
if (null != sim) {
|
||||
System.out.println(sim.getOriginChange().m + " " + sim.getOriginChange().x + " " + sim.getOriginChange().y + " " + sim.getOriginChange().getList());
|
||||
System.out.println(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y + " " + sim.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListObjectObj> sim2 = ContrastUtil.contrast(s1, s3);
|
||||
System.out.println("两个值不一样的对象 ");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getOriginChange().m + " " + sim2.getOriginChange().x + " " + sim2.getOriginChange().y + " " + sim2.getOriginChange().getList());
|
||||
System.out.println(sim2.getTargetChange().m + " " + sim2.getTargetChange().x + " " + sim2.getTargetChange().y + " " + sim2.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListObjectObj> sim3 = ContrastUtil.contrast(s1, s4);
|
||||
System.out.println("一个对象对多个对象的List ");
|
||||
if (null != sim3) {
|
||||
System.out.println(sim3.getOriginChange().m + " " + sim3.getOriginChange().x + " " + sim3.getOriginChange().y + " " + sim3.getOriginChange().getList());
|
||||
System.out.println(sim3.getTargetChange().m + " " + sim3.getTargetChange().x + " " + sim3.getTargetChange().y + " " + sim3.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListObjectObj> sim4 = ContrastUtil.contrast(s1, s5);
|
||||
System.out.println("空的List和非空List ");
|
||||
if (null != sim4) {
|
||||
System.out.println(sim4.getOriginChange().m + " " + sim4.getOriginChange().x + " " + sim4.getOriginChange().y + " " + sim4.getOriginChange().getList());
|
||||
System.out.println(sim4.getTargetChange().m + " " + sim4.getTargetChange().x + " " + sim4.getTargetChange().y + " " + sim4.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void testListList() throws InstantiationException, IllegalAccessException {
|
||||
|
||||
ListListObj s1 = new ListListObj();
|
||||
s1.setM((float) 2.2);
|
||||
s1.setY("55555");
|
||||
List<List<String>> list = new ArrayList<>();
|
||||
list.add(Lists.newArrayList("1", "2", "3"));
|
||||
s1.setList(list);
|
||||
|
||||
|
||||
ListListObj s2 = new ListListObj();
|
||||
s2.setM((float) 2.2);
|
||||
s2.setY("55555");
|
||||
|
||||
ListListObj s3 = new ListListObj();
|
||||
s3.setM((float) 2.2);
|
||||
s3.setY("55555");
|
||||
List<List<String>> list1 = new ArrayList<>();
|
||||
list1.add(Lists.newArrayList("3", "2", "5", "99"));
|
||||
s3.setList(list1);
|
||||
|
||||
|
||||
ListListObj s4 = new ListListObj();
|
||||
s4.setM((float) 2.2);
|
||||
s4.setY("55555");
|
||||
List<List<String>> list2 = new ArrayList<>();
|
||||
list2.add(Lists.newArrayList("3", "2", "5", "99"));
|
||||
s4.setList(list2);
|
||||
|
||||
ListListObj s5 = new ListListObj();
|
||||
s5.setM((float) 2.2);
|
||||
s5.setY("55555");
|
||||
List<List<String>> list3 = new ArrayList<>();
|
||||
list3.add(Lists.newArrayList("3", "2", "5", "99"));
|
||||
list3.add(Lists.newArrayList("5", "2", "5", "99"));
|
||||
list3.add(Lists.newArrayList("5", "2", "5", "99"));
|
||||
s5.setList(list3);
|
||||
|
||||
|
||||
ContrastObject<ListListObj> sim = ContrastUtil.contrast(s1, s2);
|
||||
System.out.println("空的List和非空List ");
|
||||
if (null != sim) {
|
||||
System.out.println(sim.getOriginChange().m + " " + sim.getOriginChange().x + " " + sim.getOriginChange().y + " " + sim.getOriginChange().getList());
|
||||
System.out.println(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y + " " + sim.getTargetChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListListObj> sim1 = ContrastUtil.contrast(s1, s3);
|
||||
System.out.println("List只有一个值,都是非空 ");
|
||||
if (null != sim1) {
|
||||
System.out.println(sim1.getTargetChange().m + " " + sim1.getTargetChange().x + " " + sim1.getTargetChange().y + " " + sim1.getTargetChange().getList());
|
||||
System.out.println(sim1.getOriginChange().m + " " + sim1.getOriginChange().x + " " + sim1.getOriginChange().y + " " + sim1.getOriginChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListListObj> sim2 = ContrastUtil.contrast(s2, s3);
|
||||
System.out.println("空的List和非空List ");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getTargetChange().m + " " + sim2.getTargetChange().x + " " + sim2.getTargetChange().y + " " + sim2.getTargetChange().getList());
|
||||
System.out.println(sim2.getOriginChange().m + " " + sim2.getOriginChange().x + " " + sim2.getOriginChange().y + " " + sim2.getOriginChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListListObj> sim3 = ContrastUtil.contrast(s5, s3);
|
||||
System.out.println("List为一个值和多个值,一样的值会进行剔除 ");
|
||||
if (null != sim3) {
|
||||
System.out.println(sim3.getTargetChange().m + " " + sim3.getTargetChange().x + " " + sim3.getTargetChange().y + " " + sim3.getTargetChange().getList());
|
||||
System.out.println(sim3.getOriginChange().m + " " + sim3.getOriginChange().x + " " + sim3.getOriginChange().y + " " + sim3.getOriginChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListListObj> sim4 = ContrastUtil.contrast(s5, s1);
|
||||
System.out.println("List为一个值和多个值,值完全不一样 ");
|
||||
if (null != sim4) {
|
||||
System.out.println(sim4.getOriginChange().m + " " + sim4.getOriginChange().x + " " + sim4.getOriginChange().y + " " + sim4.getOriginChange().getList());
|
||||
System.out.println(sim4.getTargetChange().m + " " + sim4.getTargetChange().x + " " + sim4.getTargetChange().y + " " + sim4.getTargetChange().getList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void testSimpleList() throws InstantiationException, IllegalAccessException {
|
||||
SimpleListObj s1 = new SimpleListObj();
|
||||
s1.setM((float) 2.2);
|
||||
s1.setY("55555");
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("abc");
|
||||
s1.setList(list);
|
||||
|
||||
SimpleListObj s2 = new SimpleListObj();
|
||||
s2.setM((float) 2.2);
|
||||
s2.setY("555556");
|
||||
List<String> list1 = new ArrayList<>();
|
||||
list1.add("abc");
|
||||
s2.setList(list1);
|
||||
|
||||
|
||||
SimpleListObj s3 = new SimpleListObj();
|
||||
s3.setM((float) 2.2);
|
||||
s3.setY("55555");
|
||||
List<String> list2 = new ArrayList<>();
|
||||
list2.add("abc");
|
||||
s3.setList(list2);
|
||||
|
||||
|
||||
SimpleListObj s4 = new SimpleListObj();
|
||||
s4.setM((float) 2.2);
|
||||
s4.setY("55555");
|
||||
List<String> list3 = new ArrayList<>();
|
||||
list3.add("abc");
|
||||
list3.add("bcd");
|
||||
list3.add("cde");
|
||||
s4.setList(list3);
|
||||
|
||||
ContrastObject<SimpleListObj> sim = ContrastUtil.contrast(s1, s2);
|
||||
System.out.println("List的值一样 ,其他字段不一样");
|
||||
if (null != sim) {
|
||||
System.out.println(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y + " " + sim.getTargetChange().getList());
|
||||
System.out.println(sim.getOriginChange().m + " " + sim.getOriginChange().x + " " + sim.getOriginChange().y + " " + sim.getOriginChange().getList());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<SimpleListObj> sim1 = ContrastUtil.contrast(s1, s3);
|
||||
System.out.println("List的值一样,其他字段也一样 ");
|
||||
if (null != sim1) {
|
||||
System.out.println(sim1.getTargetChange().m + " " + sim1.getTargetChange().x + " " + sim1.getTargetChange().y + " " + sim1.getTargetChange().getList().toString());
|
||||
System.out.println(sim1.getOriginChange().m + " " + sim1.getOriginChange().x + " " + sim1.getOriginChange().y + " " + sim1.getOriginChange().getList().toString());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<SimpleListObj> sim2 = ContrastUtil.contrast(s1, s4);
|
||||
System.out.println("List为一个值和多个值 ");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getTargetChange().m + " " + sim2.getTargetChange().x + " " + sim2.getTargetChange().y + " " + sim2.getTargetChange().getList().toString());
|
||||
System.out.println(sim2.getOriginChange().m + " " + sim2.getOriginChange().x + " " + sim2.getOriginChange().y + " " + sim2.getOriginChange().getList().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void testSimpleMap() throws InstantiationException, IllegalAccessException {
|
||||
SimpleMapObj m1 = new SimpleMapObj();
|
||||
m1.setM((float) 2.2);
|
||||
m1.setY("55555");
|
||||
HashMap<String, String> mm = new HashMap<>();
|
||||
mm.put("123", "345");
|
||||
m1.setMap(mm);
|
||||
|
||||
SimpleMapObj m2 = new SimpleMapObj();
|
||||
m2.setM((float) 2.21);
|
||||
m2.setY("555551");
|
||||
HashMap<String, String> mm1 = new HashMap<>();
|
||||
mm1.put("123", "123");
|
||||
m2.setMap(mm1);
|
||||
|
||||
SimpleMapObj m3 = new SimpleMapObj();
|
||||
m3.setM((float) 2.21);
|
||||
m3.setY("555551");
|
||||
HashMap<String, String> mm2 = new HashMap<>();
|
||||
mm2.put("123", "123");
|
||||
m3.setMap(mm2);
|
||||
|
||||
SimpleMapObj m4 = new SimpleMapObj();
|
||||
m4.setM((float) 2.21);
|
||||
m4.setY("555551");
|
||||
HashMap<String, String> mm3 = new HashMap<>();
|
||||
mm3.put("123", "123");
|
||||
mm3.put("222", "123");
|
||||
m4.setMap(mm3);
|
||||
|
||||
SimpleMapObj m5 = new SimpleMapObj();
|
||||
m5.setM((float) 2.21);
|
||||
m5.setY("555551");
|
||||
|
||||
|
||||
ContrastObject<SimpleMapObj> sim = ContrastUtil.contrast(m1, m2);
|
||||
System.out.println("Map只有一个值,并且不一样");
|
||||
if (null != sim) {
|
||||
System.out.println(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y + " " + sim.getTargetChange().getMap().toString());
|
||||
System.out.println(sim.getOriginChange().m + " " + sim.getOriginChange().x + " " + sim.getOriginChange().y + " " + sim.getOriginChange().getMap().toString());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<SimpleMapObj> sim1 = ContrastUtil.contrast(m3, m2);
|
||||
System.out.println("Map的值相同并且其他字段也相同");
|
||||
if (null != sim1) {
|
||||
System.out.println(sim1.getTargetChange().m + " " + sim1.getTargetChange().x + " " + sim1.getTargetChange().y + " " + sim1.getTargetChange().getMap().toString());
|
||||
System.out.println(sim1.getOriginChange().m + " " + sim1.getOriginChange().x + " " + sim1.getOriginChange().y + " " + sim1.getOriginChange().getMap().toString());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<SimpleMapObj> sim2 = ContrastUtil.contrast(m3, m4);
|
||||
System.out.println("Map只有一个值和多个值");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getTargetChange().m + " " + sim2.getTargetChange().x + " " + sim2.getTargetChange().y + " " + sim2.getTargetChange().getMap().toString());
|
||||
System.out.println(sim2.getOriginChange().m + " " + sim2.getOriginChange().x + " " + sim2.getOriginChange().y + " " + sim2.getOriginChange().getMap().toString());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<SimpleMapObj> sim3 = ContrastUtil.contrast(m3, m5);
|
||||
System.out.println("测试有一个Map为空的情况");
|
||||
if (null != sim3) {
|
||||
System.out.println(sim3.getTargetChange().m + " " + sim3.getTargetChange().x + " " + sim3.getTargetChange().y + " " + sim3.getTargetChange().getMap());
|
||||
System.out.println(sim3.getOriginChange().m + " " + sim3.getOriginChange().x + " " + sim3.getOriginChange().y + " " + sim3.getOriginChange().getMap());
|
||||
}
|
||||
}
|
||||
|
||||
private static void testSimple() throws InstantiationException, IllegalAccessException {
|
||||
SimpleObj s1 = new SimpleObj();
|
||||
s1.setM((float) 2.2);
|
||||
s1.setY("55555");
|
||||
ContrastObject<SimpleObj> sim = ContrastUtil.contrast(new SimpleObj(), s1);
|
||||
|
||||
System.out.println("测试一下对象中的基本类型");
|
||||
if (sim != null) {
|
||||
System.out.println(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y);
|
||||
System.out.println(sim.getOriginChange().m + " " + sim.getOriginChange().x + " " + sim.getOriginChange().y);
|
||||
}
|
||||
|
||||
System.out.print(sim.getTargetChange().m + " " + sim.getTargetChange().x + " " + sim.getTargetChange().y);
|
||||
|
||||
System.out.println("测试一下基本类型");
|
||||
ContrastObject<Integer> sim1 = ContrastUtil.contrast(1, 1);
|
||||
ContrastObject<Integer> sim2 = ContrastUtil.contrast(1, 2);
|
||||
ContrastObject<String> sim3 = ContrastUtil.contrast("1", "1");
|
||||
System.out.println("两个相同的Integer");
|
||||
if (null != sim1) {
|
||||
System.out.println(sim1.getTargetChange() + " " + sim1.getTargetChange() + " " + sim1.getTargetChange() + " " + sim1.getTargetChange());
|
||||
System.out.println(sim1.getOriginChange() + " " + sim1.getOriginChange() + " " + sim1.getOriginChange() + " " + sim1.getOriginChange());
|
||||
}
|
||||
|
||||
|
||||
System.out.println("两个不同的Integer");
|
||||
if (null != sim2) {
|
||||
System.out.println(sim2.getTargetChange() + " " + sim2.getTargetChange() + " " + sim2.getTargetChange() + " " + sim2.getTargetChange());
|
||||
System.out.println(sim2.getOriginChange() + " " + sim2.getOriginChange() + " " + sim2.getOriginChange() + " " + sim2.getOriginChange());
|
||||
}
|
||||
|
||||
|
||||
System.out.println("两个相同的String");
|
||||
if (null != sim3) {
|
||||
System.out.println(sim3.getTargetChange() + " " + sim3.getTargetChange() + " " + sim3.getTargetChange() + " " + sim3.getTargetChange());
|
||||
System.out.println(sim3.getOriginChange() + " " + sim3.getOriginChange() + " " + sim3.getOriginChange() + " " + sim3.getOriginChange());
|
||||
}
|
||||
|
||||
|
||||
System.out.println("两个不同的String");
|
||||
ContrastObject<String> sim4 = ContrastUtil.contrast("1", "2");
|
||||
if (null != sim4) {
|
||||
System.out.println(sim4.getTargetChange() + " " + sim4.getTargetChange() + " " + sim4.getTargetChange() + " " + sim4.getTargetChange());
|
||||
System.out.println(sim4.getOriginChange() + " " + sim4.getOriginChange() + " " + sim4.getOriginChange() + " " + sim4.getOriginChange());
|
||||
}
|
||||
|
||||
|
||||
ContrastObject<ListListObj> sim5 = ContrastUtil.contrast(null, new ListListObj());
|
||||
System.out.println("测试有null的情况");
|
||||
if (null != sim5) {
|
||||
System.out.println(sim5.getTargetChange() + " " + sim5.getTargetChange() + " " + sim5.getTargetChange() + " " + sim5.getTargetChange());
|
||||
System.out.println(sim5.getOriginChange() + " " + sim5.getOriginChange() + " " + sim5.getOriginChange() + " " + sim5.getOriginChange());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ListListObj {
|
||||
|
||||
|
||||
int x;
|
||||
|
||||
String y;
|
||||
|
||||
float m;
|
||||
|
||||
Date date;
|
||||
|
||||
List<List<String>> list;
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(float m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public List<List<String>> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<List<String>> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ListObjectObj {
|
||||
int x;
|
||||
|
||||
String y;
|
||||
|
||||
float m;
|
||||
|
||||
Date date;
|
||||
|
||||
List<MyObject> list;
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(float m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public List<MyObject> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<MyObject> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MyObject {
|
||||
String x;
|
||||
int y;
|
||||
boolean z;
|
||||
|
||||
MyObject obj;
|
||||
|
||||
public String getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(String x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public boolean isZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(boolean z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public MyObject getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void setObj(MyObject obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ListObjectObjRewriteEquals {
|
||||
|
||||
int x;
|
||||
|
||||
String y;
|
||||
|
||||
float m;
|
||||
|
||||
Date date;
|
||||
|
||||
List<MyObjectRewrite> list;
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(float m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public List<MyObjectRewrite> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<MyObjectRewrite> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
|
||||
class MyObjectRewrite {
|
||||
String x;
|
||||
int y;
|
||||
boolean z;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MyObjectRewrite that = (MyObjectRewrite) o;
|
||||
return y == that.y &&
|
||||
z == that.z &&
|
||||
Objects.equals(x, that.x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
public String getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(String x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public boolean isZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(boolean z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleListObj {
|
||||
|
||||
int x;
|
||||
|
||||
String y;
|
||||
|
||||
float m;
|
||||
|
||||
Date date;
|
||||
|
||||
List<String> list;
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(float m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public List<String> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<String> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleMapObj {
|
||||
|
||||
int x;
|
||||
|
||||
String y;
|
||||
|
||||
float m;
|
||||
|
||||
Date date;
|
||||
|
||||
Map<String, String> map;
|
||||
|
||||
public Map<String, String> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String, String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(float m) {
|
||||
this.m = m;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import java.util.Objects;
|
||||
|
||||
public class SimpleObjectObj {
|
||||
int x;
|
||||
String y;
|
||||
|
||||
simpleObject simpleObject;
|
||||
|
||||
simpleObjectRewrite simpleObjectRewrite;
|
||||
|
||||
public simpleObjectRewrite getSimpleObjectRewrite() {
|
||||
return simpleObjectRewrite;
|
||||
}
|
||||
|
||||
public void setSimpleObjectRewrite(simpleObjectRewrite simpleObjectRewrite) {
|
||||
this.simpleObjectRewrite = simpleObjectRewrite;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public simpleObject getSimpleObject() {
|
||||
return simpleObject;
|
||||
}
|
||||
|
||||
public void setSimpleObject(simpleObject simpleObject) {
|
||||
this.simpleObject = simpleObject;
|
||||
}
|
||||
}
|
||||
|
||||
class simpleObject {
|
||||
int xx;
|
||||
String yy;
|
||||
|
||||
public int getXx() {
|
||||
return xx;
|
||||
}
|
||||
|
||||
public void setXx(int xx) {
|
||||
this.xx = xx;
|
||||
}
|
||||
|
||||
public String getYy() {
|
||||
return yy;
|
||||
}
|
||||
|
||||
public void setYy(String yy) {
|
||||
this.yy = yy;
|
||||
}
|
||||
}
|
||||
|
||||
class simpleObjectRewrite{
|
||||
int xx;
|
||||
String yy;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
simpleObjectRewrite that = (simpleObjectRewrite) o;
|
||||
return xx == that.xx &&
|
||||
Objects.equals(yy, that.yy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(xx, yy);
|
||||
}
|
||||
|
||||
public int getXx() {
|
||||
return xx;
|
||||
}
|
||||
|
||||
public void setXx(int xx) {
|
||||
this.xx = xx;
|
||||
}
|
||||
|
||||
public String getYy() {
|
||||
return yy;
|
||||
}
|
||||
|
||||
public void setYy(String yy) {
|
||||
this.yy = yy;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user