gnu.trove
Class THashIterator

java.lang.Object
  extended by gnu.trove.TIterator
      extended by gnu.trove.THashIterator
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
THashMap.KeyView.EntryIterator, TObjectHashIterator

abstract class THashIterator
extends TIterator
implements java.util.Iterator

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
protected  TObjectHash _hash
           
 
Fields inherited from class gnu.trove.TIterator
_expectedSize, _index
 
Constructor Summary
THashIterator(TObjectHash hash)
          Create an instance of THashIterator over the values of the TObjectHash
 
Method Summary
 java.lang.Object next()
          Moves the iterator to the next Object and returns it.
protected  int nextIndex()
          Returns the index of the next value in the data structure or a negative value if the iterator is exhausted.
protected abstract  java.lang.Object objectAtIndex(int index)
          Returns the object at the specified index.
 
Methods inherited from class gnu.trove.TIterator
hasNext, moveToNextIndex, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Iterator
hasNext, remove
 

Field Detail

_hash

protected final TObjectHash _hash
Constructor Detail

THashIterator

public THashIterator(TObjectHash hash)
Create an instance of THashIterator over the values of the TObjectHash

Method Detail

next

public java.lang.Object next()
Moves the iterator to the next Object and returns it.

Specified by:
next in interface java.util.Iterator
Returns:
an Object value
Throws:
java.util.ConcurrentModificationException - if the structure was changed using a method that isn't on this iterator.
java.util.NoSuchElementException - if this is called on an exhausted iterator.

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.

Specified by:
nextIndex in class TIterator
Returns:
an int value
Throws:
java.util.ConcurrentModificationException - if the underlying collection's size has been modified since the iterator was created.

objectAtIndex

protected abstract java.lang.Object objectAtIndex(int index)
Returns the object at the specified index. Subclasses should implement this to return the appropriate object for the given index.

Parameters:
index - the index of the value to return.
Returns:
an Object value