static String stringifySolution ( int size , List < List < ColumnName > > solution ) { int [ ] [ ] picture = new int [ size ] [ size ] ; StringBuffer result = new StringBuffer ( ) ; // go through the rows selected in the model and build a picture of the // solution. for ( List < ColumnName > row : solution ) { int x = - 1 ; int y = - 1 ; int num = - 1 ; for ( ColumnName item : row ) { if ( item instanceof ColumnConstraint ) { x = ( ( ColumnConstraint ) item ) . column ; num = ( ( ColumnConstraint ) item ) . num ; } else if ( item instanceof RowConstraint ) { y = ( ( RowConstraint ) item ) . row ; } } picture [ y ] [ x ] = num ; } // build the string for ( int y = 0 ; y < size ; ++ y ) { for ( int x = 0 ; x < size ; ++ x ) { result . append ( picture [ y ] [ x ] ) ; result . append ( " " ) ; } result . append ( "\n" ) ; } return result . toString ( ) ; }
A string containing a representation of the solution .