001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.contrib.table.model.common;
016    
017    import java.util.Iterator;
018    import java.util.NoSuchElementException;
019    
020    /**
021     * @author mindbridge
022     */
023    public class ArrayIterator implements Iterator
024    {
025    
026        private Object[] m_arrValues;
027        private int m_nFrom;
028        private int m_nTo;
029        private int m_nCurrent;
030    
031        public ArrayIterator(Object[] arrValues)
032        {
033            this(arrValues, 0, arrValues.length);
034        }
035    
036        public ArrayIterator(Object[] arrValues, int nFrom, int nTo)
037        {
038            m_arrValues = arrValues;
039            m_nFrom = nFrom;
040            m_nTo = nTo;
041    
042            if (m_nFrom < 0) m_nFrom = 0;
043            if (m_nTo < m_nFrom) m_nTo = m_nFrom;
044            if (m_nTo > m_arrValues.length) m_nTo = m_arrValues.length;
045    
046            m_nCurrent = m_nFrom;
047        }
048    
049        /**
050         * @see java.util.Iterator#hasNext() .
051         */
052        public boolean hasNext()
053        {
054            return m_nCurrent < m_nTo;
055        }
056    
057        /**
058         * @see java.util.Iterator#next() .
059         */
060        public Object next()
061        {
062            // System.out.println("index: " + m_nCurrent + " size: " +
063            // m_arrValues.length + " to: " + m_nTo);
064            if (!hasNext()) throw new NoSuchElementException();
065            return m_arrValues[m_nCurrent++];
066        }
067    
068        /**
069         * @see java.util.Iterator#remove() .
070         */
071        public void remove()
072        {
073            throw new UnsupportedOperationException();
074        }
075    
076    }