package ru.apetrov.checkEvenNumbers;

import java.util.Iterator;

/**
 * Created by Andrey on 25.02.2017.
 */
public class CheckEvenNumbers implements Iterator {

    private final int[] values;

    private int index = 0;

    public CheckEvenNumbers(int[] values) {
        this.values = values;
    }

    @Override
    public boolean hasNext() {
        boolean result = false;
        if (this.values.length > this.index && this.isEven(this.index)) {
            result = true;
        }
        return result;
    }

    @Override
    public Object next() {
        Integer result;
        if (this.isEven(this.index)) {
            result = this.values[index++];
        } else {
            result = null;
            this.index++;
        }
        return result;
    }

    private boolean isEven(int index) {
        boolean result = false;
        if (this.values[index] % 2 == 0) {
            result = true;
        }
        return result;
    }
}

@@ -575,26 +575,33 @@
 teger result
+ = null
 ;%0A
-
         if (
@@ -665,18 +665,16 @@
 es%5Bindex
-++
 %5D;%0A     
@@ -681,15 +681,8 @@
    %7D
- else %7B
 %0A   
@@ -690,62 +690,16 @@
     
-    result = null;%0A            this.index++;%0A        %7D
+index++;
 %0A   

update CheckEvenNumbers