use of org.codehaus.groovy.runtime.NullObject in project groovy by apache.
the class DefaultTypeTransformation method compareEqual.
public static boolean compareEqual(Object left, Object right) {
if (left == right)
return true;
if (left == null)
return right instanceof NullObject;
if (right == null)
return left instanceof NullObject;
if (left instanceof Comparable) {
return compareToWithEqualityCheck(left, right, true) == 0;
}
// handle arrays on both sides as special case for efficiency
Class leftClass = left.getClass();
Class rightClass = right.getClass();
if (leftClass.isArray() && rightClass.isArray()) {
return compareArrayEqual(left, right);
}
if (leftClass.isArray() && leftClass.getComponentType().isPrimitive()) {
left = primitiveArrayToList(left);
}
if (rightClass.isArray() && rightClass.getComponentType().isPrimitive()) {
right = primitiveArrayToList(right);
}
if (left instanceof Object[] && right instanceof List) {
return DefaultGroovyMethods.equals((Object[]) left, (List) right);
}
if (left instanceof List && right instanceof Object[]) {
return DefaultGroovyMethods.equals((List) left, (Object[]) right);
}
if (left instanceof List && right instanceof List) {
return DefaultGroovyMethods.equals((List) left, (List) right);
}
if (left instanceof Map.Entry && right instanceof Map.Entry) {
Object k1 = ((Map.Entry) left).getKey();
Object k2 = ((Map.Entry) right).getKey();
if (Objects.equals(k1, k2)) {
Object v1 = ((Map.Entry) left).getValue();
Object v2 = ((Map.Entry) right).getValue();
return v1 == v2 || (v1 != null && DefaultTypeTransformation.compareEqual(v1, v2));
}
return false;
}
return (Boolean) InvokerHelper.invokeMethod(left, "equals", right);
}
Aggregations