java equals utils_Java ObjectUtils.equals方法代码示例

import org.apache.commons.lang3.ObjectUtils; //导入方法依赖的package包/类

private void compareObjectsInternal(Object key, Object left, Object right, MutableCollection breaks) {

Class objectClass = left.getClass();

MutableCollection classCompareInfos = this.getClassCompareInfos(objectClass);

if (classCompareInfos.isEmpty()) {

if (!ObjectUtils.equals(left, right)) {

breaks.add(new FieldCompareBreak(objectClass, key, left, right, "this", left, right));

}

} else {

for (ClassCompareInfo classCompareInfo : classCompareInfos) {

for (Pair> functionPair : classCompareInfo.getCompareFunctions()) {

Function function = functionPair.getTwo();

Object leftFuncVal = function.valueOf(left);

Object rightFuncVal = function.valueOf(right);

if (leftFuncVal == null && rightFuncVal == null) {

continue; // no break - continue

} else if (leftFuncVal == null ^ rightFuncVal == null) { // XOR - if one of these is null, but not

// the other

breaks.add(new FieldCompareBreak(objectClass, key, left, right, functionPair.getOne(),

leftFuncVal, rightFuncVal));

} else {

MutableCollection funcClassCompareInfos = this.getClassCompareInfos(leftFuncVal

.getClass());

if (funcClassCompareInfos.isEmpty()) {

if (!ObjectUtils.equals(leftFuncVal, rightFuncVal)) {

breaks.add(new FieldCompareBreak(objectClass, key, left, right, functionPair.getOne(),

leftFuncVal, rightFuncVal));

}

} else {

this.compareObjectsInternal(key, leftFuncVal, rightFuncVal, breaks);

}

}

}

for (CollectionFieldCompareInfo collectionCompareInfo : classCompareInfo.getCollectionComparisonInfos()) {

this.compareCollectionsInternal(collectionCompareInfo.getElementClass()

, (Collection) collectionCompareInfo.getCollectionFieldFunction().valueOf(left)

, (Collection) collectionCompareInfo.getCollectionFieldFunction().valueOf(right)

, breaks);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值