import AssociationList; import SimpleOutput; /** * Test association lists. Takes advantage of some prior knowledge * about the magical "populate" method. * * @author Samuel A. Rebelsky * @version 1.0 of November 1999 */ public class ALTester { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The association list we're testing. */ AssociationList testme; /** Something to generate output with. */ SimpleOutput out; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ public ALTester() { // Prepare to generate output. out = new SimpleOutput(); // Set up the associatoin list. testme = new AssociationList(); // Set up a sample set of key/value pairs for testing. testme.populate(); // Look up a few names that are already there. We check all // of them so that we hit all the positions. lookup("Joshua Vickery"); lookup("Sierra Soleil"); lookup("Kate Ducey"); lookup("Wanlin Liu"); // Capitalization should matter. lookup("joshua vickery"); // Here's a name that's not there. lookup("sam rebelsky"); // Add it. add("sam rebelsky", "CS"); // Now it should be there. lookup("sam rebelsky"); // Change Josh add("Joshua Vickery", "CS"); lookup("Joshua Vickery"); out.println("Final list: " + testme.toString()); } // ALTester() // +---------+------------------------------------------------- // | Methods | // +---------+ /** Look up a name in the association list. */ public void lookup(Object key) { out.print("Looking up '" + key + "': "); try { out.println(testme.get(key)); } catch (Exception e) { out.println("FAILED"); } } // lookup(Object) /** Add a key/value pair to the list. */ public void add(Object key, Object value) { out.print("Adding key: '" + key + "', value: '" + value + "' ..."); try { testme.put(key,value); out.println("OK"); } catch (Exception e) { out.println("FAILED"); } } // add(Object,Object) // +------+---------------------------------------------------- // | Main | // +------+ /** Test away. */ public static void main(String[] args) { new ALTester(); } // main(String[]) } // class ALTester