1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.bea.xml.stream.util;
17
18 import java.util.Iterator;
19 import java.util.NoSuchElementException;
20
21 public final class ArrayIterator implements Iterator {
22
23 private final Object[] array;
24 private final int maxIndex;
25 private int index;
26
27 public ArrayIterator(Object[] a) {
28 this(a, 0, a.length);
29 }
30
31 public ArrayIterator(Object[] a, int off, int len) {
32 if (off < 0) throw new IllegalArgumentException();
33 if (off > a.length) throw new IllegalArgumentException();
34 if (len > a.length - off) throw new IllegalArgumentException();
35 array = a;
36 index = off;
37 maxIndex = len + off;
38 }
39
40 public boolean hasNext() { return index < maxIndex; }
41
42 public Object next() {
43 if (index >= maxIndex) throw new NoSuchElementException();
44 return array[index++];
45 }
46
47 public void remove() { throw new UnsupportedOperationException(); }
48
49 }
50