/**
 * An "external" iterator for TableA.  Returns data in the <em>opposite</em>
 * of table index order, as specified by the {@link TDRLTable} interface.
 *
 * @author <a href="mailto:terran@cs.unm.edu">Terran Lane</a>
 * @version 1.0
 */

import java.util.Iterator;
import java.util.NoSuchElementException;

public class TableAIterator implements Iterator {
  public TableAIterator(TableA tab) {
    if (tab==null) {
      throw new NullPointerException("Can't create an Iterator for " +
				     "a null table");
    }
    _backingTab=tab;
    _currPtr=_backingTab.size()-1;
  }

  public boolean hasNext() {
    return _currPtr>=0;
  }
  
  public Object next() {
    if (!hasNext()) {
      throw new NoSuchElementException("Out of items");
    }
    return new Integer(_backingTab.get(_currPtr--));
  }

  public void remove() {
    throw new RuntimeException("Removing from TDRLTables not allowed.");
    // The following is the _correct_ exception to throw.  Doesn't compile
    // properly on my Mac -- not sure why...
    //    throw UnsupportedOperationException("Removing from TDRLTables " +
    //					"not allowed.");
  }

  /* ******************** end of public interface ******************** */

  private TableA _backingTab;
  private int _currPtr;
}
