package ru.job4j.ConvertListArr;

import java.util.ArrayList;
import java.util.List;

/**
 * Task convert arr2List and vice versa
 *
 * @author Dmitriy Bobrov (mailto:bobrov.dmitriy@gmail.com)
 * @since 0.1
 */
public class ConvertList {
    /**
     * Class ConvertList.
     */

    /**
     * Private variable.
     */
    private List<Integer> list = new ArrayList<Integer>();
    /**
     * Private variable
     */
    private int[][] arr;

    /**
     * Convert Array to List.
     *
     * @param array Input array.
     * @return ArrayList.
     */
    public List<Integer> toList(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                list.add(array[i][j]);
            }
        }
        return this.list;
    }

    /**
     * Convert List to Array.
     * @param list Input list.
     * @param rows Number of rows.
     * @return Array.
     */
    public int[][] toArray(List<Integer> list, int rows) {
        //Initialization array
        int iter = 0;
        int listSize = list.size();
        if (list.size() % rows == 0) {
            this.arr = new int[rows][listSize / rows];
        } else {
            while (listSize % rows != 0) {
                listSize++;
            }
            this.arr = new int[rows][listSize / rows];
        }

        //Fill array
        for (int i = 0; i < this.arr.length; i++) {
            for (int j = 0; j < this.arr[i].length; j++) {
                if (iter < list.size()) {
                    this.arr[i][j] = list.get(iter++);
                }
            }
        }
        return this.arr;
    }

    /**
     * Convert List<int[]> to List<Integer>
     *
     * @param list Input List.
     * @return List<Integer>.
     */
    public List<Integer> convert(List<int[]> list) {
        for (int[] ints : list) {
            for (int i : ints) {
                this.list.add(i);
            }
        }
        return this.list;
    }
}

@@ -278,174 +278,8 @@
 */%0A%0A
-    /**%0A     * Private variable.%0A     */%0A    private List%3CInteger%3E list = new ArrayList%3CInteger%3E();%0A    /**%0A     * Private variable%0A     */%0A    private int%5B%5D%5B%5D arr;%0A%0A
     
@@ -431,24 +431,79 @@
 %5B%5D array) %7B%0A
+        List%3CInteger%3E list = new ArrayList%3CInteger%3E();%0A
         for 
@@ -665,37 +665,32 @@
 %0A        return 
-this.
 list;%0A    %7D%0A%0A   
@@ -906,24 +906,45 @@
 ation array%0A
+        int%5B%5D%5B%5D arr;%0A
         int 
@@ -1032,37 +1032,32 @@
 ) %7B%0A            
-this.
 arr = new int%5Bro
@@ -1192,21 +1192,16 @@
         
-this.
 arr = ne
@@ -1290,21 +1290,16 @@
  0; i %3C 
-this.
 arr.leng
@@ -1341,21 +1341,16 @@
  0; j %3C 
-this.
 arr%5Bi%5D.l
@@ -1425,21 +1425,16 @@
         
-this.
 arr%5Bi%5D%5Bj
@@ -1512,21 +1512,16 @@
  return 
-this.
 arr;%0A   
@@ -1697,32 +1697,90 @@
 %3Cint%5B%5D%3E list) %7B%0A
+        List%3CInteger%3E listArr = new ArrayList%3CInteger%3E();%0A
         for (int
@@ -1846,25 +1846,23 @@
         
-this.
 list
+Arr
 .add(i);
@@ -1905,17 +1905,15 @@
 urn 
-this.
 list
+Arr
 ;%0A  

Convert List