/* * 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; public class DictionaryTest { static String colors[] = { "red", "green", "orange", "purple", "chartreuse", "gray", "magenta", "cyan", "yellow", "tangerine", "turquoise", "brown", "black", "white", "silver", "gold", "pink", "bronze", "beige", "blue", "aquamarine", }; /** * Use either BinarySearchTree or Hashtable in the * allocation of the Dictionary below. */ public static void main(String args[]) { // Dictionary d = new Hashtable(); Dictionary d = new BinarySearchTree(); Object o; for (int i = 0; i < colors.length; i++) { d.put(colors[i], i+": "+colors[i]); } 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) { } o = d.get("orange"); System.out.println("Deleting node : "+o); if (o != null) { o = d.remove("orange"); System.out.println("Deleted node : "+ o); } 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) { } } }