From: <zy...@us...> - 2009-04-05 19:27:21
|
Revision: 6168 http://jython.svn.sourceforge.net/jython/?rev=6168&view=rev Author: zyasoft Date: 2009-04-05 19:27:20 +0000 (Sun, 05 Apr 2009) Log Message: ----------- Shim in PySequenceObjectList so that we can begin a gradual replacement of the underlying collection support for list (and probably tuple too). test_itertools and test_javalist currently fail, due to a slightly deeper stack exceeding the recursion limit. That's fine for now. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PySequenceList.java branches/newlist/src/org/python/core/PyTuple.java Added Paths: ----------- branches/newlist/src/org/python/core/PySequenceObjectList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-05 19:15:19 UTC (rev 6167) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-05 19:27:20 UTC (rev 6168) @@ -15,7 +15,7 @@ * A builtin python list. */ @ExposedType(name = "list", base = PyObject.class) -public class PyList extends PySequenceList { +public class PyList extends PySequenceObjectList { public static final PyType TYPE = PyType.fromClass(PyList.class); @@ -70,8 +70,8 @@ if(seq == null) { return; } - if(seq instanceof PySequenceList) { - PySequenceList p = (PySequenceList)seq.__getslice__(Py.None, Py.None, Py.One); + if(seq instanceof PySequenceObjectList) { + PySequenceObjectList p = (PySequenceObjectList)seq.__getslice__(Py.None, Py.None, Py.One); this.list = p.list; } else { for (PyObject item : seq.asIterable()) { Modified: branches/newlist/src/org/python/core/PySequenceList.java =================================================================== --- branches/newlist/src/org/python/core/PySequenceList.java 2009-04-05 19:15:19 UTC (rev 6167) +++ branches/newlist/src/org/python/core/PySequenceList.java 2009-04-05 19:27:20 UTC (rev 6168) @@ -5,171 +5,81 @@ import java.util.List; import java.util.ListIterator; -public abstract class PySequenceList extends PySequence implements List { +public abstract class PySequenceList extends PySequence { - protected PyObjectList list; - public PySequenceList() { - list = new PyObjectList(); } protected PySequenceList(PyType type) { super(type); - list = new PyObjectList(); } - protected PySequenceList(PyType type, PyObject[] elements) { - super(type); - list = new PyObjectList(elements); - } + public abstract void add(int index, Object element); - /** - * Creates an instance directly backed by the array of PyObject elements. - */ - public PySequenceList(PyObject[] elements) { - list = new PyObjectList(elements); - } + public abstract boolean add(Object o); - public PySequenceList(PyType type, Collection<PyObject> c) { - super(type); - list = new PyObjectList(c); - } + public abstract boolean addAll(int index, Collection c); - public void add(int index, Object element) { - list.add(index, element); - } + public abstract boolean addAll(Collection c); - public boolean add(Object o) { - return list.add(o); - } + public abstract void clear(); - public boolean addAll(int index, Collection c) { - return list.addAll(index, c); - } + public abstract boolean contains(Object o); - public boolean addAll(Collection c) { - return list.addAll(c); - } + public abstract boolean containsAll(Collection c); - public void clear() { - list.clear(); - } + public abstract boolean equals(Object o); - public boolean contains(Object o) { - return list.contains(o); - } + public abstract Object get(int index); - public boolean containsAll(Collection c) { - return list.containsAll(c); - } + /** + * Get the backing array. The array should not be modified. To get a copy of the array, see + * {@link #toArray()}. + */ + public abstract PyObject[] getArray(); - public Object get(int index) { - return list.get(index); - } + public abstract int hashCode(); - public int indexOf(Object o) { - return list.indexOf(o); - } + public abstract int indexOf(Object o); - public boolean isEmpty() { - return list.isEmpty(); - } + public abstract boolean isEmpty(); - public Iterator iterator() { - return list.iterator(); - } + public abstract Iterator iterator(); - public int lastIndexOf(Object o) { - return list.lastIndexOf(o); - } + public abstract int lastIndexOf(Object o); - public ListIterator listIterator() { - return list.listIterator(); - } + public abstract ListIterator listIterator(); - public ListIterator listIterator(int index) { - return list.listIterator(index); - } + public abstract ListIterator listIterator(int index); - public void pyadd(int index, PyObject element) { - list.pyadd(index, element); - } + public abstract void pyadd(int index, PyObject element); - public PyObject pyget(int index) { - return list.pyget(index); - } + public abstract boolean pyadd(PyObject o); - public void pyset(int index, PyObject element) { - list.pyset(index, element); - } + public abstract PyObject pyget(int index); - public Object remove(int index) { - return list.remove(index); - } + public abstract void pyset(int index, PyObject element); - public void remove(int start, int stop) { - list.remove(start, stop); - } + public abstract Object remove(int index); - public boolean remove(Object o) { - return list.remove(o); - } + public abstract void remove(int start, int stop); - public boolean removeAll(Collection c) { - return list.removeAll(c); - } + public abstract boolean remove(Object o); - public boolean retainAll(Collection c) { - return list.retainAll(c); - } + public abstract boolean removeAll(Collection c); - public Object set(int index, Object element) { - return list.set(index, element); - } + public abstract boolean retainAll(Collection c); - public int size() { - return list.size(); - } + public abstract Object set(int index, Object element); - public List subList(int fromIndex, int toIndex) { - return list.subList(fromIndex, toIndex); - } + public abstract int size(); - public Object[] toArray() { - return list.toArray(); - } + public abstract List subList(int fromIndex, int toIndex); - public Object[] toArray(Object[] a) { - return list.toArray(a); - } + public abstract Object[] toArray(); - public String toString() { - return list.toString(); - } + public abstract Object[] toArray(Object[] a); - public boolean pyadd(PyObject o) { - return list.pyadd(o); - } + public abstract String toString(); - public boolean equals(Object o) { - if(o instanceof PySequenceList) { - return list.equals(((PySequenceList)o).list); - } else if(o instanceof List) { - return o.equals(this); - } else { - return super.equals(o); - } - } - - public int hashCode() { - return list.hashCode(); - } - - /** - * Get the backing array. The array should not be modified. To get a copy of the array, see - * {@link #toArray()}. - */ - public PyObject[] getArray() { - return list.getArray(); - } } Added: branches/newlist/src/org/python/core/PySequenceObjectList.java =================================================================== --- branches/newlist/src/org/python/core/PySequenceObjectList.java (rev 0) +++ branches/newlist/src/org/python/core/PySequenceObjectList.java 2009-04-05 19:27:20 UTC (rev 6168) @@ -0,0 +1,175 @@ +package org.python.core; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +public abstract class PySequenceObjectList extends PySequenceList implements List { + + protected PyObjectList list; + + public PySequenceObjectList() { + list = new PyObjectList(); + } + + protected PySequenceObjectList(PyType type) { + super(type); + list = new PyObjectList(); + } + + protected PySequenceObjectList(PyType type, PyObject[] elements) { + super(type); + list = new PyObjectList(elements); + } + + /** + * Creates an instance directly backed by the array of PyObject elements. + */ + public PySequenceObjectList(PyObject[] elements) { + list = new PyObjectList(elements); + } + + public PySequenceObjectList(PyType type, Collection<PyObject> c) { + super(type); + list = new PyObjectList(c); + } + + public void add(int index, Object element) { + list.add(index, element); + } + + public boolean add(Object o) { + return list.add(o); + } + + public boolean addAll(int index, Collection c) { + return list.addAll(index, c); + } + + public boolean addAll(Collection c) { + return list.addAll(c); + } + + public void clear() { + list.clear(); + } + + public boolean contains(Object o) { + return list.contains(o); + } + + public boolean containsAll(Collection c) { + return list.containsAll(c); + } + + public Object get(int index) { + return list.get(index); + } + + public int indexOf(Object o) { + return list.indexOf(o); + } + + public boolean isEmpty() { + return list.isEmpty(); + } + + public Iterator iterator() { + return list.iterator(); + } + + public int lastIndexOf(Object o) { + return list.lastIndexOf(o); + } + + public ListIterator listIterator() { + return list.listIterator(); + } + + public ListIterator listIterator(int index) { + return list.listIterator(index); + } + + public void pyadd(int index, PyObject element) { + list.pyadd(index, element); + } + + public PyObject pyget(int index) { + return list.pyget(index); + } + + public void pyset(int index, PyObject element) { + list.pyset(index, element); + } + + public Object remove(int index) { + return list.remove(index); + } + + public void remove(int start, int stop) { + list.remove(start, stop); + } + + public boolean remove(Object o) { + return list.remove(o); + } + + public boolean removeAll(Collection c) { + return list.removeAll(c); + } + + public boolean retainAll(Collection c) { + return list.retainAll(c); + } + + public Object set(int index, Object element) { + return list.set(index, element); + } + + public int size() { + return list.size(); + } + + public List subList(int fromIndex, int toIndex) { + return list.subList(fromIndex, toIndex); + } + + public Object[] toArray() { + return list.toArray(); + } + + public Object[] toArray(Object[] a) { + return list.toArray(a); + } + + public String toString() { + return list.toString(); + } + + public boolean pyadd(PyObject o) { + return list.pyadd(o); + } + + public boolean equals(Object o) { + if(o instanceof PySequenceObjectList) { + return list.equals(((PySequenceObjectList)o).list); + } else if(o instanceof List) { + return o.equals(this); + } else { + return ((PySequence)this).equals(o); + } + } + + public int hashCode() { + return list.hashCode(); + } + + /** + * Get the backing array. The array should not be modified. To get a copy of the array, see + * {@link #toArray()}. + */ + public PyObject[] getArray() { + return list.getArray(); + } +} Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-05 19:15:19 UTC (rev 6167) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-05 19:27:20 UTC (rev 6168) @@ -17,7 +17,7 @@ */ @ExposedType(name = "tuple", base = PyObject.class) -public class PyTuple extends PySequenceList +public class PyTuple extends PySequenceObjectList { public static final PyType TYPE = PyType.fromClass(PyTuple.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |