package pro.ru.job4j.iterator;

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

/**
 * Class IteratorInteger.
 *
 * @author Andrey Lemdyanov {lemdyanov5@mail.ru)
 * @version $Id$
 * @since 0.1
 */
public class IteratorInteger implements IteratorIter {

    private Iterator<Integer> result;

    private Iterator<Iterator<Integer>> ar;

    private int position = 0;

    public IteratorInteger(Iterator<Iterator<Integer>> ar) {
        this.ar = ar;
    }

    @Override
    public Object next() {
        return ar.next();
    }

    @Override
    public boolean hasNext() {

        return ar.hasNext();
    }


    @Override
    public Iterator convert(Iterator it) {
        List<Integer> list = new ArrayList<>();
        IteratorInteger t = new IteratorInteger(it);
        while(t.hasNext()) {
            Iterator current =(Iterator) t.next();
            while(current.hasNext()) {
                list.add((Integer)(current.next()));
            }
        }
        result = new ArrayList<Integer>(list).iterator();
        return result;
    }



    public static void main(String[] args) {
        Iterator<Integer> it1 = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5, 6, 7)).iterator();
        Iterator<Integer> it2 = new ArrayList<Integer>(Arrays.asList(11, 22, 33, 44, 55, 66, 77)).iterator();
        Iterator<Integer> it3 = new ArrayList<Integer>(Arrays.asList(10, 20, 30, 40, 50, 60, 70)).iterator();
        Iterator<Iterator<Integer>> it = Arrays.asList(it1, it2, it3).iterator();
        IteratorInteger a = new IteratorInteger(it);
        a.convert(it);
        while(a.result.hasNext()) {
            System.out.println(a.result.next());
        }


    }
}

@@ -108,31 +108,8 @@
 tor;
-%0Aimport java.util.List;
 %0A%0A/*
@@ -275,24 +275,65 @@
 atorIter %7B%0A%0A
+    private Iterator%3CInteger%3E current;%0A//
     private 
@@ -408,38 +408,8 @@
 r;%0A%0A
-    private int position = 0;%0A
 %0A   
@@ -488,16 +488,50 @@
 r = ar;%0A
+        this.current = ar.next();%0A
     %7D%0A%0A 
@@ -578,25 +578,211 @@
         
-return ar
+if (current.hasNext()) %7B%0A            return current.next();%0A        %7D else if (ar.hasNext()) %7B%0A            current = ar.next();%0A            return current.next();%0A        %7D%0A        return current
 .next();
@@ -849,16 +849,37 @@
   return
+ current.hasNext() %7C%7C
  ar.hasN
@@ -946,24 +946,26 @@
 rator it) %7B%0A
+//
         List
@@ -996,24 +996,26 @@
 ayList%3C%3E();%0A
+//
         Iter
@@ -1047,32 +1047,34 @@
 torInteger(it);%0A
+//
         while(t.
@@ -1070,16 +1070,17 @@
    while
+ 
 (t.hasNe
@@ -1079,32 +1079,34 @@
 (t.hasNext()) %7B%0A
+//
             Iter
@@ -1119,16 +1119,17 @@
 urrent =
+ 
 (Iterato
@@ -1133,32 +1133,34 @@
 ator) t.next();%0A
+//
             whil
@@ -1160,16 +1160,17 @@
    while
+ 
 (current
@@ -1175,32 +1175,34 @@
 nt.hasNext()) %7B%0A
+//
                 
@@ -1219,16 +1219,17 @@
 Integer)
+ 
 (current
@@ -1235,24 +1235,26 @@
 t.next()));%0A
+//
             
@@ -1247,32 +1247,34 @@
 //            %7D%0A
+//
         %7D%0A      
@@ -1259,32 +1259,34 @@
   %7D%0A//        %7D%0A
+//
         result =
@@ -1327,24 +1327,26 @@
 ator();%0A
+//
         
 return r
@@ -1341,21 +1341,85 @@
     
-return result
+while (t.hasNext()) %7B%0A//            t.next();%0A//        %7D%0A        return this
 ;%0A  
@@ -1424,17 +1424,16 @@
     %7D%0A%0A%0A
-%0A
     publ
@@ -1931,31 +1931,8 @@
 t);%0A
-        a.convert(it);%0A
     
@@ -1940,26 +1940,20 @@
    while
+ 
 (a.
-result.
 hasNext(
@@ -1994,15 +1994,8 @@
 n(a.
-result.
 next
@@ -2005,22 +2005,62 @@
 ;%0A        %7D%0A
+        System.out.println(a.hasNext());
 %0A%0A    %7D%0A%7D%0A

task 152