我在用着unitils http://www.unitils.org/用于深度对象比较的工具,通过ReflectionComparator
:
ReflectionComparatorMode[] modes = {ReflectionComparatorMode.LENIENT_ORDER, ReflectionComparatorMode.IGNORE_DEFAULTS};
ReflectionComparator comparator = ReflectionComparatorFactory.createRefectionComparator(modes);
Difference difference = comparator.getDifference(oldObject, newObject);
事实证明,这ReflectionComparator
不忽略大小写String
字段值。并且没有用于此目的的特殊模式ReflectionComparatorMode
enum:
public enum ReflectionComparatorMode {
IGNORE_DEFAULTS,
LENIENT_DATES,
LENIENT_ORDER
}
有什么想法,如何实现?
ReflectionComparatorMode
没有模式可以模仿ignore_case
行为。
您没有指定类型oldObject
and newObject
但我想你也可以'正常化' 在将它们传递给之前ReflectionComparator
(转换所有String
字段为大写或小写)或根据特定类型实现您自己的 Java 比较器oldObject
and newObject
.
查看this http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#CASE_INSENSITIVE_ORDER.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)