/* * DictionaryTest.java - Test the implementation of Dictionaries. * * Copyright (c) 1996 Chuck McManis, All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. * * CHUCK MCMANIS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. CHUCK MCMANIS * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT * OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ import java.util.Dictionary; import java.util.Hashtable; import java.util.Enumeration; import java.awt.Color; public class DictionaryTest { static String colors[] = { "black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow" }; static Color colorArray[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow }; public static void main(String args[]) { ColorOrganizer co = new ColorOrganizer(); Dictionary d = new BinarySearchTree(co); ColorItem item1, item2, testKey; for (int i = 0; i < colors.length; i++) { ColorItem ci = new ColorItem(colors[i], colorArray[i]); d.put(ci, ci); } System.out.println("BinarySearchTree contains :"); for (Enumeration e = d.elements(); e.hasMoreElements(); ) { System.out.println(e.nextElement()); } try { System.out.println("press any key to continue."); int zz = System.in.read(); } catch (Exception e) { } testKey = new ColorItem("orange", Color.orange); item1 = (ColorItem) d.get(testKey); item2 = co.fetch(testKey); System.out.println("Testing two keys for equality ... "+ co.equalKeys(item1, item2)); System.out.println("Deleting node : "+item1); if (item1 != null) { item1 = (ColorItem) d.remove(testKey); System.out.println("Deleted node : "+ item1); } System.out.println("Dictionary contains :"); for (Enumeration e = d.elements(); e.hasMoreElements(); ) { System.out.println(e.nextElement()); } try { System.out.println("press any key to continue."); int zz = System.in.read(); } catch (Exception e) { } } }