package Iterator;

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

/**
 * Created by user8.3 on 30.05.2017.
 */
public class IteratorIterator {
    public static void main(String[] args) {
        Iterator<Integer> first = Arrays.asList(1, 2, 3).iterator();
        Iterator<Integer> second = Arrays.asList(4, 5, 6).iterator();
        Iterator<Iterator<Integer>> it = Arrays.asList(first, second).iterator();
        Iterator<Integer> iter = convert(it);
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }
    }

    private static Iterator<Integer> convert(Iterator<Iterator<Integer>> it) {
        It iterator = new It(it);
        int j= 0;
        return iterator;
    }
    public static class It implements Iterator {
        private Iterator<Iterator<Integer>> list;
        private ArrayList<Iterator<Integer>> arrayList = new ArrayList<>();
        int index = 0;

        public It(Iterator<Iterator<Integer>> list) {
            this.list = list;
            while (list.hasNext()) {
                arrayList.add(list.next());
            }
        }

        @Override
        public boolean hasNext() {
            if (index < arrayList.size()) {
                if (arrayList.get(index).hasNext()) {
                    return true;
                } else {
                    if (index + 1 < arrayList.size()) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public Object next() {
            if (arrayList.get(index).hasNext()) {
                return arrayList.get(index).next();
            } else {
                return arrayList.get(++index).next();
            }
        }

        @Override
        public void remove() {
        }
    }
}
@@ -195,428 +195,186 @@
 tor 
-%7B%0A    public static void main(String%5B%5D args) %7B%0A        Iterator%3CInteger%3E first = Arrays.asList(1, 2, 3).iterator();%0A        Iterator%3CInteger%3E second = Arrays.asList(4, 5, 6).iterator();%0A        Iterator%3CIterator%3CInteger%3E%3E it = Arrays.asList(first, second).iterator();%0A        Iterator%3CInteger%3E iter = convert(it);%0A        while (iter.hasNext()) %7B%0A            System.out.println(iter.next());%0A        %7D%0A    %7D
+implements Iterator %7B%0A    private Iterator%3CIterator%3CInteger%3E%3E list;%0A    private ArrayList%3CIterator%3CInteger%3E%3E arrayList = new ArrayList%3C%3E();%0A    private int index = 0;
 %0A%0A    p
-rivate
+ublic
  sta
@@ -447,16 +447,30 @@
       It
+eratorIterator
  iterato
@@ -479,16 +479,30 @@
 = new It
+eratorIterator
 (it);%0A  
@@ -512,16 +512,17 @@
    int j
+ 
 = 0;%0A   
@@ -545,24 +545,25 @@
 ator;%0A    %7D%0A
+%0A
     public s
@@ -565,213 +565,24 @@
 lic 
-static class It implements Iterator %7B%0A        private Iterator%3CIterator%3CInteger%3E%3E list;%0A        private ArrayList%3CIterator%3CInteger%3E%3E arrayList = new ArrayList%3C%3E();%0A        int index = 0;%0A%0A        public It
+IteratorIterator
 (Ite
@@ -622,20 +622,16 @@
         
-   
- 
 this.lis
@@ -640,20 +640,16 @@
 = list;%0A
-    
         
@@ -685,20 +685,16 @@
         
- 
-   
 arrayLis
@@ -721,37 +721,25 @@
         
-  
-  %7D%0A    
+%7D%0A
     %7D%0A%0A
-    
     @Ove
@@ -744,28 +744,24 @@
 verride%0A    
- 
-   
 public boole
@@ -767,36 +767,32 @@
 ean hasNext() %7B%0A
-    
         if (inde
@@ -807,36 +807,32 @@
 yList.size()) %7B%0A
-    
             if (
@@ -873,36 +873,32 @@
                 
-    
 return true;%0A   
@@ -898,36 +898,32 @@
 ue;%0A            
-    
 %7D else %7B%0A       
@@ -927,28 +927,24 @@
             
-  
-  
 if (index + 
@@ -979,36 +979,32 @@
                 
-    
 return true;%0A   
@@ -1008,36 +1008,32 @@
                 
-    
 %7D%0A              
@@ -1030,33 +1030,26 @@
         
- 
-   %7D%0A   
+%7D%0A
         
  %7D%0A     
@@ -1032,39 +1032,34 @@
       %7D%0A        
- 
 %7D%0A
-    
         return f
@@ -1064,35 +1064,27 @@
  false;%0A    
-    %7D%0A%0A    
+%7D%0A%0A
     @Overrid
@@ -1093,25 +1093,22 @@
     
-   
- 
 public 
-Object
+Integer
  nex
@@ -1109,28 +1109,24 @@
 er next() %7B%0A
-    
         if (
@@ -1163,36 +1163,32 @@
 ) %7B%0A            
-    
 return arrayList
@@ -1207,36 +1207,32 @@
 next();%0A        
- 
-   
 %7D else %7B%0A       
@@ -1216,36 +1216,32 @@
        %7D else %7B%0A
-    
             retu
@@ -1270,28 +1270,24 @@
 ex).next();%0A
-    
         %7D%0A  
@@ -1288,27 +1288,19 @@
   %7D%0A    
-    %7D%0A%0A    
+%7D%0A%0A
     @Ove
@@ -1309,20 +1309,16 @@
 ide%0A    
-   
- 
 public v
@@ -1332,25 +1332,16 @@
 ove() %7B%0A
-        %7D
 %0A    %7D%0A%7D

task 151