/**
 * A small test rig to demonstrate the function of TDRLTable and iterators on
 * it.
 *
 * @author <a href="mailto:terran@cs.unm.edu">Terran Lane</a>
 * @version 1.0
 */

import java.util.Iterator;

public class TestTables {
  public static void main(String[] args) {
    TDRLTable tab1=new TableA(10);
    TDRLTable tab2=new TableB(10);

    System.out.println("Filling table 1 (TableA)...");
    _fillTable(tab1);
    System.out.println("Filling table 2 (TableB)...");
    _fillTable(tab2);
    System.out.println("Dumping table 1 (TableA)...");
    _dumpTable(tab1);
    System.out.println("Dumping table 2 (TableB)...");
    _dumpTable(tab2);
  }

  /**
   * Populate a <code>TDRLTable</code> with the squares of the integers.
   *
   * @param t Table to fill.
   */
  private static void _fillTable(TDRLTable t) {
    for (int i=0;i<t.size();++i) {
      t.put(i*i,i);
    }
  }

  /**
   * Write the contents of the table to stdout.
   *
   * @param t Table to dump.
   */
  private static void _dumpTable(TDRLTable t) {
    Iterator i=t.getIterator();
    int count=t.size()-1;
    while (i.hasNext()) {
      Integer item=(Integer)i.next();
      System.out.println("\ttable[" + count + "]=" + item.intValue());
      --count;
    }
  }
}
