Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
package org.python.core;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.python.util.Generic;
/**
* Proxy Java objects implementing java.util.List with Python methods corresponding to the standard
* list type
*/
class JavaProxyList {
@Untraversable
private static class ListMethod extends PyBuiltinMethodNarrow {
protected ListMethod(String name, int numArgs) {
super(name, numArgs);
}
protected ListMethod(String name, int minArgs, int maxArgs) {
super(name, minArgs, maxArgs);
}
protected List asList() {
return (List) self.getJavaProxy();
}
protected List newList() {
try {
return (List) asList().getClass().getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException | SecurityException
| IllegalArgumentException e) {
throw Py.JavaError(e);
}
}
/**
* Compares this object with other to check for equality. Used to implement __eq __ and
* __ne__. May return null if the other object cannot be compared i.e. is not a Python list
* or Java List.
*
* @param other The object to compare to this
* @return true is equal, false if not equal and null if we can't compare
*/
protected PyBoolean isEqual(PyObject other) {
if (isPyList(other)) {
// Being compared to a Python list
PyList oList = (PyList) other;
List jList = asList();
if (jList.size() != oList.size()) {
// Size mismatched so not equal
return Py.False;
}
for (int i = 0; i < jList.size(); i++) {
// Do element by element comparison, if any elements are not equal return false
if (!Py.java2py(jList.get(i))._eq(oList.pyget(i)).__nonzero__()) {
return Py.False;
}
}
// All elements are equal so the lists are equal
return Py.True;
} else {
// Being compared to something that is not a Python list
Object oj = other.getJavaProxy();
if (oj instanceof List) {
// Being compared to a Java List
List oList = (List) oj;
List jList = asList();
if (jList.size() != oList.size()) {
// Size mismatched so not equal
return Py.False;
}
for (int i = 0; i < jList.size(); i++) {
/*
* Do element by element comparison, if any elements are not equal return
* false.
*/
if (!Py.java2py(jList.get(i))._eq(Py.java2py(oList.get(i))).__nonzero__()) {
return Py.False;
}
}
// All elements are equal so the lists are equal
return Py.True;
} else {
/*
* other is not a Python or Java list, so we don't know if were equal therefore
* return null.
*/
return null;
}
}
}
private boolean isPyList(PyObject object) {
return object.getType().isSubType(PyList.TYPE);
}
}
protected static class ListIndexDelegate extends SequenceIndexDelegate {
private final List list;
public ListIndexDelegate(List list) {
this.list = list;
}
@Override
public void delItem(int idx) {
list.remove(idx);
}
@Override
public PyObject getItem(int idx) {
return Py.java2py(list.get(idx));
}
@Override
public PyObject getSlice(int start, int stop, int step) {
if (step > 0 && stop < start) {
stop = start;
}
int n = PySequence.sliceLength(start, stop, step);
List newList;
try {
newList = list.getClass().getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException | SecurityException
| IllegalArgumentException e) {
throw Py.JavaError(e);
}
int j = 0;
for (int i = start; j < n; i += step) {
newList.add(list.get(i));
j++;
}
return Py.java2py(newList);
}
@Override
public String getTypeName() {
return list.getClass().getName();
}
@Override
public int len() {
return list.size();
}
protected int fixBoundIndex(PyObject index) {
PyInteger length = Py.newInteger(len());
if (index._lt(Py.Zero).__nonzero__()) {
index = index._add(length);
if (index._lt(Py.Zero).__nonzero__()) {
index = Py.Zero;
}
} else if (index._gt(length).__nonzero__()) {
index = length;
}
int i = index.asIndex();
assert i >= 0;
return i;
}
@Override
public void setItem(int idx, PyObject value) {
list.set(idx, value.__tojava__(Object.class));
}
@Override
public void setSlice(int start, int stop, int step, PyObject value) {
if (stop < start) {
stop = start;
}
if (JyAttribute.getAttr(value, JyAttribute.JAVA_PROXY_ATTR) == this.list) {
List xs = Generic.list();
xs.addAll(this.list);
setsliceList(start, stop, step, xs);
} else if (value instanceof PyList) {
setslicePyList(start, stop, step, (PyList) value);
} else {
Object valueList = value.__tojava__(List.class);
if (valueList != null && valueList != Py.NoConversion) {
setsliceList(start, stop, step, (List) valueList);
} else {
setsliceIterator(start, stop, step, value.asIterable().iterator());
}
}
}
final private void setsliceList(int start, int stop, int step, List value) {
if (step == 1) {
list.subList(start, stop).clear();
list.addAll(start, value);
} else {
int size = list.size();
Iterator