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 //////////////////////////////////////////////////
22 // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
23 //////////////////////////////////////////////////
27 * Iterator for maps of type int and Object.
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>
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
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>
46 * <p>Here are some sample scenarios for this class of iterator:</p>
49 * // accessing keys/values through an iterator:
50 * for (TIntObjectIterator it = map.iterator();
53 * if (satisfiesCondition(it.key()) {
54 * doSomethingWithValue(it.value());
60 * // modifying values in-place through iteration:
61 * for (TIntObjectIterator it = map.iterator();
64 * if (satisfiesCondition(it.key()) {
65 * it.setValue(newValueForKey(it.key()));
71 * // deleting entries during iteration:
72 * for (TIntObjectIterator it = map.iterator();
75 * if (satisfiesCondition(it.key()) {
82 * // faster iteration by avoiding hasNext():
83 * TIntObjectIterator iterator = map.iterator();
84 * for (int i = map.size(); i-- > 0;) {
86 * doSomethingWithKeyAndValue(iterator.key(), iterator.value());
90 * @author Eric D. Friedman
91 * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $
94 public class TIntObjectIterator<V> extends TPrimitiveIterator {
95 /** the collection being iterated over */
96 private final TIntObjectHashMap<V> _map;
99 * Creates an iterator over the specified map
101 public TIntObjectIterator(TIntObjectHashMap<V> map) {
107 * Moves the iterator forward to the next entry in the underlying map.
109 * @throws java.util.NoSuchElementException
110 * if the iterator is already exhausted
112 public void advance() {
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.
121 * @return the key of the entry at the iterator's current position.
124 return _map._set[_index];
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.
132 * @return the value of the entry at the iterator's current position.
135 return _map._values[_index];
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.
143 * @param val the value to set in the current entry
144 * @return the old value of the entry.
146 public V setValue(V val) {
148 _map._values[_index] = val;
151 }// TIntObjectIterator