public static boolean checkDimensions ( final Object object , final int dimX , final int dimY ) { boolean hasGoodDimensions = false ; if ( object != null ) { if ( object . getClass ( ) . isArray ( ) ) { if ( Array . getLength ( object ) == 0 && dimX == 0 ) { // is a 0D Array hasGoodDimensions = true ; } else if ( object . getClass ( ) . getComponentType ( ) . isArray ( ) ) { // is a 2D Array final Object line = Array . get ( object , 0 ) ; if ( dimX * dimY == Array . getLength ( object ) * Array . getLength ( line ) ) { hasGoodDimensions = true ; } } else { // 1 D array final int length = Array . getLength ( object ) ; if ( dimX == length && dimY == 0 ) { hasGoodDimensions = true ; } else if ( dimX * dimY == length ) { hasGoodDimensions = true ; } } } else { // not an array if ( dimX == 1 && dimY == 0 ) { hasGoodDimensions = true ; } } } return hasGoodDimensions ; }
Check of size corresponds to given dimensions