From: <cg...@us...> - 2008-11-23 00:46:12
|
Revision: 5605 http://jython.svn.sourceforge.net/jython/?rev=5605&view=rev Author: cgroves Date: 2008-11-23 00:46:06 +0000 (Sun, 23 Nov 2008) Log Message: ----------- Use PyJavaType to initialize array, not PyJavaClass Modified Paths: -------------- branches/newstyle-java-types/Lib/test/test_array_jy.py branches/newstyle-java-types/src/org/python/core/PyArray.java Modified: branches/newstyle-java-types/Lib/test/test_array_jy.py =================================================================== --- branches/newstyle-java-types/Lib/test/test_array_jy.py 2008-11-23 00:18:15 UTC (rev 5604) +++ branches/newstyle-java-types/Lib/test/test_array_jy.py 2008-11-23 00:46:06 UTC (rev 5605) @@ -12,7 +12,7 @@ def test_jarray(self): # until it is fully formally removed - # While jarray is still being phased out, just flex the initilaizers. + # While jarray is still being phased out, just flex the initializers. # The rest of the test for array will catch all the big problems. import jarray jarray.array(range(5), 'i') @@ -23,7 +23,7 @@ def test_java_object_arrays(self): jStringArr = array(String, [String("a"), String("b"), String("c")]) self.assert_( - Arrays.equals(jStringArr.typecode, str(String)), + Arrays.equals(jStringArr.typecode, 'java.lang.String'), "String array typecode of wrong type, expected %s, found %s" % (jStringArr.typecode, str(String))) self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) Modified: branches/newstyle-java-types/src/org/python/core/PyArray.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyArray.java 2008-11-23 00:18:15 UTC (rev 5604) +++ branches/newstyle-java-types/src/org/python/core/PyArray.java 2008-11-23 00:46:06 UTC (rev 5605) @@ -21,7 +21,7 @@ /** * A wrapper class around native java arrays. - * + * * Instances of PyArray are created either by java functions or directly by the * jarray module. * <p> @@ -95,8 +95,8 @@ } typecode = obj.toString(); type = char2class(typecode.charAt(0)); - } else if (obj instanceof PyJavaClass) { - type = ((PyJavaClass)obj).proxyClass; + } else if (obj instanceof PyJavaType) { + type = ((PyJavaType)obj).underlying_class; typecode = type.getName(); } else { throw Py.TypeError("array() argument 1 must be char, not " + obj.getType().fastGetName()); @@ -153,7 +153,7 @@ /** * Create a PyArray storing <em>ctype</em> types and being initialised * with <em>initialiser</em>. - * + * * @param init * an initialiser for the array - can be PyString or PySequence * (including PyArray) or iterable type. @@ -325,7 +325,7 @@ /** * Adds (appends) two PyArrays together - * + * * @param other * a PyArray to be added to the instance * @return the result of the addition as a new PyArray instance @@ -348,7 +348,7 @@ /** * Length of the array - * + * * @return number of elements in the array */ public int __len__() { @@ -393,9 +393,9 @@ if (typecode.length() > 1) return typecode; else return "'" + typecode + "'"; } - + /** - * + * * @param c * target <em>Class</em> for the conversion * @return Java object converted to required class type if possible. @@ -426,7 +426,7 @@ throw Py.TypeError("array item must be unicode character"); } - + // relax to allow mixing with PyString, integers private static int getCodePointOrInt(PyObject obj) { if (obj instanceof PyUnicode) { @@ -444,14 +444,14 @@ return -1; } } - + /** * Append new value x to the end of the array. - * + * * @param value * item to be appended to the array */ - + public void append(PyObject value) { // Currently, this is asymmetric with extend, which // *will* do conversions like append(5.0) to an int array. @@ -497,7 +497,7 @@ /** * Implementation of <em>Cloneable</em> interface. - * + * * @return copy of current PyArray */ public Object clone() { @@ -507,7 +507,7 @@ /** * Converts a character code for the array type to a Java <code>Class</code>. * <p /> - * + * * The following character codes and their native types are supported:<br /> * <table> * <tr> @@ -548,10 +548,10 @@ * </tr> * </table> * <p /> - * + * * @param type * character code for the array type - * + * * @return <code>Class</code> of the native type */ @@ -609,7 +609,7 @@ else return cls.getName(); } - + @ExposedMethod public final int array_count(PyObject value) { // note: cpython does not raise type errors based on item type; @@ -634,7 +634,7 @@ } /** * Return the number of occurrences of x in the array. - * + * * @param value * instances of the value to be counted * @return number of time value was found in the array. @@ -645,7 +645,7 @@ /** * Delete the element at position <em>i</em> from the array - * + * * @param i * index of the item to be deleted from the array */ @@ -658,7 +658,7 @@ /** * Delete the slice defined by <em>start</em>, <em>stop</em> and * <em>step</em> from the array. - * + * * @param start * starting index of slice * @param stop @@ -681,7 +681,7 @@ } } } - + @ExposedMethod public final void array_extend(PyObject iterable){ extendInternal(iterable); @@ -694,7 +694,7 @@ * iterable and its elements must be the right type to be appended to the * array. Changed in version 2.4: Formerly, the argument could only be * another array. - * + * * @param iterable * iterable object used to extend the array */ @@ -707,12 +707,12 @@ * Handles specific cases of <em>iterable</em> being PyStrings or * PyArrays. Default behaviour is to defer to * {@link #extendInternalIter(PyObject) extendInternalIter } - * + * * @param iterable * object of type PyString, PyArray or any object that can be * iterated over. */ - + private void extendInternal(PyObject iterable) { if (iterable instanceof PyUnicode) { if ("u".equals(typecode)) { @@ -737,7 +737,7 @@ /** * Internal extend function to process iterable objects. - * + * * @param iterable * any object that can be iterated over. */ @@ -774,7 +774,7 @@ } } } - + private void extendArray(int[] items) { int last = delegate.getSize(); delegate.ensureCapacity(last + items.length); @@ -783,12 +783,12 @@ delegate.size++; } } - + @ExposedMethod public final void array_fromfile(PyObject f, int count){ fromfile(f, count); } - + /** * Read <em>count</em> items (as machine values) from the file object * <em>f</em> and append them to the end of the array. If less than @@ -796,7 +796,7 @@ * that were available are still inserted into the array. <em>f</em> must * be a real built-in file object; something else with a read() method won't * do. - * + * * @param f * Python builtin file object to retrieve data * @param count @@ -825,7 +825,7 @@ + Integer.toString(readcount) + " actually read"); } } - + @ExposedMethod public final void array_fromlist(PyObject obj){ fromlist(obj); @@ -834,7 +834,7 @@ /** * Append items from the list. This is equivalent to "for x in list: * a.append(x)"except that if there is a type error, the array is unchanged. - * + * * @param obj * input list object that will be appended to the array */ @@ -857,12 +857,12 @@ /** * Generic stream reader to read the entire contents of a stream into the * array. - * + * * @param is * InputStream to source the data from - * + * * @return number of primitives successfully read - * + * * @throws IOException * @throws EOFException */ @@ -873,14 +873,14 @@ /** * Generic stream reader to read <em>count</em> primitive types from a * stream into the array. - * + * * @param is * InputStream to source the data from * @param count * number of primitive types to read from the stream - * + * * @return number of primitives successfully read - * + * * @throws IOException * @throws EOFException */ @@ -948,7 +948,7 @@ * Appends items from the string, interpreting the string as an array of * machine values (as if it had been read from a file using the * {@link #fromfile(PyObject, int) fromfile()} method). - * + * * @param input * string of bytes containing array data */ @@ -990,7 +990,7 @@ /** * Get the element at position <em>i</em> from the array - * + * * @param i * index of the item to be retrieved from the array */ @@ -1003,7 +1003,7 @@ /** * Return the internal Java array storage of the PyArray instance - * + * * @return the <code>Array</code> store. */ public Object getArray() throws PyIgnoreMethodTag { @@ -1013,17 +1013,17 @@ /** * Getter for the storage size of the array's type. * <p /> - * + * * The sizes returned by this method represent the number of bytes used to * store the type. In the case of streams, this is the number of bytes * written to, or read from a stream. For memory this value is the * <em>minimum</em> number of bytes required to store the type. * <p /> - * + * * This method is used by other methods to define read/write quanta from * strings and streams. * <p /> - * + * * Values returned are:<br /> * <table> * <tr> @@ -1063,7 +1063,7 @@ * <td>8</td> * </tr> * </table> - * + * * @return number of bytes used to store array type. */ @ExposedGet(name = "itemsize") @@ -1093,7 +1093,7 @@ /** * Retrieve a slice from the array specified by the <em>start</em>, * <em>stop</em> and <em>step</em>. - * + * * @param start * start index of the slice * @param stop @@ -1124,14 +1124,14 @@ * Getter for the type code of the array. * {@link #char2class(char) char2class} describes the possible type codes * and their meaning. - * + * * @return single character type code for the array */ @ExposedGet(name = "typecode") public String getTypecode() { return typecode; } - + @ExposedMethod public final int array_index(PyObject value){ int index = indexInternal(value); @@ -1144,7 +1144,7 @@ /** * Return the smallest <em>i</em> such that <em>i</em> is the index of * the first occurrence of <em>value</em> in the array. - * + * * @param value * value to find the index of * @return index of the first occurance of <em>value</em> @@ -1156,7 +1156,7 @@ /** * Return the smallest <em>i</em> such that <em>i</em> is the index of * the first occurrence of <em>value</em> in the array. - * + * * @param value * value to find the index of * @return index of the first occurance of <em>value</em> @@ -1181,7 +1181,7 @@ } return -1; } - + @ExposedMethod public final void array_insert(int index, PyObject value){ insert(index, value); @@ -1191,7 +1191,7 @@ * Insert a new item with value <em>value</em> in the array before * position <em>index</em>. Negative values are treated as being relative * to the end of the array. - * + * * @param index * insert position * @param value @@ -1209,7 +1209,7 @@ Array.set(data, index, Py.tojava(value, type)); } } - + @ExposedMethod(defaults="-1") public final PyObject array_pop(int i){ PyObject val = pop(i); @@ -1232,7 +1232,7 @@ * Removes the item with the index <em>index</em> from the array and * returns it. The optional argument defaults to -1, so that by default the * last item is removed and returned. - * + * * @param index * array location to be popped from the array * @return array element popped from index @@ -1249,7 +1249,7 @@ delegate.remove(index); return ret; } - + @ExposedMethod public final void array_remove(PyObject value){ remove(value); @@ -1257,7 +1257,7 @@ /** * Remove the first occurrence of <em>value</em> from the array. - * + * * @param value * array value to be removed */ @@ -1273,7 +1273,7 @@ /** * Repeat the array <em>count</em> times. - * + * * @param count * number of times to repeat the array * @return A new PyArray object containing the source object repeated @@ -1289,7 +1289,7 @@ } return ret; } - + @ExposedMethod public final void array_reverse(){ reverse(); @@ -1297,7 +1297,7 @@ /** * Reverse the elements in the array - * + * */ public void reverse() { // build a new reversed array and set this.data to it when done @@ -1315,10 +1315,10 @@ * {@link AbstractArray#ensureCapacity(int) AbstractArray.ensureCapacity()} * for ways to extend capacity. * <p /> - * + * * This code specifically checks for overflows of the integral types: byte, * short, int and long. - * + * * @param i * index of the element to be set * @param value @@ -1328,8 +1328,8 @@ if ("u".equals(typecode)) { Array.setInt(data, i, getCodePoint(value)); return; - } - + } + if(type == Byte.TYPE) { long val; try { @@ -1401,15 +1401,15 @@ throw Py.TypeError("Type not compatible with array type"); } } - + public void set(int i, char value) { if ("c".equals(typecode) || type == Integer.TYPE || type == Long.TYPE) { Array.setChar(data, i, value); } else { throw Py.TypeError("Type not compatible with array type"); - } + } } - + private boolean isSigned() { return typecode.length() == 1 && typecode.equals(typecode.toUpperCase()); } @@ -1419,7 +1419,7 @@ * <code>byte</code> and <code>char</code> types) or PyArray. If a * PyArray, its type must be convertible into the type of the target * PyArray. - * + * * @param start * start index of the delete slice * @param stop @@ -1486,12 +1486,12 @@ } } } - + @ExposedMethod public final void array_tofile(PyObject f){ tofile(f); } - + @ExposedMethod public void array_write(PyObject f){ tofile(f); @@ -1499,7 +1499,7 @@ /** * Write all items (as machine values) to the file object <em>f</em>. - * + * * @param f * Python builtin file object to write data */ @@ -1521,7 +1521,7 @@ /** * Convert the array to an ordinary list with the same items. - * + * * @return array contents as a list */ public PyObject tolist() { @@ -1542,12 +1542,12 @@ /** * Generic stream writer to write the entire contents of the array to the * stream as primitive types. - * + * * @param os * OutputStream to sink the array data to - * + * * @return number of primitives successfully written - * + * * @throws IOException */ private int toStream(OutputStream os) throws IOException { @@ -1581,7 +1581,7 @@ } return dos.size(); } - + @ExposedMethod public final PyObject array_tostring(){ return new PyString(tostring()); @@ -1610,10 +1610,10 @@ int[] codepoints = new int[len]; for(int i = 0; i < len; i++) codepoints[i] = Array.getInt(data, i); - return new String(codepoints, 0, codepoints.length); + return new String(codepoints, 0, codepoints.length); } - - + + @ExposedMethod public final PyObject array_tounicode() { return new PyUnicode(tounicode()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |