1111import java .io .PrintWriter ;
1212import java .nio .file .Files ;
1313import java .nio .file .Paths ;
14+ import java .util .ArrayList ;
1415import java .util .Comparator ;
1516import java .util .Formatter ;
1617import java .util .List ;
@@ -30,29 +31,27 @@ private IoUtils() {
3031 * @return 2d array representing a pizza
3132 * @throws IOException parsing fail
3233 */
33- public static Cell [][] parsePizza (String file ) throws IOException {
34+ public static List < Cell > parsePizza (String file ) throws IOException {
3435 try (FileReader fileReader = new FileReader (file )) {
3536 BufferedReader br = new BufferedReader (fileReader );
36- //parse the first line
37- String [] headerTokens = br .readLine ().split (" " );
38- int rowsCount = Integer .parseInt (headerTokens [0 ]);
39- int columnsCount = Integer .parseInt (headerTokens [1 ]);
37+ //skip a line with slice instructions
38+ br .readLine ();
4039 //declare a pizza cells array
41- Cell [][] ingredients = new Cell [ rowsCount ][ columnsCount ] ;
40+ List < Cell > cells = new ArrayList <>() ;
4241 int row = 0 ;
4342 String fileLine ;
4443 while ((fileLine = br .readLine ()) != null ) {
4544 for (int column = 0 ; column < fileLine .length (); column ++) {
4645 Character literal = fileLine .charAt (column );
4746 if (literal .toString ().equals (Ingredient .TOMATO .toString ())) {
48- ingredients [ row ][ column ] = new Cell (column , row , Ingredient .TOMATO );
47+ cells . add ( new Cell (column , row , Ingredient .TOMATO ) );
4948 } else if (literal .toString ().equals (Ingredient .MUSHROOM .toString ())) {
50- ingredients [ row ][ column ] = new Cell (column , row , Ingredient .MUSHROOM );
49+ cells . add ( new Cell (column , row , Ingredient .MUSHROOM ) );
5150 }
5251 }
5352 row ++;
5453 }
55- return ingredients ;
54+ return cells ;
5655 }
5756 }
5857
0 commit comments