]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/gnu/trove/TPrimitiveIterator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / gnu / trove / TPrimitiveIterator.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
3 //
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.
8 //
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.
13 //
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 ///////////////////////////////////////////////////////////////////////////////
18
19 package gnu.trove;
20
21 import java.util.ConcurrentModificationException;
22
23 /**
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
27  * objects).
28  *
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:
32  *
33  * <pre>
34  * Iterator i = collection.iterator();
35  * for (int size = collection.size(); size-- > 0;) {
36  *   Object o = i.next();
37  * }
38  * </pre>
39  *
40  * <p>You may, of course, use the hasNext(), next() idiom too if
41  * you aren't in a performance critical spot.</p>
42  *
43  */
44 abstract class TPrimitiveIterator extends TIterator {
45     /** the collection on which this iterator operates. */
46     protected final TPrimitiveHash _hash;
47
48     /**
49      * Creates a TPrimitiveIterator for the specified collection.
50      */
51     public TPrimitiveIterator(TPrimitiveHash hash) {
52     super(hash);
53         _hash = hash;
54     }
55     
56     /**
57      * Returns the index of the next value in the data structure
58      * or a negative value if the iterator is exhausted.
59      *
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.
63      */
64     protected final int nextIndex() {
65         if (_expectedSize != _hash.size()) {
66             throw new ConcurrentModificationException();
67         }
68
69         byte[] states = _hash._states;
70         int i = _index;
71         while (i-- > 0 && (states[i] != TPrimitiveHash.FULL)) ;
72         return i;
73     }
74
75 } // TPrimitiveIterator