package ru.agolovin;

import java.util.Iterator;

/**
 * @author agolovin (agolovin@list.ru)
 * @version $Id$
 * @since 0.1
 */
public class ArrayIterator implements Iterator<Integer> {


    /**
     * inner array int[][].
     */
    private int[][] array;

    /**
     * Current row index.
     */
    private int rowIndex;

    /**
     * Current column index.
     */
    private int colIndex;

    /**
     * Constructor.
     *
     * @param array int[][]
     */
    ArrayIterator(int[][] array) {
        this.array = array;
    }

    @Override
    public boolean hasNext() {
        boolean result = false;
        if (this.array.length > rowIndex && this.array[rowIndex].length > colIndex) {
            result = true;
        }
        return result;
    }

    @Override
    public Integer next() {
        int result;
        if (hasNext()) {
            result = this.array[rowIndex][colIndex++];
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
        if (colIndex > this.array[rowIndex].length - 1) {
            rowIndex++;
            colIndex = 0;
        }
        return result;
    }
}

@@ -915,87 +915,8 @@
     
-    %7D else %7B%0A            throw new ArrayIndexOutOfBoundsException();%0A        %7D%0A
     
@@ -981,16 +981,20 @@
         
+    
 rowIndex
@@ -997,16 +997,20 @@
 ndex++;%0A
+    
         
@@ -1027,16 +1027,103 @@
 ex = 0;%0A
+            %7D%0A        %7D else %7B%0A            throw new ArrayIndexOutOfBoundsException();%0A
         

add task1 in chapter5_pro package2