/*
 * Copyright (c) 2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 *
 */

package com.jscape.util.collections;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @author Alex Usun
 */
public class ArrayIterator<T>
        implements Iterator<T> {

    /**
     * Data.
     */
    private final T[] data;
    /**
     * Index.
     */
    private int index;

    /**
     * @param data data
     * @param <T>  data
     *
     * @return arrayIterator
     */
    public static <T> Iterator<T> iterator(T[] data) {
        return new ArrayIterator<T>(data);
    }

    /**
     * @param data data
     */
    public ArrayIterator(T[] data) {
        this.data = data;
        this.index = -1;
    }

    /**
     * @return boolean value
     */
    public boolean hasNext() {
        return this.index < this.data.length - 1;
    }

    /**
     * @return T
     */
    public T next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }

        return this.data[++this.index];
    }

    /** */
    public void remove() {
        throw new UnsupportedOperationException("Remove operation not supported.");
    }
}
