01: /*
02: * $Id: ArrayIteratorAdapter.java 458270 2005-12-09 07:43:11Z ivaynberg $
03: * $Revision: 458270 $
04: * $Date: 2005-12-09 08:43:11 +0100 (Fri, 09 Dec 2005) $
05: *
06: * ====================================================================
07: * Licensed under the Apache License, Version 2.0 (the "License");
08: * you may not use this file except in compliance with the License.
09: * You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19: package wicket.extensions.markup.html.repeater.util;
20:
21: import java.util.Iterator;
22:
23: import wicket.model.IModel;
24:
25: /**
26: * Iterator over an array. Implementation must provide
27: * {@link ArrayIteratorAdapter#model(Object) } method to wrap each item in a
28: * model before it is returned through {@link ArrayIteratorAdapter#next() }
29: * method.
30: *
31: * @author Igor Vaynberg (ivaynberg)
32: *
33: */
34: public abstract class ArrayIteratorAdapter implements Iterator {
35: private Object[] array;
36: private int pos = 0;
37:
38: /**
39: * Constructor
40: *
41: * @param array
42: */
43: public ArrayIteratorAdapter(Object[] array) {
44: this .array = array;
45: }
46:
47: /**
48: * @see java.util.Iterator#remove()
49: */
50: public void remove() {
51: throw new UnsupportedOperationException(
52: "remove() is not allowed");
53: }
54:
55: /**
56: * @see java.util.Iterator#hasNext()
57: */
58: public boolean hasNext() {
59: return pos < array.length;
60: }
61:
62: /**
63: * @see java.util.Iterator#next()
64: */
65: public Object next() {
66: return model(array[pos++]);
67: }
68:
69: /**
70: * Resets the iterator position back to the beginning of the array
71: */
72: public void reset() {
73: pos = 0;
74: }
75:
76: /**
77: * This method is used to wrap the provided object with an implementation of
78: * IModel. The provided object is guaranteed to be returned from the
79: * delegate iterator.
80: *
81: * @param object
82: * object to be wrapped
83: * @return IModel wrapper for the object
84: */
85: abstract protected IModel model(Object object);
86:
87: }
|