本文整理汇总了Java中org.python.core.PyInteger类的典型用法代码示例。如果您正苦于以下问题:Java PyInteger类的具体用法?Java PyInteger怎么用?Java PyInteger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PyInteger类属于org.python.core包,在下文中一共展示了PyInteger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PyObjectWrappersManager
import org.python.core.PyInteger; //导入依赖的package包/类
protected PyObjectWrappersManager(){
PyObjectWrappersManager.wrappers.put(PyInteger.class, new PyIntegerWrapper());
PyObjectWrappersManager.wrappers.put(Integer.class, new PyIntegerWrapper());
PyObjectWrappersManager.wrappers.put(PyFloat.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(Float.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(Double.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(PyLong.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(Long.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(BigInteger.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(PyString.class, new PyStringWrapper());
PyObjectWrappersManager.wrappers.put(String.class, new PyStringWrapper());
PyObjectWrappersManager.wrappers.put(PyList.class, new PyListWrapper());
PyObjectWrappersManager.wrappers.put(PyDictionary.class, new PyDictionaryWrapper());
PyObjectWrappersManager.wrappers.put(PyTuple.class, new PyTupleWrapper());
PyObjectWrappersManager.wrappers.put(PyInstance.class, new PyInstanceWrapper());
}
示例2: getAttribute
import org.python.core.PyInteger; //导入依赖的package包/类
@Override
public Object getAttribute( Object inst, String name ) throws ScriptException
{
try {
this.interpreter.set("__inst", inst);
Object result = this.interpreter.eval("__inst." + name);
if (result instanceof PyBoolean) {
return ((PyBoolean) result).getBooleanValue();
}
if (result instanceof PyInteger) {
return ((PyInteger) result).getValue();
} else if (result instanceof PyString) {
return ((PyString) result).toString();
} else if (result instanceof PyFloat) {
return ((PyFloat) result).getValue();
} else if (result instanceof PyLong) {
return ((PyLong) result).getValue();
} else if (result instanceof PyNone) {
return null;
}
return result;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
示例3: getJavaObject
import org.python.core.PyInteger; //导入依赖的package包/类
/**
* Returns Integer instance of the stored value.
*/
@Override
public Object getJavaObject(Object pyObject) {
if (pyObject instanceof Integer) return new Integer((Integer)pyObject);
if (pyObject instanceof PyInteger) {
PyInteger pyInteger = (PyInteger) pyObject;
return pyInteger.__tojava__(Integer.class);
}
throw new IllegalArgumentException("pyObject is instance neither of Integer nor PyInteger");
}
示例4: isatty
import org.python.core.PyInteger; //导入依赖的package包/类
public static boolean isatty(PyObject fdObj) {
if (fdObj instanceof PyInteger) {
FileDescriptor fd;
switch (fdObj.asInt()) {
case 0:
fd = FileDescriptor.in;
break;
case 1:
fd = FileDescriptor.out;
break;
case 2:
fd = FileDescriptor.err;
break;
default:
throw Py.NotImplementedError("Integer file descriptor compatibility only "
+ "available for stdin, stdout and stderr (0-2)");
}
return posix.isatty(fd);
}
Object tojava = fdObj.__tojava__(FileDescriptor.class);
if (tojava != Py.NoConversion) {
return posix.isatty((FileDescriptor)tojava);
}
tojava = fdObj.__tojava__(IOBase.class);
if (tojava == Py.NoConversion) {
throw Py.TypeError("a file descriptor is required");
}
return ((IOBase)tojava).isatty();
}
示例5: toPy
import org.python.core.PyInteger; //导入依赖的package包/类
@SuppressWarnings("unchecked")
PyObject toPy(Object o) {
if(o instanceof List) {
Iterator<PyObject> converter = ((List<Object>) o).stream()
.map(this::toPy)
.iterator();
return new PyList(converter);
} else if(o instanceof Map) {
PyDictionary dictionary = new PyDictionary();
((Map<Object, Object>) o).entrySet().stream()
.map(v -> new AbstractMap.SimpleEntry<>(toPy(v.getKey()), toPy(v.getValue())))
.forEach(v -> dictionary.put(v.getKey(), v.getValue()));
return dictionary;
} else if(o instanceof Integer) {
return new PyInteger((int) o);
} else if(o instanceof Long) {
return new PyLong((long) o);
} else if(o instanceof Float) {
return new PyFloat((float) o);
} else if(o instanceof Double) {
return new PyFloat((double) o);
} else if(o instanceof Boolean) {
return new PyBoolean((boolean) o);
} else if(o instanceof Character) {
return new PyString((char) o);
} else if(o instanceof String) {
return new PyString((String) o);
} else {
return null;
}
}
示例6: testJavaOperator
import org.python.core.PyInteger; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testJavaOperator()
{
PythonOperator oper = new PythonOperator();
String setupScript = "import operator\n";
setupScript += "def square():\n";
setupScript += " return val*val\n\n";
oper.addSetupScript(setupScript);
oper.setScript("square()");
oper.setPassThru(true);
CollectorTestSink sink = new CollectorTestSink();
oper.result.setSink(sink);
HashMap<String, Object> tuple = new HashMap<String, Object>();
tuple.put("val", new Integer(2));
oper.setup(null);
oper.beginWindow(0);
oper.inBindings.process(tuple);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, sink.collectedTuples.size());
for (Object o : sink.collectedTuples) {
PyInteger val = (PyInteger)o;
Assert.assertEquals("emitted should be 4", new Integer(4),
(Integer)val.__tojava__(Integer.class));
}
}
示例7: getFloat
import org.python.core.PyInteger; //导入依赖的package包/类
public static double getFloat(ArgParser ap, int position)
/* */ {
/* 129 */ PyObject arg = ap.getPyObject(position);
/* */
/* 131 */ if (Py.isInstance(arg, PyFloat.TYPE)) {
/* 132 */ return ((PyFloat)arg).asDouble();
/* */ }
/* 134 */ if (Py.isInstance(arg, PyInteger.TYPE)) {
/* 135 */ return ((PyInteger)arg).asDouble();
/* */ }
/* 137 */ throw Py.TypeError("Unable to parse argument: " + position);
/* */ }
示例8: convertObject
import org.python.core.PyInteger; //导入依赖的package包/类
private static PyObject convertObject(Object o) {
/* 222 */ if ((o instanceof String))
/* 223 */ return new PyString((String)o);
/* 224 */ if ((o instanceof Double))
/* 225 */ return new PyFloat(((Double)o).doubleValue());
/* 226 */ if ((o instanceof Integer))
/* 227 */ return new PyInteger(((Integer)o).intValue());
/* 228 */ if ((o instanceof Float)) {
/* 229 */ float f = ((Float)o).floatValue();
/* 230 */ return new PyFloat(f);
/* */ }
/* 232 */ return Py.None;
/* */ }
示例9: convertSupportedValues
import org.python.core.PyInteger; //导入依赖的package包/类
private Object convertSupportedValues(PyObject object) {
if (object instanceof PyBoolean) {
return ((PyBoolean) object).getBooleanValue();
} else if (object instanceof PyInteger) {
return ((PyInteger) object).getValue();
} else {
return object;
}
}
示例10: getInt
import org.python.core.PyInteger; //导入依赖的package包/类
/**
* Get PyInteger from a byte, short, or integer column
*
* @return PyInteger
*/
public PyInteger getInt() {
int value;
if (column.hiveType() == HiveType.BYTE) {
value = column.getByte();
} else if (column.hiveType() == HiveType.SHORT) {
value = column.getShort();
} else if (column.hiveType() == HiveType.LONG) {
value = column.getInt();
} else {
throw new IllegalArgumentException(
"Column is not a byte/short/int, is " + column.hiveType());
}
return new PyInteger(value);
}
示例11: getNewValue
import org.python.core.PyInteger; //导入依赖的package包/类
/**
* Returns PyInteger instance of the value newValue.
* NewValue must be of the type Integer, otherwise
* the IllegalCastException will occure.
*/
@Override
public PyObject getNewValue(Object newValue) {
if (newValue instanceof Integer) return new PyInteger((Integer) newValue);
throw new IllegalArgumentException("newValue is not instance of Integer");
}
示例12: convertToSlice
import org.python.core.PyInteger; //导入依赖的package包/类
/**
* @param pyslice
* @return slice
*/
public static Slice convertToSlice(PySlice pyslice) {
return new Slice(pyslice.start instanceof PyNone ? null : ((PyInteger) pyslice.start).getValue(),
pyslice.stop instanceof PyNone ? null : ((PyInteger) pyslice.stop).getValue(),
pyslice.step instanceof PyNone ? null : ((PyInteger) pyslice.step).getValue());
}
示例13: remove
import org.python.core.PyInteger; //导入依赖的package包/类
@Override
public void remove(int index) {
pyObject.__delitem__(new PyInteger(index));
}
示例14: tap
import org.python.core.PyInteger; //导入依赖的package包/类
public void tap(int x, int y) {
_device.touch(new PyObject[] { new PyInteger(x), new PyInteger(y), new PyString("DOWN_AND_UP")}, null);
}
示例15: longPress
import org.python.core.PyInteger; //导入依赖的package包/类
public void longPress(int x, int y) {
PyTuple point = new PyTuple(new PyInteger(x), new PyInteger(y));
_device.drag(new PyObject[] { point, point, new PyInteger(2), new PyInteger(2) }, null);
}