Returns true if the two given arrays are deeply equal to one another. Unlike the method equals(Object[] array1, Object[] array2), this method is appropriate for use for nested arrays of arbitrary depth. Two array references are considered deeply equal if they are both {@code null
(Object[] array1, Object[] array2)
| 1426 | * equal according to {@code equals()}, {@code false} otherwise. |
| 1427 | */ |
| 1428 | public static boolean deepEquals(Object[] array1, Object[] array2) { |
| 1429 | if (array1 == array2) { |
| 1430 | return true; |
| 1431 | } |
| 1432 | if (array1 == null || array2 == null || array1.length != array2.length) { |
| 1433 | return false; |
| 1434 | } |
| 1435 | for (int i = 0; i < array1.length; i++) { |
| 1436 | Object e1 = array1[i], e2 = array2[i]; |
| 1437 | |
| 1438 | if (!deepEqualsElements(e1, e2)) { |
| 1439 | return false; |
| 1440 | } |
| 1441 | } |
| 1442 | return true; |
| 1443 | } |
| 1444 | |
| 1445 | private static boolean deepEqualsElements(Object e1, Object e2) { |
| 1446 | Class<?> cl1, cl2; |
no test coverage detected