From: <zy...@us...> - 2009-04-18 01:06:27
|
Revision: 6238 http://jython.svn.sourceforge.net/jython/?rev=6238&view=rev Author: zyasoft Date: 2009-04-18 01:06:26 +0000 (Sat, 18 Apr 2009) Log Message: ----------- All tests now pass, so just need some minor cleanup. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PyTuple.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-17 23:50:17 UTC (rev 6237) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-18 01:06:26 UTC (rev 6238) @@ -758,28 +758,13 @@ @Override public boolean addAll(int index, Collection c) { - if (c instanceof PySequenceList) { - list.addAll(index, c); - } else { - // need to use add to convert anything pulled from a collection into a PyObject - for (Object element : c) { - add(element); - } - } - return c.size() > 0; + PyList elements = new PyList(c); + return list.addAll(index, elements.list); } @Override public boolean addAll(Collection c) { - if (c instanceof PySequenceList) { - list.addAll(c); - } else { - // need to use add to convert anything pulled from a collection into a PyObject - for (Object element : c) { - add(element); - } - } - return c.size() > 0; + return addAll(0, c); } @Override @@ -846,57 +831,51 @@ @Override public ListIterator listIterator() { - return new PyListIterator(0); + return listIterator(0); } @Override - public ListIterator listIterator(int index) { - return new PyListIterator(index); - } + public ListIterator listIterator(final int index) { + return new ListIterator() { - public class PyListIterator implements ListIterator { + private final ListIterator<PyObject> iter = list.listIterator(index); - private final ListIterator<PyObject> iter; + public boolean hasNext() { + return iter.hasNext(); + } - PyListIterator(int index) { - iter = list.listIterator(index); - } + public Object next() { + return iter.next().__tojava__(Object.class); + } - public boolean hasNext() { - return iter.hasNext(); - } + public boolean hasPrevious() { + return iter.hasPrevious(); + } - public Object next() { - return iter.next().__tojava__(Object.class); - } + public Object previous() { + return iter.previous().__tojava__(Object.class); + } - public boolean hasPrevious() { - return iter.hasPrevious(); - } + public int nextIndex() { + return iter.nextIndex(); + } - public Object previous() { - return iter.previous().__tojava__(Object.class); - } + public int previousIndex() { + return iter.previousIndex(); + } - public int nextIndex() { - return iter.nextIndex(); - } + public void remove() { + iter.remove(); + } - public int previousIndex() { - return iter.previousIndex(); - } + public void set(Object o) { + iter.set(Py.java2py(o)); + } - public void remove() { - iter.remove(); - } - - public void set(Object o) { - iter.set(Py.java2py(o)); - } - - public void add(Object o) { - iter.add(Py.java2py(o)); - } + public void add(Object o) { + iter.add(Py.java2py(o)); + } + }; } @Override Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-17 23:50:17 UTC (rev 6237) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-18 01:06:26 UTC (rev 6238) @@ -322,7 +322,17 @@ } public List subList(int fromIndex, int toIndex) { - return Collections.unmodifiableList(getList().subList(fromIndex, toIndex)); + if (fromIndex < 0 || toIndex > size()) { + throw new IndexOutOfBoundsException(); + } else if (fromIndex > toIndex) { + throw new IllegalArgumentException(); + } + System.err.println("subList" + fromIndex + "," + toIndex); + PyObject elements[] = new PyObject[toIndex - fromIndex]; + for (int i = 0, j = fromIndex; i < elements.length; i++, j++) { + elements[i] = array[j]; + } + return new PyTuple(elements); } // Make PyTuple immutable from the collections interfaces by overriding @@ -331,18 +341,18 @@ public Iterator iterator() { return new Iterator() { - Iterator i = getList().iterator(); + private final Iterator<PyObject> iter = getList().iterator(); public void remove() { throw new UnsupportedOperationException(); } public boolean hasNext() { - return i.hasNext(); + return iter.hasNext(); } public Object next() { - return i.next(); + return iter.next().__tojava__(Object.class); } }; } @@ -394,30 +404,30 @@ public ListIterator listIterator(final int index) { return new ListIterator() { - ListIterator i = getList().listIterator(index); + private final ListIterator<PyObject> iter = getList().listIterator(index); public boolean hasNext() { - return i.hasNext(); + return iter.hasNext(); } public Object next() { - return i.next(); + return iter.next().__tojava__(Object.class); } public boolean hasPrevious() { - return i.hasPrevious(); + return iter.hasPrevious(); } public Object previous() { - return i.previous(); + return iter.previous().__tojava__(Object.class); } public int nextIndex() { - return i.nextIndex(); + return iter.nextIndex(); } public int previousIndex() { - return i.previousIndex(); + return iter.previousIndex(); } public void remove() { @@ -447,12 +457,12 @@ @Override public boolean contains(Object o) { - return getList().contains(o); + return getList().contains(Py.java2py(o)); } @Override public boolean containsAll(Collection c) { - return getList().containsAll(c); + return getList().containsAll(new PyList(c)); } @Override @@ -487,7 +497,7 @@ @Override public int lastIndexOf(Object o) { - return getList().lastIndexOf(o); + return getList().lastIndexOf(Py.java2py(o)); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |