package ru.job4j.convertation;

import java.util.ArrayList;
//import java.util.Arrays;
import java.util.List;

/**
 * Convert array[][] to List and back.
 */
public class ConvertList {
    List<Integer> list = new ArrayList<>();

    /**
     * Convert array[][] to List.
     * @param array - array.
     * @return - list.
     */
    public List<Integer> toList (int[][] array) {
        for (int[] temp1 : array) {
            for (int temp2 : temp1) {
                list.add(temp2);
            }
        }
        System.out.println(list);
        return list;
    }

    /**
     * Convert List to array[][].
     * @param list - list.
     * @param rows - rows of returned array.
     * @return - array[][].
     */
    public int[][] toArray (List<Integer> list, int rows) {
        int count = 0;
        int countInRow;
        if (list.size() % rows != 0) {
            countInRow = list.size() / rows + 1;
        } else {
            countInRow = list.size() / rows;
        }

        Integer[] arrLine = new Integer[rows * countInRow];
        arrLine = list.toArray(arrLine);
        for (int i = 0; i < arrLine.length; i++) {
            if (arrLine[i] == null) {
                arrLine[i] = 0;
            }
        }

        int[][] arrSquare = new int[rows][countInRow];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < countInRow; j++) {
                arrSquare[i][j] = arrLine[count++];
            }
        }
        return arrSquare;
    }
}
/*
public class ConvertList {
    public static void main(String[] args) {
        Convert convert = new Convert();
        int[][] arrAdd = {{1, 2, 3}, {4, 5, 6}, {7}};
        convert.list = convert.toList(arrAdd);
        int[][] arr = convert.toArray(convert.list, 3);
        for (int tempArr[] : arr) {
            System.out.println(Arrays.toString(tempArr));
        }
    }
}
*/
@@ -151,23 +151,16 @@
 ck.%0A */%0A
-public 
 class Co
@@ -214,16 +214,66 @@
 ist%3C%3E();
+%0A    //List%3Cint%5B%5D%3E listIntArr = new ArrayList%3C%3E();
 %0A%0A    /*
@@ -1530,16 +1530,411 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * Convert List%3Cint%5B%5D%3E to List%3CInteger%3E.%0A     * @param list - List%3Cint%5B%5D%3E.%0A     * @return - List%3CInteger%3E.%0A     */%0A    public List%3CInteger%3E convert (List%3Cint%5B%5D%3E list) %7B%0A        List%3CInteger%3E result = new ArrayList%3C%3E();%0A        for (int%5B%5D intArr : list) %7B%0A            for (int intEl : intArr) %7B%0A                result.add(intEl);%0A            %7D%0A        %7D%0A        return result;%0A    %7D
 %0A%7D%0A/*%0Apu
@@ -2026,16 +2026,18 @@
  convert
+Ob
  = new C
@@ -2111,24 +2111,26 @@
      convert
+Ob
 .list = conv
@@ -2132,16 +2132,18 @@
  convert
+Ob
 .toList(
@@ -2180,16 +2180,18 @@
  convert
+Ob
 .toArray
@@ -2198,16 +2198,18 @@
 (convert
+Ob
 .list, 3
@@ -2311,22 +2311,304 @@
 ;%0A        %7D%0A
+        convertOb.listIntArr.add(new int%5B%5D%7B1, 2%7D);%0A        convertOb.listIntArr.add(new int%5B%5D%7B3, 4, 5, 6%7D);%0A        convertOb.listIntArr.add(new int%5B%5D%7B7, 8, 9, 10, 11, 12%7D);%0A        List%3CInteger%3E result = convertOb.convert(convertOb.listIntArr);%0A        System.out.println(result);%0A
     %7D%0A%7D%0A*/

Task #10037