public static boolean arrayEquals(Object x,Object y,double tolf,double told){
  if (x == null && y == null) {
    return true;
  }
  if (x == null || y == null) {
    return false;
  }
  Class<?> xClass=x.getClass();
  Class<?> yClass=y.getClass();
  if (xClass != yClass) {
    return false;
  }
  if (!xClass.isArray()) {
    return x.equals(y);
  }
 else {
    if (xClass.equals(int[].class)) {
      return Arrays.equals((int[])x,(int[])y);
    }
 else     if (xClass.equals(double[].class)) {
      if (told == 0) {
        return Arrays.equals((double[])x,(double[])y);
      }
 else {
        return doubleArrayEquals((double[])x,(double[])y,told);
      }
    }
 else     if (xClass.equals(long[].class)) {
      return Arrays.equals((long[])x,(long[])y);
    }
 else     if (xClass.equals(float[].class)) {
      if (tolf == 0) {
        return Arrays.equals((float[])x,(float[])y);
      }
 else {
        return floatArrayEquals((float[])x,(float[])y,(float)tolf);
      }
    }
 else     if (xClass.equals(byte[].class)) {
      return Arrays.equals((byte[])x,(byte[])y);
    }
 else     if (xClass.equals(short[].class)) {
      return Arrays.equals((short[])x,(short[])y);
    }
 else     if (xClass.equals(char[].class)) {
      return Arrays.equals((char[])x,(char[])y);
    }
 else     if (xClass.equals(boolean[].class)) {
      return Arrays.equals((boolean[])x,(boolean[])y);
    }
 else {
      Object[] xo=(Object[])x;
      Object[] yo=(Object[])y;
      if (xo.length != yo.length) {
        return false;
      }
      for (int i=0; i < xo.length; i+=1) {
        if (!arrayEquals(xo[i],yo[i],tolf,told)) {
          return false;
        }
      }
      return true;
    }
  }
}

public static boolean arrayEquals ( Object x , Object y , double tolf , double told ) { if ( x == null && y == null ) { return true ; } if ( x == null || y == null ) { return false ; } Class < ? > xClass = x . getClass ( ) ; Class < ? > yClass = y . getClass ( ) ; if ( xClass != yClass ) { return false ; } if ( ! xClass . isArray ( ) ) { return x . equals ( y ) ; } else { if ( xClass . equals ( int [ ] . class ) ) { return Arrays . equals ( ( int [ ] ) x , ( int [ ] ) y ) ; } else if ( xClass . equals ( double [ ] . class ) ) { if ( told == 0 ) { return Arrays . equals ( ( double [ ] ) x , ( double [ ] ) y ) ; } else { return doubleArrayEquals ( ( double [ ] ) x , ( double [ ] ) y , told ) ; } } else if ( xClass . equals ( long [ ] . class ) ) { return Arrays . equals ( ( long [ ] ) x , ( long [ ] ) y ) ; } else if ( xClass . equals ( float [ ] . class ) ) { if ( tolf == 0 ) { return Arrays . equals ( ( float [ ] ) x , ( float [ ] ) y ) ; } else { return floatArrayEquals ( ( float [ ] ) x , ( float [ ] ) y , ( float ) tolf ) ; } } else if ( xClass . equals ( byte [ ] . class ) ) { return Arrays . equals ( ( byte [ ] ) x , ( byte [ ] ) y ) ; } else if ( xClass . equals ( short [ ] . class ) ) { return Arrays . equals ( ( short [ ] ) x , ( short [ ] ) y ) ; } else if ( xClass . equals ( char [ ] . class ) ) { return Arrays . equals ( ( char [ ] ) x , ( char [ ] ) y ) ; } else if ( xClass . equals ( boolean [ ] . class ) ) { return Arrays . equals ( ( boolean [ ] ) x , ( boolean [ ] ) y ) ; } else { Object [ ] xo = ( Object [ ] ) x ; Object [ ] yo = ( Object [ ] ) y ; if ( xo . length != yo . length ) { return false ; } for ( int i = 0 ; i < xo . length ; i += 1 ) { if ( ! arrayEquals ( xo [ i ] , yo [ i ] , tolf , told ) ) { return false ; } } return true ; } } }
are two objects equal ? arrays have the standard object equals method which only returns true if the two object are the same . this method returns true if every element of the arrays match . the inputs may be of any dimensionality . the dimensionality and dimensions of the arrays must match as well as any elements . if the elements are non - primitive . non - tiledimageoperation objects , then the equals method is called for each element . if both elements are multi - dimensional arrays , then the method recurses .
