001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.runtime;
011
012import java.util.Iterator;
013
014public class PrimitiveArrayIterator implements Iterator<Object> {
015
016  private final Object[] array;
017  private int position = 0;
018
019  public PrimitiveArrayIterator(Object[] array) {
020    if (array == null) {
021      this.array = new Object[0];
022    } else {
023      this.array = java.util.Arrays.copyOf(array, array.length);
024    }
025  }
026
027  @Override
028  public boolean hasNext() {
029    return position < array.length;
030  }
031
032  @Override
033  public Object next() {
034    if (hasNext()) {
035      return array[position++];
036    } else {
037      throw new ArrayIndexOutOfBoundsException(position);
038    }
039  }
040
041  @Override
042  public void remove() {
043    throw new UnsupportedOperationException();
044  }
045}