1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 ///////////////////////////////////////////////////////////////////////////////
21 import java.util.ConcurrentModificationException;
24 * Implements all iterator functions for the hashed object set.
25 * Subclasses may override objectAtIndex to vary the object
26 * returned by calls to next() (e.g. for values, and Map.Entry
29 * <p> Note that iteration is fastest if you forego the calls to
30 * <tt>hasNext</tt> in favor of checking the size of the structure
31 * yourself and then call next() that many times:
34 * Iterator i = collection.iterator();
35 * for (int size = collection.size(); size-- > 0;) {
36 * Object o = i.next();
40 * <p>You may, of course, use the hasNext(), next() idiom too if
41 * you aren't in a performance critical spot.</p>
44 abstract class TPrimitiveIterator extends TIterator {
45 /** the collection on which this iterator operates. */
46 protected final TPrimitiveHash _hash;
49 * Creates a TPrimitiveIterator for the specified collection.
51 public TPrimitiveIterator(TPrimitiveHash hash) {
57 * Returns the index of the next value in the data structure
58 * or a negative value if the iterator is exhausted.
60 * @return an <code>int</code> value
61 * @exception ConcurrentModificationException if the underlying collection's
62 * size has been modified since the iterator was created.
64 protected final int nextIndex() {
65 if (_expectedSize != _hash.size()) {
66 throw new ConcurrentModificationException();
69 byte[] states = _hash._states;
71 while (i-- > 0 && (states[i] != TPrimitiveHash.FULL)) ;
75 } // TPrimitiveIterator