public static Object fromArrayTo2DArray ( final Object array , final int dimX , final int dimY ) throws DevFailed { Object array2D = null ; // final Profiler profilerPeriod = new Profiler("fromArrayTo2DArray"); // profilerPeriod.start("fromArrayTo2DArray"); if ( array . getClass ( ) . isArray ( ) ) { if ( dimY > 0 ) { // to a 2D Array array2D = Array . newInstance ( array . getClass ( ) . getComponentType ( ) , dimY , dimX ) ; for ( int y = 0 ; y < dimY ; y ++ ) { final Object line = Array . get ( array2D , y ) ; System . arraycopy ( array , y * dimX , line , 0 , Array . getLength ( line ) ) ; } } else { array2D = Array . newInstance ( array . getClass ( ) . getComponentType ( ) , Array . getLength ( array ) ) ; System . arraycopy ( array , 0 , array2D , 0 , Array . getLength ( array ) ) ; } } else { array2D = array ; } // profilerPeriod.stop().print(); return array2D ; }
Convert an array to a 2D array