KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > common > ArrayIterator


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 JavaDoc;
18 import java.util.NoSuchElementException JavaDoc;
19
20 /**
21  * @author mindbridge
22  */

23 public class ArrayIterator implements Iterator JavaDoc
24 {
25     private Object JavaDoc[] m_arrValues;
26     private int m_nFrom;
27     private int m_nTo;
28     private int m_nCurrent;
29
30     public ArrayIterator(Object JavaDoc[] arrValues)
31     {
32         this(arrValues, 0, arrValues.length);
33     }
34
35     public ArrayIterator(Object JavaDoc[] arrValues, int nFrom, int nTo)
36     {
37         m_arrValues = arrValues;
38         m_nFrom = nFrom;
39         m_nTo = nTo;
40
41         if (m_nFrom < 0)
42             m_nFrom = 0;
43         if (m_nTo < m_nFrom)
44             m_nTo = m_nFrom;
45         if (m_nTo > m_arrValues.length)
46             m_nTo = m_arrValues.length;
47
48         m_nCurrent = m_nFrom;
49     }
50
51     /**
52      * @see java.util.Iterator#hasNext()
53      */

54     public boolean hasNext()
55     {
56         return m_nCurrent < m_nTo;
57     }
58
59     /**
60      * @see java.util.Iterator#next()
61      */

62     public Object JavaDoc next()
63     {
64         //System.out.println("index: " + m_nCurrent + " size: " + m_arrValues.length + " to: " + m_nTo);
65
if (!hasNext())
66             throw new NoSuchElementException JavaDoc();
67         return m_arrValues[m_nCurrent++];
68     }
69
70     /**
71      * @see java.util.Iterator#remove()
72      */

73     public void remove()
74     {
75         throw new UnsupportedOperationException JavaDoc();
76     }
77
78 }
79
Popular Tags