From: Peter Bernard West Date: Tue, 7 May 2002 15:16:53 +0000 (+0000) Subject: Vector->ArrayList, Hashtable->HashMap, Enumerator->Iterator X-Git-Tag: FOP_Alt-Design_Migration~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=637d02655d2b68a3f2c9977b2eedb552f44235bb;p=xmlgraphics-fop.git Vector->ArrayList, Hashtable->HashMap, Enumerator->Iterator git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194790 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/configuration/Configuration.java b/src/org/apache/fop/configuration/Configuration.java index ad9deedae..9a94c4960 100644 --- a/src/org/apache/fop/configuration/Configuration.java +++ b/src/org/apache/fop/configuration/Configuration.java @@ -7,16 +7,16 @@ package org.apache.fop.configuration; -import java.util.Vector; -import java.util.Hashtable; -import java.util.Enumeration; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import org.apache.fop.messaging.MessageHandler; /** * a configuration class for all general configuration aspects except those - * related to specific renderers. All configuration is stored - * in key / value pairs. The value can be a String, a list of Strings - * or a map, containing a list of key / value pairs. + * related to specific renderers. All configuration is stored in + * key.value pairs. The value can be a String, a Boolean, an Integer, + * or a list of Strings or a map, containing a list of key.value pairs. * */ public class Configuration { @@ -31,18 +31,18 @@ public class Configuration { /** * stores the configuration information */ - private static Hashtable standardConfiguration = new Hashtable(30); + private static HashMap standardConfiguration = new HashMap(30); ; - private static Hashtable pdfConfiguration = new Hashtable(20); - private static Hashtable awtConfiguration = new Hashtable(20); + private static HashMap pdfConfiguration = new HashMap(20); + private static HashMap awtConfiguration = new HashMap(20); /** - * contains a Hashtable of existing Hashtables + * contains a HashMap of existing HashMaps */ - private static Hashtable configuration = new Hashtable(3); + private static HashMap configuration = new HashMap(3); /** - * loads the configuration types into the configuration Hashtable + * loads the configuration types into the configuration HashMap */ static { configuration.put("standard", standardConfiguration); @@ -50,15 +50,15 @@ public class Configuration { configuration.put("awt", awtConfiguration); } - public static Hashtable getConfiguration() { + public static HashMap getConfiguration() { return configuration; } /** * general access method * - * @param key a string containing the key value for the configuration value - * role detemines the configuration target + * @param key a string containing the key for the configuration value + * role determines the configuration target * @return Object containing the value; normally you would use one of the * convenience methods, which return the correct form. * null if the key is not defined. @@ -76,12 +76,11 @@ public class Configuration { } } - ; /** * convenience methods to access strings values in the configuration - * @param key a string containing the key value for the configuration value - * role detemines the configuration target + * @param key a string containing the key for the configuration value + * role determines the configuration target * @return String a string containing the value * null if the key is not defined. */ @@ -94,12 +93,11 @@ public class Configuration { } } - ; /** * convenience methods to access int values in the configuration - * @param key a string containing the key value for the configuration value - * role detemines the configuration target + * @param key a string containing the key for the configuration value + * role determines the configuration target * @return int a int containing the value * -1 if the key is not defined. */ @@ -107,17 +105,18 @@ public class Configuration { Object obj = Configuration.getValue(key, role); if (obj instanceof String) { return Integer.parseInt((String)obj); + } else if (obj instanceof Integer) { + return ((Integer)obj).intValue(); } else { return -1; } } - ; /** * convenience methods to access boolean values in the configuration - * @param key a string containing the key value for the configuration value - * role detemines the configuration target + * @param key a string containing the key for the configuration value + * role determines the configuration target * @return Boolean true or false as value * null if the key is not defined. */ @@ -132,50 +131,69 @@ public class Configuration { } } - ; /** * convenience methods to access list values in the configuration - * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return Vector a Vector containing the values + * @param key a string containing the key for the configuration value + * role determines the configuration target + * @return ArrayList a ArrayList containing the values * null if the key is not defined. */ - public static Vector getListValue(String key, int role) { + public static ArrayList getListValue(String key, int role) { Object obj = Configuration.getValue(key, role); - if (obj instanceof Vector) { - return (Vector)obj; + if (obj instanceof ArrayList) { + return (ArrayList)obj; } else { return null; } } - ; /** * convenience methods to access map/hashtable values in the configuration - * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return Hashtable a Hashtable containing the values + * @param key a string containing the key for the configuration value + * role determines the configuration target + * @return HashMap a HashMap containing the values * null if the key is not defined. */ - public static Hashtable getHashtableValue(String key, int role) { + public static HashMap getHashMapValue(String key, int role) { Object obj = Configuration.getValue(key, role); - if (obj instanceof Hashtable) { - return (Hashtable)obj; + if (obj instanceof HashMap) { + return (HashMap)obj; } else { return null; } } - ; + + /** + * Convenience method to access values in HashMap entries in the + * configuration. + * @param map a string containing the key for the configuration value. + * N.B. this is the key of the HashMap itself. + * @param key an object containing the key for an entry in the + * HashMap indexed by map. + * @param role determines the configuration target + * @return an Object containing the value associated with + * key, or null + * if the map is not defined, the keyentry is not defined, + * or the keyentry is itself null. + */ + public static Object getHashMapEntry(String map, Object key, int role) { + Object obj = getValue(map, role); + if (obj instanceof HashMap) { + return ((HashMap)obj).get(key); + } else { + return null; + } + } /** * convenience method which retrieves some configuration information * from the standard configuration * - * @param key a string containing the key value for the configuration value + * @param key a string containing the key for the configuration value * @return Object containing the value; normally you would use one of the * convenience methods, which return the correct form. * null if the key is not defined. @@ -185,9 +203,10 @@ public class Configuration { } /** - * convenience methods to access strings values in the standard configuration + * convenience methods to access strings values in the standard + * configuration * - * @param key a string containing the key value for the configuration value + * @param key a string containing the key for the configuration value * @return String a string containing the value * null if the key is not defined. */ @@ -198,7 +217,7 @@ public class Configuration { /** * convenience methods to access int values in the standard configuration * - * @param key a string containing the key value for the configuration value + * @param key a string containing the key for the configuration value * @return int a int containing the value * -1 if the key is not defined. */ @@ -209,7 +228,7 @@ public class Configuration { /** * convenience methods to access boolean values in the configuration * - * @param key a string containing the key value for the configuration value + * @param key a string containing the key for the configuration value * @return boolean true or false as value * null if the key is not defined. */ @@ -220,35 +239,53 @@ public class Configuration { /** * convenience methods to access list values in the standard configuration * - * @param key a string containing the key value for the configuration value - * @return Vector a Vector containing the values + * @param key a string containing the key for the configuration value + * @return ArrayList a ArrayList containing the values * null if the key is not defined. */ - public static Vector getListValue(String key) { + public static ArrayList getListValue(String key) { return Configuration.getListValue(key, Configuration.STANDARD); } /** - * convenience methods to access map/hashtable values in the standard configuration + * convenience methods to access map/hashtable values in the standard + * configuration * - * @param key a string containing the key value for the configuration value - * @return Hashtable a Hashtable containing the values + * @param key a string containing the key for the configuration value + * @return HashMap a HashMap containing the values * null if the key is not defined. */ - public static Hashtable getHashtableValue(String key) { - return Configuration.getHashtableValue(key, Configuration.STANDARD); + public static HashMap getHashMapValue(String key) { + return Configuration.getHashMapValue(key, Configuration.STANDARD); + } + + + /** + * Convenience method to access values in HashMap entries in the + * standard configuration. + * @param map a string containing the key for the configuration value. + * N.B. this is the key of the HashMap itself. + * @param key an object containing the key for an entry in the + * HashMap indexed by map. + * @return an Object containing the value associated with + * key, or null + * if the map is not defined, the keyentry is not defined, + * or the keyentry is itself null. + */ + public static Object getHashMapEntry(String map, Object key) { + return Configuration.getHashMapEntry(map, key, STANDARD); } /** * method to access fonts values in the standard configuration * - * @param key a string containing the key value for the configuration value - * @return Hashtable a Hashtable containing the values + * @param key a string containing the key for the configuration value + * @return HashMap a HashMap containing the values * null if the key is not defined. */ - public static Vector getFonts() { - return (Vector)Configuration.getValue("fonts", + public static ArrayList getFonts() { + return (ArrayList)Configuration.getValue("fonts", Configuration.STANDARD); } @@ -256,7 +293,7 @@ public class Configuration { * initializes this configuration * @param config contains the configuration information */ - public static void setup(int role, Hashtable config) { + public static void setup(int role, HashMap config) { switch (role) { case Configuration.STANDARD: standardConfiguration = config; @@ -268,16 +305,19 @@ public class Configuration { awtConfiguration = config; break; default: - MessageHandler.errorln("Can't setup configuration. Unknown configuration role/target"); + MessageHandler.errorln( + "Can't setup configuration. Unknown configuration role/target" + ); } } /** * adds information to the configuration map/hashtable in key,value form - * @param key a string containing the key value for the configuration value + * @param key a string containing the key for the configuration value * value the configuration information - * role detemines the configuration target - * @param value an Object containing the value; can be a String, a Vector or a Hashtable + * role determines the configuration target + * @param value an Object containing the value; + * can be a String, a Boolean, and Integer, an ArrayList or a HashMap */ public static void put(String key, Object value, int role) { switch (role) { @@ -292,20 +332,20 @@ public class Configuration { break; default: standardConfiguration.put(key, value); - MessageHandler.errorln("Unknown role for new configuration entry. " - + "Putting key:" + key + " - value:" + MessageHandler.errorln("Unknown role for new configuration entry." + + " Putting key:" + key + " - value:" + value + " into standard configuration."); } } - ; /** - * adds information to the standard configuration map/hashtable in key,value form - * @param key a string containing the key value for the configuration value + * adds information to the standard configuration hashmap in key.value form + * @param key a string containing the key for the configuration value * value the configuration information - * role detemines the configuration target - * @param value an Object containing the value; can be a String, a Vector or a Hashtable + * role determines the configuration target + * @param value an Object containing the value; + * can be a String, a Boolean, an Integer, an ArrayList or a HashMap */ public static void put(String key, Object value) { @@ -318,38 +358,44 @@ public class Configuration { public static void dumpConfiguration() { String key; Object value; - Vector list; - Hashtable map, configuration; - Enumeration enum; + ArrayList list; + HashMap map, configuration; + Iterator iterator; String tmp; System.out.println("Dumping configuration: "); - Hashtable[] configs = { + HashMap[] configs = { standardConfiguration, pdfConfiguration, awtConfiguration }; for (int i = 0; i < configs.length; i++) { MessageHandler.logln("----------------------"); configuration = configs[i]; - Enumeration enumeration = configuration.keys(); - while (enumeration.hasMoreElements()) { - key = (String)enumeration.nextElement(); + Iterator iter = configuration.keySet().iterator(); + while (iter.hasNext()) { + key = (String)iter.next(); MessageHandler.logln("key: " + key); value = configuration.get(key); if (value instanceof String) { MessageHandler.logln(" value: " + value); - } else if (value instanceof Vector) { - list = (Vector)value; - enum = list.elements(); + } else if (value instanceof Boolean) { + MessageHandler.logln + (" value: " + ((Boolean)value).booleanValue()); + } else if (value instanceof Integer) { + MessageHandler.logln + (" value: " + ((Integer)value).intValue()); + } else if (value instanceof ArrayList) { + list = (ArrayList)value; + iterator = list.iterator(); MessageHandler.log(" values: "); - while (enum.hasMoreElements()) { - MessageHandler.log(enum.nextElement() + " - "); + while (iterator.hasNext()) { + MessageHandler.log(iterator.next() + " - "); } MessageHandler.logln(""); - } else if (value instanceof Hashtable) { - map = (Hashtable)value; - enum = map.keys(); + } else if (value instanceof HashMap) { + map = (HashMap)value; + iterator = map.keySet().iterator(); MessageHandler.log(" values: "); - while (enum.hasMoreElements()) { - tmp = (String)enum.nextElement(); + while (iterator.hasNext()) { + tmp = (String)iterator.next(); MessageHandler.log(" " + tmp + ":" + map.get(tmp)); } MessageHandler.logln(""); @@ -358,7 +404,5 @@ public class Configuration { } } - - }