package ru.matevosyan;

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

public class NaturalNumber implements NaturalNumberIterator {

    private int index = 0;
    private final int[] array;

    /**
     * EvenNumber constructor.
     * @param array an array.
     */

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

    /**
     * Override the next() method to iterate each element from an array.
     * @return even numbers from an array.
     */

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

            if (isSimpleOrNot() || checkNextIndex()) {
                result = this.array[this.index];
                checkNextIndex();
            }

        return result;

    }

    /**
     * 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() {
        return this.array.length > this.index && (isSimpleOrNot()|| checkNextIndex());
    }

    private boolean checkNextIndex() {
        boolean check = true;
        while (this.array.length > this.index) {
            this.index++;
            if (this.array.length > this.index) {
                check = isSimpleOrNot();
                break;
            }

        }
        return check;
    }

    private boolean isSimpleOrNot() {

        boolean isSimple = true;

        if (this.array[this.index] == 1) {
            isSimple = false;
        }

        for (int i = 2; i <= Math.sqrt(this.array[this.index]); i++) {
            if (this.array[this.index] % i == 0) {
                isSimple = false;
                break;
            }
        }

        return isSimple;
    }
}

@@ -443,42 +443,55 @@
  to 
-iterate each element from an array
+return current number and increment index value
 .%0A  
@@ -507,12 +507,14 @@
 urn 
-even
+simple
  num
@@ -846,22 +846,34 @@
  if 
-eny of
+there are a simple
  element
 s ar
@@ -872,13 +872,8 @@
 ment
-s are
  in 
@@ -889,35 +889,8 @@
 read
-, looking to next() pointer
 .%0A  
@@ -1101,32 +1101,156 @@
 ndex());%0A    %7D%0A%0A
+    /**%0A     * Check if next element is simple and increment index.%0A     * @return true if next element is simple.%0A     */%0A%0A
     private bool
@@ -1538,23 +1538,114 @@
  check;%0A
-
     %7D%0A%0A
+    /**%0A     * Check if umber is simple.%0A     * @return true if number is simple.%0A     */%0A%0A
     priv

add javadoc