1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -277,14 +277,14 @@ public static Object[] toObjectArray(Object source) {
277
277
//---------------------------------------------------------------------
278
278
279
279
/**
280
- * Determine if the given objects are equal, returning {@code true}
281
- * if both are {@code null} or {@code false} if only one is
282
- * {@code null}.
280
+ * Determine if the given objects are equal, returning {@code true} if
281
+ * both are {@code null} or {@code false} if only one is {@code null}.
283
282
* <p>Compares arrays with {@code Arrays.equals}, performing an equality
284
283
* check based on the array elements rather than the array reference.
285
284
* @param o1 first Object to compare
286
285
* @param o2 second Object to compare
287
286
* @return whether the given objects are equal
287
+ * @see Object#equals(Object)
288
288
* @see java.util.Arrays#equals
289
289
*/
290
290
public static boolean nullSafeEquals (Object o1 , Object o2 ) {
@@ -298,33 +298,47 @@ public static boolean nullSafeEquals(Object o1, Object o2) {
298
298
return true ;
299
299
}
300
300
if (o1 .getClass ().isArray () && o2 .getClass ().isArray ()) {
301
- if (o1 instanceof Object [] && o2 instanceof Object []) {
302
- return Arrays .equals ((Object []) o1 , (Object []) o2 );
303
- }
304
- if (o1 instanceof boolean [] && o2 instanceof boolean []) {
305
- return Arrays .equals ((boolean []) o1 , (boolean []) o2 );
306
- }
307
- if (o1 instanceof byte [] && o2 instanceof byte []) {
308
- return Arrays .equals ((byte []) o1 , (byte []) o2 );
309
- }
310
- if (o1 instanceof char [] && o2 instanceof char []) {
311
- return Arrays .equals ((char []) o1 , (char []) o2 );
312
- }
313
- if (o1 instanceof double [] && o2 instanceof double []) {
314
- return Arrays .equals ((double []) o1 , (double []) o2 );
315
- }
316
- if (o1 instanceof float [] && o2 instanceof float []) {
317
- return Arrays .equals ((float []) o1 , (float []) o2 );
318
- }
319
- if (o1 instanceof int [] && o2 instanceof int []) {
320
- return Arrays .equals ((int []) o1 , (int []) o2 );
321
- }
322
- if (o1 instanceof long [] && o2 instanceof long []) {
323
- return Arrays .equals ((long []) o1 , (long []) o2 );
324
- }
325
- if (o1 instanceof short [] && o2 instanceof short []) {
326
- return Arrays .equals ((short []) o1 , (short []) o2 );
327
- }
301
+ return arrayEquals (o1 , o2 );
302
+ }
303
+ return false ;
304
+ }
305
+
306
+ /**
307
+ * Compare the given arrays with {@code Arrays.equals}, performing an equality
308
+ * check based on the array elements rather than the array reference.
309
+ * @param o1 first array to compare
310
+ * @param o2 second array to compare
311
+ * @return whether the given objects are equal
312
+ * @see #nullSafeEquals(Object, Object)
313
+ * @see java.util.Arrays#equals
314
+ */
315
+ private static boolean arrayEquals (Object o1 , Object o2 ) {
316
+ if (o1 instanceof Object [] && o2 instanceof Object []) {
317
+ return Arrays .equals ((Object []) o1 , (Object []) o2 );
318
+ }
319
+ if (o1 instanceof boolean [] && o2 instanceof boolean []) {
320
+ return Arrays .equals ((boolean []) o1 , (boolean []) o2 );
321
+ }
322
+ if (o1 instanceof byte [] && o2 instanceof byte []) {
323
+ return Arrays .equals ((byte []) o1 , (byte []) o2 );
324
+ }
325
+ if (o1 instanceof char [] && o2 instanceof char []) {
326
+ return Arrays .equals ((char []) o1 , (char []) o2 );
327
+ }
328
+ if (o1 instanceof double [] && o2 instanceof double []) {
329
+ return Arrays .equals ((double []) o1 , (double []) o2 );
330
+ }
331
+ if (o1 instanceof float [] && o2 instanceof float []) {
332
+ return Arrays .equals ((float []) o1 , (float []) o2 );
333
+ }
334
+ if (o1 instanceof int [] && o2 instanceof int []) {
335
+ return Arrays .equals ((int []) o1 , (int []) o2 );
336
+ }
337
+ if (o1 instanceof long [] && o2 instanceof long []) {
338
+ return Arrays .equals ((long []) o1 , (long []) o2 );
339
+ }
340
+ if (o1 instanceof short [] && o2 instanceof short []) {
341
+ return Arrays .equals ((short []) o1 , (short []) o2 );
328
342
}
329
343
return false ;
330
344
}
@@ -335,6 +349,7 @@ public static boolean nullSafeEquals(Object o1, Object o2) {
335
349
* this method will delegate to any of the {@code nullSafeHashCode}
336
350
* methods for arrays in this class. If the object is {@code null},
337
351
* this method returns 0.
352
+ * @see Object#hashCode()
338
353
* @see #nullSafeHashCode(Object[])
339
354
* @see #nullSafeHashCode(boolean[])
340
355
* @see #nullSafeHashCode(byte[])
0 commit comments