mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
implement Arrays.deepEquals and Objects.deepEquals
This commit is contained in:
@ -305,6 +305,132 @@ public class Arrays {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean equals(int[] a, int[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean equals(long[] a, long[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean equals(short[] a, short[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean equals(char[] a, char[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean equals(float[] a, float[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean equals(double[] a, double[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean deepEquals(Object[] a, Object[] b) {
|
||||
if(a == b) {
|
||||
return true;
|
||||
}
|
||||
if(a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
if(a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(!Objects.deepEquals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static <T> List<T> asList(final T ... array) {
|
||||
return new AbstractList<T>() {
|
||||
@Override
|
||||
|
@ -17,7 +17,25 @@ public final class Objects {
|
||||
return true;
|
||||
if (x == null || y == null)
|
||||
return false;
|
||||
throw new UnsupportedOperationException("deepEquals is not implemented yet.");
|
||||
if (x.getClass().isArray()) {
|
||||
if(x instanceof Object[] && y instanceof Object[])
|
||||
return Arrays.deepEquals((Object[])x, (Object[])y);
|
||||
if(x instanceof byte[] && y instanceof byte[])
|
||||
return Arrays.equals((byte[]) x, (byte[]) y);
|
||||
if(x instanceof int[] && y instanceof int[])
|
||||
return Arrays.equals((int[]) x, (int[]) y);
|
||||
if(x instanceof long[] && y instanceof long[])
|
||||
return Arrays.equals((long[]) x, (long[]) y);
|
||||
if(x instanceof short[] && y instanceof short[])
|
||||
return Arrays.equals((short[]) x, (short[]) y);
|
||||
if(x instanceof char[] && y instanceof char[])
|
||||
return Arrays.equals((char[]) x, (char[]) y);
|
||||
if(x instanceof float[] && y instanceof float[])
|
||||
return Arrays.equals((float[]) x, (float[]) y);
|
||||
if(x instanceof double[] && y instanceof double[])
|
||||
return Arrays.equals((double[]) x, (double[]) y);
|
||||
}
|
||||
return x.equals(y);
|
||||
}
|
||||
|
||||
public static boolean equals(final Object x, final Object y) {
|
||||
|
Reference in New Issue
Block a user