import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;

public class Test {

    public static WordCount processFile (String filename)
	throws FileNotFoundException, IOException {

	// open the file and create a BufferedReader for it
	FileReader fileReader = new FileReader (filename);
	BufferedReader in = new BufferedReader (fileReader);

	// use the BufferedReader to get lines from the file
	// and pass each to the WordCount

	WordCount wc = new WordCount ();
	while (true) {
	    String s = in.readLine();
	    if (s == null) break;
	    wc.processLine (s);
	}
	return wc;
    }
    
    public static void main (String[] args)
	throws FileNotFoundException, IOException {

	WordCount wc = processFile ("text.txt");

	Heap heap = new Heap ();
	Enumeration enum = wc.ht.keys ();
	while (enum.hasMoreElements ()) {
	    String key = (String) enum.nextElement ();
	    Integer value = (Integer) wc.ht.get (key);
	    heap.insert (new Pair (key, value));
	}

	int i = 1;
	while (!heap.isEmpty ()) {
	    Pair p = (Pair) heap.remove ();
	    System.out.print (i++ + "\t");
	    p.print ();
	}

	for (i=0; i<1000; i++) {
	    System.out.print (wc.randomWord () + " ");
	}
    }
}
