From: <cg...@us...> - 2008-12-22 03:21:49
|
Revision: 5786 http://jython.svn.sourceforge.net/jython/?rev=5786&view=rev Author: cgroves Date: 2008-12-22 03:21:46 +0000 (Mon, 22 Dec 2008) Log Message: ----------- Use Generic.map to create genericized versions of all the newly HashMapped instances. Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/handler/RowIdHandler.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java trunk/jython/src/org/python/modules/_weakref/GlobalRef.java trunk/jython/src/org/python/modules/cPickle.java Modified: trunk/jython/src/com/ziclix/python/sql/handler/RowIdHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/handler/RowIdHandler.java 2008-12-22 02:18:12 UTC (rev 5785) +++ trunk/jython/src/com/ziclix/python/sql/handler/RowIdHandler.java 2008-12-22 03:21:46 UTC (rev 5786) @@ -12,13 +12,13 @@ import com.ziclix.python.sql.DataHandler; import java.util.Map; -import java.util.HashMap; import java.sql.Statement; import java.sql.SQLException; import java.lang.reflect.Method; import org.python.core.PyObject; import org.python.core.Py; +import org.python.util.Generic; /** * Handle the rowid methods since the API is not available until JDBC 3.0. @@ -29,7 +29,7 @@ */ public abstract class RowIdHandler extends FilterDataHandler { - private static Map ROWIDS = new HashMap(); + private static Map<Class<?>, Object> ROWIDS = Generic.map(); private static Object CHECKED = new Object(); public RowIdHandler(DataHandler handler) { @@ -52,7 +52,7 @@ */ public PyObject getRowId(Statement stmt) throws SQLException { - Class c = stmt.getClass(); + Class<?> c = stmt.getClass(); Object o = ROWIDS.get(c); if (o == null) { Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-12-22 02:18:12 UTC (rev 5785) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-12-22 03:21:46 UTC (rev 5786) @@ -7,7 +7,6 @@ import java.net.URL; import java.net.URLDecoder; import java.security.AccessControlException; -import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; @@ -21,6 +20,7 @@ import org.python.core.packagecache.SysPackageManager; import org.python.modules.Setup; import org.python.modules.zipimport.zipimporter; +import org.python.util.Generic; /** * The "sys" module. @@ -31,7 +31,7 @@ public static final String PYTHON_CACHEDIR = "python.cachedir"; public static final String PYTHON_CACHEDIR_SKIP = "python.cachedir.skip"; protected static final String CACHEDIR_DEFAULT_NAME = "cachedir"; - + public static final String JYTHON_JAR = "jython.jar"; public static final String JYTHON_COMPLETE_JAR = "jython-complete.jar"; @@ -76,7 +76,7 @@ public static PackageManager packageManager; public static File cachedir; - + private static PyList defaultPath; private static PyList defaultArgv; private static PyObject defaultExecutable; @@ -86,7 +86,7 @@ public static PyObject exec_prefix = Py.EmptyString; private static boolean initialized = false; - + /** The arguments passed to this program on the command line. */ public PyList argv = new PyList(); @@ -127,7 +127,7 @@ public PyObject last_traceback = Py.None; public PyObject __name__ = new PyString("sys"); - + public PyObject __dict__; private int recursionlimit = 1000; @@ -170,7 +170,7 @@ __dict__.__setitem__("displayhook", __displayhook__); __dict__.__setitem__("excepthook", __excepthook__); } - + void reload() throws PyIgnoreMethodTag { __dict__.invoke("update", getType().fastGetDict()); } @@ -426,7 +426,7 @@ platform = new PyString("java" + version); } - private static void initRegistry(Properties preProperties, Properties postProperties, + private static void initRegistry(Properties preProperties, Properties postProperties, boolean standalone, String jarFileName) { if (registry != null) { @@ -641,8 +641,8 @@ private static PyList initArgv(String[] args) { PyList argv = new PyList(); if (args != null) { - for (int i=0; i<args.length; i++) { - argv.append(new PyString(args[i])); + for (String arg : args) { + argv.append(new PyString(arg)); } } return argv; @@ -697,15 +697,15 @@ } private static void initBuiltins(Properties props) { - builtinNames = new HashMap<String,String>(); + builtinNames = Generic.map(); // add the oddball builtins that are specially handled builtinNames.put("__builtin__", ""); builtinNames.put("sys", ""); // add builtins specified in the Setup.java file - for (int i=0; i < Setup.builtinModules.length; i++) - addBuiltin(Setup.builtinModules[i]); + for (String builtinModule : Setup.builtinModules) + addBuiltin(builtinModule); // add builtins specified in the registry file String builtinprop = props.getProperty("python.modules.builtin", ""); @@ -723,7 +723,7 @@ } public static String getBuiltin(String name) { - return (String)builtinNames.get(name); + return builtinNames.get(name); } private static PyList initPath(Properties props, boolean standalone, String jarFileName) { @@ -737,15 +737,15 @@ // standalone jython: add the /Lib directory inside JYTHON_JAR to the path addPaths(path, jarFileName + "/Lib"); } - + return path; } - + /** * Check if we are in standalone mode. - * + * * @param jarFileName The name of the jar file - * + * * @return <code>true</code> if we have a standalone .jar file, <code>false</code> otherwise. */ private static boolean isStandalone(String jarFileName) { @@ -888,7 +888,6 @@ if (o == Py.None) return; - PySystemState sys = Py.getThreadState().systemState; PySystemState.builtins.__setitem__("_", Py.None); Py.stdout.println(o.__repr__()); PySystemState.builtins.__setitem__("_", o); Modified: trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2008-12-22 02:18:12 UTC (rev 5785) +++ trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2008-12-22 03:21:46 UTC (rev 5786) @@ -4,6 +4,7 @@ package org.python.core.packagecache; import org.python.core.Options; +import org.python.util.Generic; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -19,9 +20,6 @@ import java.net.URL; import java.net.URLConnection; import java.security.AccessControlException; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -37,7 +35,7 @@ /** * Message log method - hook. This default impl does nothing. - * + * * @param msg message text */ protected void message(String msg) { @@ -45,7 +43,7 @@ /** * Warning log method - hook. This default impl does nothing. - * + * * @param warn warning text */ protected void warning(String warn) { @@ -53,7 +51,7 @@ /** * Comment log method - hook. This default impl does nothing. - * + * * @param msg message text */ protected void comment(String msg) { @@ -61,7 +59,7 @@ /** * Debug log method - hook. This default impl does nothing. - * + * * @param msg message text */ protected void debug(String msg) { @@ -72,7 +70,7 @@ * by {@link #addJarToPackages} in order to filter out classes whose name * contains '$' (e.g. inner classes,...). Should be used or overriden by * derived classes too. Also to be used in {@link #doDir}. - * + * * @param name class/pkg name * @param pkg if true, name refers to a pkg * @return true if name must be filtered out @@ -87,7 +85,7 @@ * classes. Should be used or overriden by derived classes too. Also to be * used in {@link #doDir}. Access perms can be read with * {@link #checkAccess}. - * + * * @param name class name * @param acc class access permissions as int * @return true if name must be filtered out @@ -100,11 +98,11 @@ private Map<String,JarXEntry> jarfiles; - private static String vectorToString(List vec) { - int n = vec.size(); + private static String listToString(List<String> list) { + int n = list.size(); StringBuilder ret = new StringBuilder(); for (int i = 0; i < n; i++) { - ret.append((String) vec.get(i)); + ret.append(list.get(i)); if (i < n - 1) { ret.append(","); } @@ -114,7 +112,7 @@ // Add a single class from zipFile to zipPackages // Only add valid, public classes - private void addZipEntry(Map zipPackages, ZipEntry entry, + private void addZipEntry(Map<String, List<String>[]> zipPackages, ZipEntry entry, ZipInputStream zip) throws IOException { String name = entry.getName(); // System.err.println("entry: "+name); @@ -142,9 +140,9 @@ return; } - List[] vec = (List[]) zipPackages.get(packageName); + List<String>[] vec = zipPackages.get(packageName); if (vec == null) { - vec = new ArrayList[] { new ArrayList(), new ArrayList() }; + vec = new List[] { Generic.list(), Generic.list() }; zipPackages.put(packageName, vec); } int access = checkAccess(zip); @@ -156,8 +154,8 @@ } // Extract all of the packages in a single jarfile - private Map getZipPackages(InputStream jarin) throws IOException { - Map zipPackages = new HashMap(); + private Map<String, String> getZipPackages(InputStream jarin) throws IOException { + Map<String, List<String>[]> zipPackages = Generic.map(); ZipInputStream zip = new ZipInputStream(jarin); @@ -168,16 +166,17 @@ } // Turn each vector into a comma-separated String - for (Object key : zipPackages.keySet()) { - List[] vec = (List[]) zipPackages.get(key); - String classes = vectorToString(vec[0]); + Map<String, String> transformed = Generic.map(); + for (String key : zipPackages.keySet()) { + List<String>[] vec = zipPackages.get(key); + String classes = listToString(vec[0]); if (vec[1].size() > 0) { - classes += '@' + vectorToString(vec[1]); + classes += '@' + listToString(vec[1]); } - zipPackages.put(key, classes); + transformed.put(key, classes); } - return zipPackages; + return transformed; } /** @@ -247,7 +246,7 @@ return; } - Map zipPackages = null; + Map<String, String> zipPackages = null; long mtime = 0; String jarcanon = null; @@ -264,7 +263,7 @@ jarcanon = jarurl.toString(); } - entry = (JarXEntry) this.jarfiles.get(jarcanon); + entry = this.jarfiles.get(jarcanon); if ((entry == null || !(new File(entry.cachefile).exists())) && cache) { @@ -345,7 +344,7 @@ // Read in cache file storing package info for a single .jar // Return null and delete this cachefile if it is invalid - private Map readCacheFile(JarXEntry entry, String jarcanon) { + private Map<String, String> readCacheFile(JarXEntry entry, String jarcanon) { String cachefile = entry.cachefile; long mtime = entry.mtime; @@ -361,7 +360,7 @@ deleteCacheFile(cachefile); return null; } - Map packs = new HashMap(); + Map<String, String> packs = Generic.map(); try { while (true) { String packageName = istream.readUTF(); @@ -406,7 +405,7 @@ */ protected void initCache() { this.indexModified = false; - this.jarfiles = new HashMap(); + this.jarfiles = Generic.map(); try { DataInputStream istream = inOpenIndex(); @@ -419,8 +418,7 @@ String jarcanon = istream.readUTF(); String cachefile = istream.readUTF(); long mtime = istream.readLong(); - this.jarfiles - .put(jarcanon, new JarXEntry(cachefile, mtime)); + this.jarfiles.put(jarcanon, new JarXEntry(cachefile, mtime)); } } catch (EOFException eof) { ; Modified: trunk/jython/src/org/python/modules/_weakref/GlobalRef.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2008-12-22 02:18:12 UTC (rev 5785) +++ trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2008-12-22 03:21:46 UTC (rev 5786) @@ -5,7 +5,6 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.HashMap; import java.util.Map; import java.util.List; @@ -13,6 +12,7 @@ import org.python.core.PyException; import org.python.core.PyList; import org.python.core.PyObject; +import org.python.util.Generic; public class GlobalRef extends WeakReference { @@ -27,7 +27,7 @@ private static RefReaperThread reaperThread; - private static Map objects = new HashMap(); + private static Map<GlobalRef, GlobalRef> objects = Generic.map(); static { initReaperThread(); @@ -122,7 +122,7 @@ } public static GlobalRef newInstance(PyObject object) { - GlobalRef ref = (GlobalRef)objects.get(new GlobalRef(object)); + GlobalRef ref = objects.get(new GlobalRef(object)); if (ref == null) { ref = new GlobalRef(object); objects.put(ref, ref); Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2008-12-22 02:18:12 UTC (rev 5785) +++ trunk/jython/src/org/python/modules/cPickle.java 2008-12-22 03:21:46 UTC (rev 5786) @@ -13,7 +13,6 @@ package org.python.modules; import java.math.BigInteger; -import java.util.HashMap; import java.util.Map; import org.python.core.ClassDictInit; @@ -44,6 +43,7 @@ import org.python.core.codecs; import org.python.core.exceptions; import org.python.core.imp; +import org.python.util.Generic; /** * @@ -1512,11 +1512,8 @@ } + private static Map<PyObject,PyObject> classmap = Generic.map(); - - - private static Map<PyObject,PyObject> classmap = new HashMap<PyObject,PyObject>(); - final private static PyObject whichmodule(PyObject cls, PyObject clsname) { @@ -1705,7 +1702,7 @@ private IOFile file; - public Map<String,PyObject> memo = new HashMap<String,PyObject>(); + public Map<String,PyObject> memo = Generic.map(); /** * For the benefit of persistency modules written using pickle, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |