29 |
22 Feb 05 |
nicklas |
1 |
/* |
192 |
17 Mar 05 |
jari |
$Id$ |
29 |
22 Feb 05 |
nicklas |
3 |
|
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2005 Jari Häkkinen, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen |
29 |
22 Feb 05 |
nicklas |
6 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
29 |
22 Feb 05 |
nicklas |
9 |
|
29 |
22 Feb 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
29 |
22 Feb 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
29 |
22 Feb 05 |
nicklas |
of the License, or (at your option) any later version. |
29 |
22 Feb 05 |
nicklas |
14 |
|
29 |
22 Feb 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
29 |
22 Feb 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
29 |
22 Feb 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
29 |
22 Feb 05 |
nicklas |
GNU General Public License for more details. |
29 |
22 Feb 05 |
nicklas |
19 |
|
29 |
22 Feb 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
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 |
This class implements the {@link Iterator} interface |
29 |
22 Feb 05 |
nicklas |
for an array of objects. |
29 |
22 Feb 05 |
nicklas |
31 |
|
29 |
22 Feb 05 |
nicklas |
@author Nicklas |
29 |
22 Feb 05 |
nicklas |
@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 |
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 |
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 |
Create a new <code>ArrayIterator</code> object. |
4026 |
30 Nov 07 |
martin |
@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 |
This operation is not supported. |
29 |
22 Feb 05 |
nicklas |
@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 |
} |