package pro.ru.job4j.iterator;

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

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


    private Iterator[] ar;

    private int position = 0;

    public IteratorInteger(Iterator[] ar) {
        this.ar = ar;
    }

    public void check() {
        if (!ar[position].hasNext()) {
            position++;
        }
    }

    @Override
    public Object next() {
        check();
        return ar[position].next();
    }

    @Override
    public boolean hasNext() {
        if (position == ar.length) {
            return false;
        }
        check();
        if (position == ar.length) {
            return false;
        }
        return ar[position].hasNext();
    }

    @Override
    public Iterator convert(Iterator it) {

        return null;
    }


    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[] mas = new Iterator[]{it1, it2, it3};
        IteratorInteger iter = new IteratorInteger(mas);
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }
        System.out.println(iter.hasNext());
        System.out.println(iter.hasNext());

    }
}

@@ -104,16 +104,39 @@
 terator;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -302,16 +302,54 @@
 Iter %7B%0A%0A
+    private Iterator%3CInteger%3E result;%0A
 %0A    pri
@@ -361,18 +361,35 @@
 Iterator
-%5B%5D
+%3CIterator%3CInteger%3E%3E
  ar;%0A%0A  
@@ -452,18 +452,35 @@
 Iterator
-%5B%5D
+%3CIterator%3CInteger%3E%3E
  ar) %7B%0A 
@@ -511,114 +511,8 @@
  %7D%0A%0A
-    public void check() %7B%0A        if (!ar%5Bposition%5D.hasNext()) %7B%0A            position++;%0A        %7D%0A    %7D%0A%0A
     
@@ -560,44 +560,17 @@
     
-check();%0A        return ar%5Bposition%5D
+return ar
 .nex
@@ -630,198 +630,26 @@
 ) %7B%0A
-        if (position == ar.length) %7B%0A            return false;%0A        %7D%0A        check();%0A        if (position == ar.length) %7B%0A            return false;%0A        %7D%0A        return ar%5Bposition%5D
+%0A        return ar
 .has
@@ -655,32 +655,33 @@
 sNext();%0A    %7D%0A%0A
+%0A
     @Override%0A  
@@ -725,28 +725,384 @@
 ) %7B%0A
-%0A        return null
+        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        IteratorInteger t = new IteratorInteger(it);%0A        while(t.hasNext()) %7B%0A            Iterator current =(Iterator) t.next();%0A            while(current.hasNext()) %7B%0A                list.add((Integer)(current.next()));%0A            %7D%0A        %7D%0A        result = new ArrayList%3CInteger%3E(list).iterator();%0A        return result
 ;%0A  
@@ -1103,24 +1103,25 @@
 lt;%0A    %7D%0A%0A%0A
+%0A
     public s
@@ -1496,32 +1496,47 @@
 ator
-%5B%5D mas = new Iterator%5B%5D%7B
+%3CIterator%3CInteger%3E%3E it = Arrays.asList(
 it1,
@@ -1544,17 +1544,28 @@
 it2, it3
-%7D
+).iterator()
 ;%0A      
@@ -1582,20 +1582,17 @@
 Integer 
-iter
+a
  = new I
@@ -1610,11 +1610,33 @@
 ger(
-mas
+it);%0A        a.convert(it
 );%0A 
@@ -1651,14 +1651,17 @@
 hile
- (iter
+(a.result
 .has
@@ -1705,119 +1705,36 @@
 tln(
-iter.next());%0A        %7D%0A        System.out.println(iter.hasNext());%0A        System.out.println(iter.hasNext());
+a.result.next());%0A        %7D%0A
 %0A%0A  

task 152