src/core/net/sf/basedb/util/ArrayIterator.java

Code
Comments
Other
Rev Date Author Line
29 22 Feb 05 nicklas 1 /*
192 17 Mar 05 jari 2   $Id$
29 22 Feb 05 nicklas 3
4889 06 Apr 09 nicklas 4   Copyright (C) 2005 Jari Häkkinen, Nicklas Nordborg
4889 06 Apr 09 nicklas 5   Copyright (C) 2006 Jari Häkkinen
29 22 Feb 05 nicklas 6
2304 22 May 06 jari 7   This file is part of BASE - BioArray Software Environment.
2304 22 May 06 jari 8   Available at http://base.thep.lu.se/
29 22 Feb 05 nicklas 9
29 22 Feb 05 nicklas 10   BASE is free software; you can redistribute it and/or
29 22 Feb 05 nicklas 11   modify it under the terms of the GNU General Public License
4479 05 Sep 08 jari 12   as published by the Free Software Foundation; either version 3
29 22 Feb 05 nicklas 13   of the License, or (at your option) any later version.
29 22 Feb 05 nicklas 14
29 22 Feb 05 nicklas 15   BASE is distributed in the hope that it will be useful,
29 22 Feb 05 nicklas 16   but WITHOUT ANY WARRANTY; without even the implied warranty of
29 22 Feb 05 nicklas 17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 22 Feb 05 nicklas 18   GNU General Public License for more details.
29 22 Feb 05 nicklas 19
29 22 Feb 05 nicklas 20   You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 21   along with BASE. If not, see <http://www.gnu.org/licenses/>.
29 22 Feb 05 nicklas 22 */
29 22 Feb 05 nicklas 23 package net.sf.basedb.util;
29 22 Feb 05 nicklas 24
29 22 Feb 05 nicklas 25 import java.util.Iterator;
29 22 Feb 05 nicklas 26 import java.util.NoSuchElementException;
29 22 Feb 05 nicklas 27
29 22 Feb 05 nicklas 28 /**
29 22 Feb 05 nicklas 29   This class implements the {@link Iterator} interface
29 22 Feb 05 nicklas 30   for an array of objects.
29 22 Feb 05 nicklas 31
29 22 Feb 05 nicklas 32   @author Nicklas
29 22 Feb 05 nicklas 33   @version 2.0
29 22 Feb 05 nicklas 34 */
29 22 Feb 05 nicklas 35 public class ArrayIterator<E>
29 22 Feb 05 nicklas 36   implements Iterator<E>
29 22 Feb 05 nicklas 37 {
29 22 Feb 05 nicklas 38   /**
29 22 Feb 05 nicklas 39     The array to iterate.
29 22 Feb 05 nicklas 40   */
29 22 Feb 05 nicklas 41   private final E[] array;
29 22 Feb 05 nicklas 42
29 22 Feb 05 nicklas 43   /**
29 22 Feb 05 nicklas 44     The index of the next element to return.
29 22 Feb 05 nicklas 45   */
29 22 Feb 05 nicklas 46   private int index;
29 22 Feb 05 nicklas 47
29 22 Feb 05 nicklas 48   /**
29 22 Feb 05 nicklas 49     Create a new <code>ArrayIterator</code> object.
4026 30 Nov 07 martin 50      @param array Array to set. 
29 22 Feb 05 nicklas 51   */
29 22 Feb 05 nicklas 52   public ArrayIterator(E[] array)
29 22 Feb 05 nicklas 53   {
29 22 Feb 05 nicklas 54     this.array = array;
29 22 Feb 05 nicklas 55     index = 0;
29 22 Feb 05 nicklas 56   }
6127 14 Sep 12 nicklas 57   @Override
29 22 Feb 05 nicklas 58   public boolean hasNext()
29 22 Feb 05 nicklas 59   {
29 22 Feb 05 nicklas 60     return (array != null) && (index < array.length);
29 22 Feb 05 nicklas 61   }
6127 14 Sep 12 nicklas 62   @Override
29 22 Feb 05 nicklas 63   public E next()
29 22 Feb 05 nicklas 64   {
29 22 Feb 05 nicklas 65     if (!hasNext()) throw new NoSuchElementException();
29 22 Feb 05 nicklas 66     return array[index++];
29 22 Feb 05 nicklas 67   }
29 22 Feb 05 nicklas 68   /**
29 22 Feb 05 nicklas 69     This operation is not supported.
29 22 Feb 05 nicklas 70     @throws UnsupportedOperationException Is always thrown
29 22 Feb 05 nicklas 71   */
6127 14 Sep 12 nicklas 72   @Override
29 22 Feb 05 nicklas 73   public void remove()
29 22 Feb 05 nicklas 74   {
29 22 Feb 05 nicklas 75     throw new UnsupportedOperationException();
29 22 Feb 05 nicklas 76   }
29 22 Feb 05 nicklas 77 }