@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___add___doc) final synchronized PyObject list___add__(PyObject o) { PyList sum = null; if (o instanceof PySequenceList && !(o instanceof PyTuple)) { if (o instanceof PyList) { List oList = ((PyList) o).list; List newList = new ArrayList(list.size() + oList.size()); newList.addAll(list); newList.addAll(oList); sum = fromList(newList); } } else if (!(o instanceof PySequenceList)) { // also support adding java lists (but not PyTuple!) Object oList = o.__tojava__(List.class); if (oList != Py.NoConversion && oList != null) { List otherList = (List) oList; sum = new PyList(); sum.list_extend(this); for (Iterator i = otherList.iterator(); i.hasNext(); ) { sum.add(i.next()); } } } return sum; }
/** Provide functionality for Oracle specific types, such as ROWID. */ public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { if (DataHandler.checkNull(stmt, index, object, type)) { return; } switch (type) { case OracleTypes.ROWID: stmt.setString(index, (String) object.__tojava__(String.class)); break; case Types.DECIMAL: // Oracle is annoying Object input = object.__tojava__(Double.class); if (input != Py.NoConversion) { stmt.setDouble(index, ((Double) input).doubleValue()); break; } super.setJDBCObject(stmt, index, object, type); break; case Types.NUMERIC: super.setJDBCObject(stmt, index, object, Types.DOUBLE); break; case Types.BLOB: case Types.CLOB: Integer[] vals = {new Integer(index), new Integer(type)}; String msg = zxJDBC.getString("errorSettingIndex", vals); throw new SQLException(msg); default: super.setJDBCObject(stmt, index, object, type); } }
// XXX: needs __doc__ @ExposedMethod(type = MethodType.BINARY) final synchronized PyObject list___radd__(PyObject o) { // Support adding java.util.List, but prevent adding PyTuple. // 'o' should never be a PyNewList since __add__ is defined. PyList sum = null; if (o instanceof PySequence) { return null; } Object oList = o.__tojava__(List.class); if (oList != Py.NoConversion && oList != null) { sum = new PyList(); sum.addAll((List) oList); sum.extend(this); } return sum; }
public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the // specified class. Without this, derived.__tojava__(PyObject.class) // would broke. (And that's not pure speculation: PyReflectedFunction's // ReflectedArgs asks for things like that). if ((c != Object.class) && (c != Serializable.class) && (c.isInstance(this))) { return this; } // Otherwise, we call the derived __tojava__, if it exists: PyType self_type = getType(); PyObject impl = self_type.lookup("__tojava__"); if (impl != null) { PyObject delegate = impl.__get__(this, self_type).__call__(Py.java2py(c)); if (delegate != this) return delegate.__tojava__(Object.class); } return super.__tojava__(c); }
@Override protected void setslice(int start, int stop, int step, PyObject value) { if (stop < start) { stop = start; } if (value instanceof PyList) { if (value == this) { // copy value = new PyList((PySequence) value); } setslicePyList(start, stop, step, (PyList) value); } else if (value instanceof PySequence) { setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (value != null && !(value instanceof List)) { value = new PyList(value); setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { List valueList = (List) value.__tojava__(List.class); if (valueList != null && valueList != Py.NoConversion) { setsliceList(start, stop, step, valueList); } } }
public static Object unwrap(PyObject arg) { return arg.__tojava__(Object.class); }