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