import java.io.*; public class TestTable { public static void createTable(Function table,String source) throws IOException { BufferedReader in = new BufferedReader(new FileReader(source)); String line = in.readLine(); while(!line.equals("end")) { int index = line.indexOf('@'); String word = line.substring(0,index); String digit = line.substring(index + 1); table.put(word,Integer.valueOf(digit)); line = in.readLine(); } in.close(); } public static void testListTable() { try { String s = File.separator; String source = System.getProperty("user.dir") + s + "testTableData.txt"; System.out.println("Read text from the file "+source); Function table = new ListTable(); createTable(table,source); System.out.println(" List table Digits in English:" + "\n" + table); }catch (IOException e) {} } public static void testHashTable() { try { String s = File.separator; String source = System.getProperty("user.dir") + s + "testTableData.txt"; System.out.println("Read text from the file "+source); Function table = new HashTable(); createTable(table,source); System.out.println(" Hash table Digits in English:" + "\n" + table); }catch (IOException e) {} } public static void testTreeTable() { try { String s = File.separator; String source = System.getProperty("user.dir") + s + "testTableData.txt"; System.out.println("Read text from the file " + source); String target = System.getProperty("user.dir") + s + "testTreeTableResult.txt"; System.out.println("Test and write results to the file " + target); BinaryTree tree = new BinarySearchTree(new EntryComparator()); Function table = new TreeTable(tree); createTable(table,source); TestBinaryTree.test(tree,target); System.out.println(" Tree table Digits traversal:"); java.util.Iterator it = new TableValuesIterator(tree.iterator()); while(it.hasNext()) System.out.println(it.next()); }catch (IOException e) {} } public static void main(String[] args) { testListTable(); testHashTable(); testTreeTable(); } }