@Override public PyInteger read(Kryo kryo, Input input, Class<PyInteger> type) { return new PyInteger(input.readInt()); } }
@Override public void write(Kryo kryo, Output output, PyInteger object) { output.writeInt(object.getValue()); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___xor___doc) final PyObject int___xor__(PyObject right) { int rightv; if (right instanceof PyInteger) { rightv = ((PyInteger)right).getValue(); } else if (right instanceof PyLong) { return int___long__().__xor__(right); } else { return null; } return Py.newInteger(getValue() ^ rightv); }
@ExposedMethod(doc = BuiltinDocs.int___abs___doc) final PyObject int___abs__() { if (getValue() < 0) { return int___neg__(); } return int___int__(); }
for (int i = 0; i < MEDIUM; i++) { int b = aRef[i] ^ 0x55; // != a[i] PyInteger pyb = new PyInteger(b); a.__setitem__(i, pyb); int ai = a.pyget(i).asInt(); if (verbose >= 3) { System.out.printf(" __setitem__(%2d,%3d) : a[%2d]=%3d\n", i, b, i, ai); PyInteger b = new PyInteger(i); try { a.__setitem__(0, b); PyInteger x = new PyInteger(10); for (int i : new int[] {-1 - MEDIUM, -100 - MEDIUM, MEDIUM, MEDIUM + 1}) { try {
/** * Check that the value of an PyInteger is suitable for storage in a (Python) byte array, and * convert it to the Java byte value that can be stored there. (Java bytes run -128..127 whereas * Python bytes run 0..255.) * * @param value to convert. * @throws PyException (ValueError) if value<0 or value>255 */ protected static final byte byteCheck(PyInteger value) throws PyException { return byteCheck(value.asInt()); }
@Override public Object __tojava__(Class<?> c) { if (c == Boolean.TYPE || c == Boolean.class || c == Object.class ) { return Boolean.valueOf(getBooleanValue()); } if (c == Integer.TYPE || c == Number.class || c == Integer.class) { return Integer.valueOf(getValue()); } if (c == Byte.TYPE || c == Byte.class) { return Byte.valueOf((byte)(getValue())); } if (c == Short.TYPE || c == Short.class) { return Short.valueOf((short)(getValue())); } if (c == Long.TYPE || c == Long.class) { return Long.valueOf(getValue()); } if (c == Float.TYPE || c == Float.class) { return Float.valueOf(getValue()); } if (c == Double.TYPE || c == Double.class) { return Double.valueOf(getValue()); } return super.__tojava__(c); }
public PyObject __abs__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__abs__"); if (impl!=null) return impl.__get__(this,self_type).__call__(); return super.__abs__(); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___or___doc) final PyObject int___or__(PyObject right) { int rightv; if (right instanceof PyInteger) { rightv = ((PyInteger)right).getValue(); } else if (right instanceof PyLong) { return int___long__().__or__(right); } else { return null; } return Py.newInteger(getValue() | rightv); }
@ExposedMethod(type = MethodType.BINARY, defaults = {"null"}, // doc = BuiltinDocs.int___pow___doc) final PyObject int___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) { return null; } modulo = (modulo == Py.None) ? null : modulo; if (modulo != null && !canCoerce(modulo)) { return null; } return _pow(getValue(), coerce(right), modulo, this, right); }
@Override public int hashCode() { return getPyObject().__hash__().asInt(); } }
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); }
public static final PyInteger newInteger(int i) { if (i >= -100 && i < 900) { return integerCache[i + 100]; } else { return new PyInteger(i); } }