© 1998-2002 McGraw-Hill

structure
Class HashtableIterator

java.lang.Object
  |
  +--structure.AbstractIterator
        |
        +--structure.HashtableIterator
All Implemented Interfaces:
Enumeration, Iterator

class HashtableIterator
extends AbstractIterator

A traversal of all the elements as they appear in a hashtable. No order is guaranteed. This iterator is not publically accessable and is used to implement Hashtable's key and value iterators. This iteration returns objects that are instances of Association.

Typical use:

      Hashtable h = new Hashtable();
      // ...hashtable gets built up...
      Iterator hi = new HashtableIterator(h.data);
      while (hi.hasNext())
      {
          System.out.println(ai.next());
      }
 


Field Summary
protected  int current
          The current entry being considered.
protected  Association[] data
          Reference to hash table data
 
Constructor Summary
HashtableIterator(Association[] table)
          Construct a traversal over a hashtable.
 
Method Summary
 Object get()
          Get current value of traversal.
 boolean hasNext()
          Returns true iff there are unconsidered elements within the table.
 Object next()
          Returns current value and increments traversal.
 void reset()
          Resets the traversal to point to the beginning of the table.
 
Methods inherited from class structure.AbstractIterator
hasMoreElements, nextElement, remove, value
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

current

protected int current
The current entry being considered.

data

protected Association[] data
Reference to hash table data
Constructor Detail

HashtableIterator

public HashtableIterator(Association[] table)
Construct a traversal over a hashtable.
Parameters:
table - The array of lists to be traversed.
Method Detail

reset

public void reset()
Resets the traversal to point to the beginning of the table.
Overrides:
reset in class AbstractIterator
Postcondition:
resets traversal to beginning of hash table

hasNext

public boolean hasNext()
Returns true iff there are unconsidered elements within the table.
Overrides:
hasNext in class AbstractIterator
Postcondition:
returns true if there are unvisited elements
Returns:
True iff there are elements yet to be considered within table.

next

public Object next()
Returns current value and increments traversal.
Overrides:
next in class AbstractIterator
Precondition:
hasNext()
Postcondition:
returns current element, increments traversal
Returns:
The current value, before incrementing.

get

public Object get()
Get current value of traversal.
Overrides:
get in class AbstractIterator
Postcondition:
returns current element
Returns:
The current value.

© 1998-2002 McGraw-Hill