/*
 * AbstractIterator.java  1.0   Michael Zanussi
 *
 * Copyright (C) 2004 Michael Zanussi
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies.
 */

package com.michaelzanussi.bayesian;

import java.util.Iterator;

/**
 * Abstract iterator for MondoHashTable's inner Entry classes.
 
 @author <a href="mailto:admin@michaelzanussi.com">Michael Zanussi</a>
 @version 1.0 (6 Feb 2004) 
 */
public abstract class AbstractIterator implements Iterator {

  // Index into the set.      
  private int _idx;
      
  // The table of entries.
  private MondoHashTable.Entry [] _iaTable;

  /**
   * No-arg constructor.
   */
  public AbstractIterator() {
    
    _idx = 0;
    
  }
      
  /**
   * Standard constructor.
   */
  public AbstractIteratorMondoHashTable.Entry [] table ) {
    
    _iaTable = table;
    _idx = 0;
    
  }
      
  /**
   * Returns <code>true</code> if there are more elements.
   * Also updates current index.
   *
   @return <code>true</code> if there are more elements.
   */
  public boolean hasNext() {
    
    // Advance pointer until an element has been found or we
    // run off the end of the table.
    for; _idx < _iaTable.length; _idx++ ) {
      if_iaTable[_idx!= null && _iaTable[_idx!= MondoHashTable.AVAILABLE ) {
        return true;
      }
    }
    
    return false;
    
  }
      
  /**
   * Returns current element in the table.
   *
   @return the current element in the table.
   */
  public Object next() {
    
    Object elt = _iaTable[_idx++];
    return elt;
    
  }
      
  /**
   * (not supported)
   *  
   @throws UnsupportedOperationException if method not supported.
   */
  public void remove() {
    
    throw new UnsupportedOperationException"Remove method not supported." );
    
  }
}