001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit http://imagingbook.com for additional details. 008 *******************************************************************************/ 009 010package imagingbook.lib.util; 011 012 013import java.util.Iterator; 014import java.util.NoSuchElementException; 015 016/** 017 * This utility class implements a basic iterator for arbitrary arrays. 018 */ 019public class ArrayIterator<T> implements Iterator<T> { 020 021 private int next; 022 private T[] data; 023 024 public ArrayIterator(T[] data) { 025 this.data = data; 026 next = 0; 027 } 028 029 public boolean hasNext() { 030 return next < data.length; 031 } 032 033 public T next() { 034 if (hasNext()) 035 return data[next++]; 036 else 037 throw new NoSuchElementException(); 038 } 039 040 public void remove() { 041 throw new UnsupportedOperationException(); 042 } 043}