package ru.matevosyan;

/**
 * EvenNumber class.
 * Created on 03.05.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class EvenNumber implements ArrayIterator {

    private int indexX = 0;
    private int indexY = 0;
    private final int[][] array;

    /**
     * DimensionalIterator constructor.
     * @param array two-dimensional array.
     */

    public EvenNumber(int[][] array) {
        this.array = array;
    }

    /**
     * Override the next() method to iterate each element from two-dimensional array.
     * @return arrays element value.
     */

    @Override
    public int next() {
        int value = 0;

        if (array.length % 2 == 0 && array[0].length % 2 == 0) {
            if (indexY < array.length) {
                value = this.array[indexX][indexY++];
            } else if (indexX < array.length) {
                indexY = 0;
                indexX++;
                value = this.array[indexX][indexY++];
            }
        } else {
            if (indexY < array[0].length) {
                value = this.array[indexX][indexY++];
            } else if (indexX < array.length){
                indexY = 0;
                indexX++;
                value = this.array[indexX][indexY++];
            }
        }
        return  value;
    }

    /**
     * Override hasNext() method to check if eny of elements are in array to read, looking to next() pointer.
     * @return true if there are any elements to read, else return false.
     */

    @Override
    public boolean hasNext() {
        boolean has = false;

        if (array.length % 2 == 0 && array[0].length % 2 == 0) {

            if (indexY >= array.length && indexX >= array.length - 1) {
                has = false;
            } else {
                has = true;
            }

        } else if (array.length % 2 != 0 &&  array.length > array[0].length) {

            if (indexX + indexY <= array.length) {
                has = true;
            } else {
                has = false;
            }

        } else if (array.length % 2 == 0 &&  array.length < array[0].length) {
                if (indexX + indexY <= array[0].length) {
                    has = true;
                } else {
                    has = false;
                }
            }
        return has;
    }
}

@@ -195,37 +195,8 @@
 ndex
-X = 0;%0A    private int indexY
  = 0
@@ -216,26 +216,24 @@
  final int%5B%5D
-%5B%5D
  array;%0A%0A   
@@ -356,18 +356,16 @@
 er(int%5B%5D
-%5B%5D
  array) 
@@ -569,16 +569,18 @@
 blic int
+%5B%5D
  next() 
@@ -592,16 +592,18 @@
      int
+%5B%5D
  value =
@@ -607,401 +607,73 @@
 e = 
-0;%0A%0A        if (array.length %25 2 == 0 && array%5B0%5D.length %25 2 == 0) %7B%0A            if (indexY %3C array.length) %7B%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D else if (indexX %3C array.length) %7B%0A                indexY = 0;%0A                indexX++;%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D%0A        %7D else %7B%0A            if (indexY %3C array%5B0%5D.length) 
+new int%5B0%5D;%0A        for (int i = 0; array%5Bindex++%5D %25 2 == 0; i++)
 %7B%0A  
@@ -686,218 +686,34 @@
     
- 
-   
 value
- = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D else if (indexX %3C array.length)%7B%0A                indexY = 0;%0A                indexX++;%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D
+%5Bi++%5D = array%5Bindex%5D;
 %0A   
@@ -1007,762 +1007,35 @@
     
-boolean has = false;%0A%0A        if (array.length %25 2 == 0 && array%5B0%5D.length %25 2 == 0) %7B%0A%0A            if (indexY %3E= array.length && indexX %3E= array.length - 1) %7B%0A                has = false;%0A            %7D else %7B%0A                has = true;%0A            %7D%0A%0A        %7D else if (array.length %25 2 != 0 &&  array.length %3E array%5B0%5D.length) %7B%0A%0A            if (indexX + indexY %3C= array.length) %7B%0A                has = true;%0A            %7D else %7B%0A                has = false;%0A            %7D%0A%0A        %7D else if (array.length %25 2 == 0 &&  array.length %3C array%5B0%5D.length) %7B%0A                if (indexX + indexY %3C= array%5B0%5D.length) %7B%0A                    has = true;%0A                %7D else %7B%0A                    has = false;%0A                %7D%0A            %7D%0A        return has
+return array.length %3E index
 ;%0A  

change logic