Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ArrayIterator |
|
| 2.2;2.2 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.contrib.table.model.common; |
|
16 | ||
17 | import java.util.Iterator; |
|
18 | import java.util.NoSuchElementException; |
|
19 | ||
20 | /** |
|
21 | * @author mindbridge |
|
22 | */ |
|
23 | public class ArrayIterator implements Iterator |
|
24 | { |
|
25 | ||
26 | private Object[] m_arrValues; |
|
27 | private int m_nFrom; |
|
28 | private int m_nTo; |
|
29 | private int m_nCurrent; |
|
30 | ||
31 | public ArrayIterator(Object[] arrValues) |
|
32 | { |
|
33 | 0 | this(arrValues, 0, arrValues.length); |
34 | 0 | } |
35 | ||
36 | public ArrayIterator(Object[] arrValues, int nFrom, int nTo) |
|
37 | 0 | { |
38 | 0 | m_arrValues = arrValues; |
39 | 0 | m_nFrom = nFrom; |
40 | 0 | m_nTo = nTo; |
41 | ||
42 | 0 | if (m_nFrom < 0) m_nFrom = 0; |
43 | 0 | if (m_nTo < m_nFrom) m_nTo = m_nFrom; |
44 | 0 | if (m_nTo > m_arrValues.length) m_nTo = m_arrValues.length; |
45 | ||
46 | 0 | m_nCurrent = m_nFrom; |
47 | 0 | } |
48 | ||
49 | /** |
|
50 | * @see java.util.Iterator#hasNext() . |
|
51 | */ |
|
52 | public boolean hasNext() |
|
53 | { |
|
54 | 0 | return m_nCurrent < m_nTo; |
55 | } |
|
56 | ||
57 | /** |
|
58 | * @see java.util.Iterator#next() . |
|
59 | */ |
|
60 | public Object next() |
|
61 | { |
|
62 | // System.out.println("index: " + m_nCurrent + " size: " + |
|
63 | // m_arrValues.length + " to: " + m_nTo); |
|
64 | 0 | if (!hasNext()) throw new NoSuchElementException(); |
65 | 0 | return m_arrValues[m_nCurrent++]; |
66 | } |
|
67 | ||
68 | /** |
|
69 | * @see java.util.Iterator#remove() . |
|
70 | */ |
|
71 | public void remove() |
|
72 | { |
|
73 | 0 | throw new UnsupportedOperationException(); |
74 | } |
|
75 | ||
76 | } |