01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package javax.faces.component;
17:
18: import java.lang.reflect.Array;
19: import java.util.Iterator;
20:
21: /**
22: * This utility iterator uses reflection to iterate over primitive arrays.
23: */
24: class _PrimitiveArrayIterator implements Iterator {
25: public _PrimitiveArrayIterator(Object primitiveArray) {
26: if (primitiveArray == null
27: || !primitiveArray.getClass().isArray()) {
28: throw new IllegalArgumentException(
29: "Requires a primitive array");
30: }
31:
32: _primitiveArray = primitiveArray;
33: _size = Array.getLength(primitiveArray);
34: }
35:
36: public boolean hasNext() {
37: return (_position < _size);
38: }
39:
40: public Object next() {
41: return Array.get(_primitiveArray, _position++);
42: }
43:
44: public void remove() {
45: throw new UnsupportedOperationException();
46: }
47:
48: private Object _primitiveArray;
49: private int _size;
50: private int _position;
51: }
|