All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ma.vi.base.collections.ArrayIterator Maven / Gradle / Ivy

The newest version!
package ma.vi.base.collections;

import java.util.Iterator;

/**
 * An iterator over arrays.
 *
 * @param  The component type of the array to iterate over
 * @author Vikash Madhow ([email protected])
 */
public class ArrayIterator implements Iterator {
  /**
   * Creates an iterator that will iterate over the provided items
   */
  public ArrayIterator(E... items) {
    this.items = items;
  }

  @Override
  public synchronized boolean hasNext() {
    return position < items.length;
  }

  @Override
  public synchronized E next() {
    return items[position++];
  }

  /**
   * Array to iterate over
   */
  private final E[] items;

  /**
   * Current position of iterator which is the position of the item that
   * will be returned by {@link #next()}.
   */
  private int position = 0;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy