© 1998-2002 McGraw-Hill

structure
Class KeyIterator

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

class KeyIterator
extends AbstractIterator

A private master iterator for filtering the key fields from an Association-returning iterator. This iterator returns objects of the Comparable type, and is publically available throught the Hashtable.keys() method.

Typical use:

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


Field Summary
protected  Iterator slave
          The underlying iterator.
 
Constructor Summary
KeyIterator(Iterator slave)
          Construct a new key iterator that filters the slave iterator, an Association-returning iterator.
 
Method Summary
 Object get()
          Returns the current key from the slave iterator.
 boolean hasNext()
          Returns true if an association is available for generating a key.
 Object next()
          Returns the current key, and increments the iterator.
 void reset()
          Resets the slave iterator (and thus the key iterator) to the first association in the structure.
 
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

slave

protected Iterator slave
The underlying iterator. The slave iterator provides the key iterator values which are Associations. The key iterator returns only the key-portion of the Associations.
Constructor Detail

KeyIterator

public KeyIterator(Iterator slave)
Construct a new key iterator that filters the slave iterator, an Association-returning iterator.
Parameters:
slave - The slave iterator.
Method Detail

reset

public void reset()
Resets the slave iterator (and thus the key iterator) to the first association in the structure.
Overrides:
reset in class AbstractIterator
Postcondition:
resets iterator to point to first key

hasNext

public boolean hasNext()
Returns true if an association is available for generating a key.
Overrides:
hasNext in class AbstractIterator
Postcondition:
returns true if current element is valid
Returns:
True if a valid key can be generated.

next

public Object next()
Returns the current key, and increments the iterator.
Overrides:
next in class AbstractIterator
Precondition:
hasNext()
Postcondition:
returns current value and increments iterator
Returns:
The current key, before iterator is incremented.

get

public Object get()
Returns the current key from the slave iterator.
Overrides:
get in class AbstractIterator
Precondition:
current value is valid
Postcondition:
returns current value
Returns:
The current key associated with the iterator.

© 1998-2002 McGraw-Hill