From: <zy...@us...> - 2009-04-23 07:38:55
|
Revision: 6257 http://jython.svn.sourceforge.net/jython/?rev=6257&view=rev Author: zyasoft Date: 2009-04-23 07:38:49 +0000 (Thu, 23 Apr 2009) Log Message: ----------- Fixed PyList#toArray(Object[]), which in turn fixes initializing a Vector from a list on Java 5. This change resolves the test_java_list_delegate. Also fixed PyList#iterator, resolving #1323 (still need to put in a test). Modified Paths: -------------- trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-04-23 05:46:39 UTC (rev 6256) +++ trunk/jython/src/org/python/core/PyList.java 2009-04-23 07:38:49 UTC (rev 6257) @@ -772,8 +772,10 @@ @Override public boolean containsAll(Collection c) { - if (c instanceof PySequenceList) { - return list.containsAll(c); + if (c instanceof PyList) { + return list.containsAll(((PyList) c).list); + } else if (c instanceof PyTuple) { + return list.containsAll(((PyTuple) c).getList()); } else { return list.containsAll(new PyList(c)); } @@ -783,8 +785,9 @@ public boolean equals(Object o) { if (o instanceof PyList) { return (((PyList) o).list.equals(list)); - } else if (o instanceof List) { // XXX copied from PyList, but... - return o.equals(this); // XXX shouldn't this compare using py2java? + } else if (o instanceof List && !(o instanceof PyTuple)) { + List oList = (List) o; + return oList.equals(list); } return false; } @@ -813,7 +816,23 @@ @Override public Iterator iterator() { - return list.iterator(); + return new Iterator() { + + private final Iterator<PyObject> iter = list.iterator(); + + public boolean hasNext() { + return iter.hasNext(); + } + + public Object next() { + return iter.next().__tojava__(Object.class); + } + + public void remove() { + iter.remove(); + } + }; + } @Override @@ -945,14 +964,14 @@ @Override public Object[] toArray(Object[] a) { Object copy[] = list.toArray(); - if (a.length != copy.length) { + if (a.length < copy.length) { a = copy; } for (int i = 0; i < copy.length; i++) { a[i] = ((PyObject) copy[i]).__tojava__(Object.class); } - for (int i = copy.length; i < a.length; i++) { - a[i] = null; + if (a.length > copy.length) { + a[copy.length] = null; } return a; } Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-04-23 05:46:39 UTC (rev 6256) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-04-23 07:38:49 UTC (rev 6257) @@ -460,7 +460,13 @@ @Override public boolean containsAll(Collection c) { - return getList().containsAll(new PyList(c)); + if (c instanceof PyList) { + return getList().containsAll(((PyList)c).list); + } else if (c instanceof PyTuple) { + return getList().containsAll(((PyTuple)c).getList()); + } else { + return getList().containsAll(new PyList(c)); + } } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |