package ru.elazarev.iterator;

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

/**
 * Iterator for even numbers.
 * @author Eugene Lazarev mailto(helycopternicht@rambler.ru)
 * @since 25.05.17
 */
public class EvenNumbersIterator implements Iterator<Integer> {
    /**
     * Storage for even numbers.
     */
    private List<Integer> storage;
    /**
     * Current index of storage.
     */
    private int index;

    /**
     * Default constructor.
     * @param sourceArr - for iterate even numbers
     */
    public EvenNumbersIterator(int[] sourceArr) {
        this.storage = new ArrayList<>();
        for (int i = 0; i < sourceArr.length; i++) {
            if (sourceArr[i] % 2 == 0) {
                this.storage.add(sourceArr[i]);
            }
        }
    }

    /**
     * If index out of range eben numbers then false else true.
     * @return true or false
     */
    @Override
    public boolean hasNext() {
        return index < this.storage.size();
    }

    /**
     * Returns next even number.
     * @throws NoSuchElementException if have not more elements.
     * @return next even number
     */
    @Override
    public Integer next() {
        if (index >= this.storage.size()) {
            throw new NoSuchElementException("No such element");
        }
        return this.storage.get(index++);
    }
}

@@ -45,67 +45,16 @@
 til.
-ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List
+Iterator
 ;%0Aim
@@ -294,32 +294,43 @@
   * 
-Storage for even numbers
+ref to array that we should iterate
 .%0A  
@@ -351,21 +351,13 @@
 ate 
-List%3CInteger%3E
+int%5B%5D
  sto
@@ -607,396 +607,887 @@
 e = 
-new ArrayList%3C%3E();%0A        for (int i = 0; i %3C sourceArr.length; i++) %7B
+sourceArr;%0A    %7D%0A%0A    /**%0A     * If index out of range eben numbers then false else true.%0A     * @return true or false%0A     */%0A    @Override%0A    public boolean hasNext() %7B%0A        return index %3C this.storage.length && arrayHasEvenNumbersBeginFromIndex();%0A    %7D%0A
 %0A    
+/**%0A
      
-  
+* Returns true
  if 
-(
+in 
 source
-Arr%5Bi%5D %25 2 == 0) %7B%0A                this.storage.add(sourceArr%5Bi%5D);%0A            %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     * If index out of range eben numbers then false else true.%0A     * @return true or false%0A     */%0A    @Override%0A    public boolean hasNext() %7B%0A        return index %3C this.storage.size()
+ array in range from cur index to end of array have%0A     * at least one eben element.%0A     * @return - true or false%0A     */%0A    private boolean arrayHasEvenNumbersBeginFromIndex() %7B%0A        for (int i = this.index; i %3C this.storage.length; i++) %7B%0A            if (isEven(this.storage%5Bi%5D)) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A    /**%0A     * Returns true if num is even or false if it is not.%0A     * @param num - number to check%0A     * @return true or false%0A     */%0A    private boolean isEven(int num) %7B%0A        return num %25 2 == 0
 ;%0A  
@@ -1691,20 +1691,27 @@
     
-if (
+for (; this.
 index 
-%3E=
+%3C
  thi
@@ -1724,82 +1724,83 @@
 age.
-size()) %7B%0A            throw new NoSuchElementException(%22No such element%22);
+length; this.index++) %7B%0A            if (isEven(this.storage%5Bthis.index%5D)) %7B
 %0A   
@@ -1796,34 +1796,32 @@
 ex%5D)) %7B%0A        
-%7D%0A
         return t
@@ -1835,20 +1835,115 @@
 rage
-.get(
+%5Bthis.
 index++
+%5D;%0A            %7D%0A        %7D%0A%0A        throw new NoSuchElementException(%22Has no more even number%22
 );%0A 

Fix EvenNumbersIterator