package ru.job4j;

import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class SimpleList<E> implements ListContainer<E> {
    private Object[] container = new Object[10];
    private int index = 0;

    public SimpleList() {
    }

    @Override
    public void add(E e) {
        if (index >= container.length) {
            arrayUp();
        }
        container[index++] = e;
    }

    private void arrayUp() {
        container = Arrays.copyOf(container, container.length * 2);
    }

    private boolean correctIndex(int pos) {
        return 0 <= pos && pos < index;
    }

    public boolean contains(E e) {
        boolean res = false;
        for(int z = 0; z<index; z++) {
            if(container[z].equals(e)) {
                res = true;
                break;
            }
        }
        return res;
    }

    @Override
    public E get(int pos) {
        if (correctIndex(pos))
            return (E) container[pos];
        else
            throw new NoSuchElementException();
    }


    @Override
    public Iterator<E> iterator() {
        return new Iterator<E>() {
            private int itIndex = 0;

            @Override
            public boolean hasNext() {
                return correctIndex(itIndex);
            }

            @Override
            public E next() {
                if (correctIndex(itIndex))
                    return (E) container[itIndex++];
                else
                    throw new NoSuchElementException();
            }
        };
    }
}

@@ -686,16 +686,43 @@
  false;%0A
+        if (index %3E 0)%0A    
         
@@ -724,16 +724,17 @@
      for
+ 
 (int z =
@@ -738,17 +738,19 @@
 z = 0; z
-%3C
+ %3C 
 index; z
@@ -767,18 +767,23 @@
         
+   
+ 
 if
+ 
 (contain
@@ -797,24 +797,28 @@
 quals(e)) %7B%0A
+    
             
@@ -849,16 +849,20 @@
         
+    
 break;%0A 
@@ -864,34 +864,42 @@
 ak;%0A            
-%7D%0A
+    %7D%0A    
         %7D%0A      

task 996.05