mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
add Arrays test for equals and hashCode, handle corner cases with null
This commit is contained in:
parent
b034d11221
commit
fffde5f445
@ -43,15 +43,25 @@ public class Arrays {
|
||||
}
|
||||
|
||||
public static int hashCode(Object[] array) {
|
||||
if(array == null) {
|
||||
return 9023;
|
||||
}
|
||||
|
||||
int hc = 823347;
|
||||
for(Object o : array) {
|
||||
hc += o.hashCode();
|
||||
hc += o != null ? o.hashCode() : 54267;
|
||||
hc *= 3;
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
public static boolean equals(Object[] a, Object[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
|
@ -77,5 +77,22 @@ public class Arrays {
|
||||
array[0] = Integer.valueOf(42);
|
||||
expect(array[0].intValue() == 42);
|
||||
}
|
||||
|
||||
{ Object[] a = new Object[3];
|
||||
Object[] b = new Object[3];
|
||||
|
||||
expect(java.util.Arrays.equals(a, b));
|
||||
a[0] = new Object();
|
||||
expect(! java.util.Arrays.equals(a, b));
|
||||
expect(! java.util.Arrays.equals(b, new Object[4]));
|
||||
expect(! java.util.Arrays.equals(b, null));
|
||||
expect(! java.util.Arrays.equals(a, b));
|
||||
expect(java.util.Arrays.equals(null, null));
|
||||
b[0] = a[0];
|
||||
expect(java.util.Arrays.equals(a, b));
|
||||
|
||||
java.util.Arrays.hashCode(a);
|
||||
java.util.Arrays.hashCode(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user