if (left == right) {
return null;
}
// check if the left value is null
if (left == null) {
return new Difference("Left value null", left, right);
}
// check if the right value is null
if (right == null) {
return new Difference("Right value null", left, right);
}
// check if right and left have same number value (including NaN and
// Infinity)
if ((left instanceof Character || left instanceof Number)
&& (right instanceof Character || right instanceof Number)) {
Double leftDouble = getDoubleValue(left);
Double rightDouble = getDoubleValue(right);
if (leftDouble.equals(rightDouble)) {
return null;
}
return new Difference("Different primitive values", left, right);
}
if (left.getClass() == String.class && Date.class.isAssignableFrom(right.getClass())) {
SimpleDateFormat df = DateUtil.getDateFormat((String) left);
right = df.format((Date) right);
}
// check if java objects are equal
if (left.getClass().getName().startsWith("java.lang") || right.getClass().getName().startsWith("java.lang")) {
if (left.equals(right)) {
return null;
}
return new Difference("Different object values", left, right);
}
// check if enums are equal
if (left instanceof Enum && right instanceof Enum) {
if (left.equals(right)) {
return null;
}
return new Difference("Different enum values", left, right);
}
return null;
}