private int [ ] [ ] getMatrix ( int size ) { logger . info ( "Creating matrix for isotopes combination" ) ; int lengthM = ( int ) Math . pow ( 2 , size ) ; lengthM -- ; // less 1 because the matrix 00000 we don't need int [ ] [ ] matrix = new int [ lengthM ] [ size ] ; int [ ] combi = new int [ size ] ; for ( int j = 0 ; j < size ; j ++ ) { combi [ j ] = 0 ; } int posChang = size - 1 ; int posRemov = size - 1 ; for ( int i = 0 ; i < lengthM ; i ++ ) { // cleaning to zeros for ( int j = posRemov ; j < size ; j ++ ) { combi [ j ] = 0 ; } combi [ posChang ] = 1 ; for ( int j = 0 ; j < size ; j ++ ) matrix [ i ] [ j ] = combi [ j ] ; if ( posChang == size - 1 ) { //find where is zero position, place to change for ( int j = posChang ; j >= 0 ; j -- ) { if ( combi [ j ] == 0 ) { posChang = j ; posRemov = j + 1 ; break ; } } } else { //look for the last zero for ( int j = posChang ; j < size ; j ++ ) { if ( combi [ j ] == 0 ) { posChang = j ; } } } } return matrix ; }
Get the corresponding matrix and create it .