blob: 6d11a1d92d0947c7210f50e177411b72fa799e9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package bjc.data;
import java.util.Iterator;
/**
* Represents an iterator over an array of values.
*
* @param <T>
* The type of values in the array.
*
* @author Ben Culkin
*/
public class ArrayIterator<T> implements Iterator<T> {
private Object[] arr;
private int idx;
/**
* Create a new array iterator.
*
* @param elms
* The array that will be iterated over.
*/
@SafeVarargs
public ArrayIterator(T... elms) {
arr = elms;
idx = 0;
}
@Override
public boolean hasNext() {
return idx < arr.length;
}
@SuppressWarnings("unchecked")
@Override
public T next() {
if (idx >= arr.length)
return null;
return (T) (arr[idx++]);
}
}
|