Package gnu.trove.impl.hash
Class THashPrimitiveIterator
java.lang.Object
gnu.trove.impl.hash.THashPrimitiveIterator
- All Implemented Interfaces:
TIterator
,TPrimitiveIterator
Implements all iterator functions for the hashed object set. Subclasses may override objectAtIndex to vary the object returned by calls to next() (e.g. for values, and Map.Entry objects).
Note that iteration is fastest if you forego the calls to hasNext in favor of checking the size of the structure yourself and then call next() that many times:
Iterator i = collection.iterator(); for (int size = collection.size(); size-- > 0;) { Object o = i.next(); }
You may, of course, use the hasNext(), next() idiom too if you aren't in a performance critical spot.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
the number of elements this iterator believes are in the data structure it accesses.protected final TPrimitiveHash
the data structure this iterator traversesprotected int
the index used for iteration. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a TPrimitiveIterator for the specified collection. -
Method Summary
Modifier and TypeMethodDescriptionboolean
hasNext()
Returns true if the iterator can be advanced past its current location.protected final void
Sets the internal index so that the `next' object can be returned.protected final int
Returns the index of the next value in the data structure or a negative value if the iterator is exhausted.void
remove()
Removes the last entry returned by the iterator.
-
Field Details
-
_hash
the data structure this iterator traverses -
_expectedSize
protected int _expectedSizethe number of elements this iterator believes are in the data structure it accesses. -
_index
protected int _indexthe index used for iteration.
-
-
Constructor Details
-
THashPrimitiveIterator
Creates a TPrimitiveIterator for the specified collection.- Parameters:
hash
- the TPrimitiveHash we want to iterate over.
-
-
Method Details
-
nextIndex
protected final int nextIndex()Returns the index of the next value in the data structure or a negative value if the iterator is exhausted.- Returns:
- an
int
value - Throws:
ConcurrentModificationException
- if the underlying collection's size has been modified since the iterator was created.
-
hasNext
public boolean hasNext()Returns true if the iterator can be advanced past its current location.- Specified by:
hasNext
in interfaceTIterator
- Specified by:
hasNext
in interfaceTPrimitiveIterator
- Returns:
- a
boolean
value
-
remove
public void remove()Removes the last entry returned by the iterator. Invoking this method more than once for a single entry will leave the underlying data structure in a confused state.- Specified by:
remove
in interfaceTIterator
- Specified by:
remove
in interfaceTPrimitiveIterator
-
moveToNextIndex
protected final void moveToNextIndex()Sets the internal index so that the `next' object can be returned.
-