]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/gnu/trove/TIntObjectIterator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / gnu / trove / TIntObjectIterator.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 //////////////////////////////////////////////////
22 // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
23 //////////////////////////////////////////////////
24
25
26 /**
27  * Iterator for maps of type int and Object.
28  * <p/>
29  * <p>The iterator semantics for Trove's primitive maps is slightly different
30  * from those defined in <tt>java.util.Iterator</tt>, but still well within
31  * the scope of the pattern, as defined by Gamma, et al.</p>
32  * <p/>
33  * <p>This iterator does <b>not</b> implicitly advance to the next entry when
34  * the value at the current position is retrieved.  Rather, you must explicitly
35  * ask the iterator to <tt>advance()</tt> and then retrieve either the <tt>key()</tt>,
36  * the <tt>value()</tt> or both.  This is done so that you have the option, but not
37  * the obligation, to retrieve keys and/or values as your application requires, and
38  * without introducing wrapper objects that would carry both.  As the iteration is
39  * stateful, access to the key/value parts of the current map entry happens in
40  * constant time.</p>
41  * <p/>
42  * <p>In practice, the iterator is akin to a "search finger" that you move from
43  * position to position.  Read or write operations affect the current entry only and
44  * do not assume responsibility for moving the finger.</p>
45  * <p/>
46  * <p>Here are some sample scenarios for this class of iterator:</p>
47  * <p/>
48  * <pre>
49  * // accessing keys/values through an iterator:
50  * for (TIntObjectIterator it = map.iterator();
51  *      it.hasNext();) {
52  *   it.advance();
53  *   if (satisfiesCondition(it.key()) {
54  *     doSomethingWithValue(it.value());
55  *   }
56  * }
57  * </pre>
58  * <p/>
59  * <pre>
60  * // modifying values in-place through iteration:
61  * for (TIntObjectIterator it = map.iterator();
62  *      it.hasNext();) {
63  *   it.advance();
64  *   if (satisfiesCondition(it.key()) {
65  *     it.setValue(newValueForKey(it.key()));
66  *   }
67  * }
68  * </pre>
69  * <p/>
70  * <pre>
71  * // deleting entries during iteration:
72  * for (TIntObjectIterator it = map.iterator();
73  *      it.hasNext();) {
74  *   it.advance();
75  *   if (satisfiesCondition(it.key()) {
76  *     it.remove();
77  *   }
78  * }
79  * </pre>
80  * <p/>
81  * <pre>
82  * // faster iteration by avoiding hasNext():
83  * TIntObjectIterator iterator = map.iterator();
84  * for (int i = map.size(); i-- > 0;) {
85  *   iterator.advance();
86  *   doSomethingWithKeyAndValue(iterator.key(), iterator.value());
87  * }
88  * </pre>
89  *
90  * @author Eric D. Friedman
91  * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $
92  */
93
94 public class TIntObjectIterator<V> extends TPrimitiveIterator {
95     /** the collection being iterated over */
96     private final TIntObjectHashMap<V> _map;
97
98     /**
99      * Creates an iterator over the specified map
100      */
101     public TIntObjectIterator(TIntObjectHashMap<V> map) {
102         super(map);
103         this._map = map;
104     }
105
106     /**
107      * Moves the iterator forward to the next entry in the underlying map.
108      *
109      * @throws java.util.NoSuchElementException
110      *          if the iterator is already exhausted
111      */
112     public void advance() {
113         moveToNextIndex();
114     }
115
116     /**
117      * Provides access to the key of the mapping at the iterator's position.
118      * Note that you must <tt>advance()</tt> the iterator at least once
119      * before invoking this method.
120      *
121      * @return the key of the entry at the iterator's current position.
122      */
123     public int key() {
124         return _map._set[_index];
125     }
126
127     /**
128      * Provides access to the value of the mapping at the iterator's position.
129      * Note that you must <tt>advance()</tt> the iterator at least once
130      * before invoking this method.
131      *
132      * @return the value of the entry at the iterator's current position.
133      */
134     public V value() {
135         return _map._values[_index];
136     }
137
138     /**
139      * Replace the value of the mapping at the iterator's position with the
140      * specified value. Note that you must <tt>advance()</tt> the iterator at
141      * least once before invoking this method.
142      *
143      * @param val the value to set in the current entry
144      * @return the old value of the entry.
145      */
146     public V setValue(V val) {
147         V old = value();
148         _map._values[_index] = val;
149         return old;
150     }
151 }// TIntObjectIterator