本文整理汇总了Java中org.python.core.PyFloat类的典型用法代码示例。如果您正苦于以下问题:Java PyFloat类的具体用法?Java PyFloat怎么用?Java PyFloat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PyFloat类属于org.python.core包,在下文中一共展示了PyFloat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PyObjectWrappersManager
import org.python.core.PyFloat; //导入依赖的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.PyFloat; //导入依赖的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.PyFloat; //导入依赖的package包/类
/**
* Returns Double instance of the stored value.
*/
@Override
public Object getJavaObject(Object pyObject) {
if (pyObject instanceof Float) return new Double((Float)pyObject);
if (pyObject instanceof Double) return new Double((Double)pyObject);
if (pyObject instanceof PyFloat){
PyFloat pyFloat = (PyFloat)pyObject;
return pyFloat.__tojava__(Double.class);
}
throw new IllegalArgumentException("pyObject is instance neither of Float, nor Double, not PyFloat");
}
示例4: getNewValue
import org.python.core.PyFloat; //导入依赖的package包/类
/**
* Returns PyFloat instance of the value newValue.
* NewValue must be of the type Double, otherwise
* the IllegalCastException will occure.
*/
@Override
public PyObject getNewValue(Object newValue) {
if (newValue instanceof Double) return new PyFloat((Double) newValue);
if (newValue instanceof Float) return new PyFloat((Float) newValue);
if (newValue instanceof Integer) return new PyFloat(new Float((Integer) newValue));
throw new IllegalArgumentException("newValue is instance neither of Double nor Float");
}
示例5: extractTimeval
import org.python.core.PyFloat; //导入依赖的package包/类
/**
* Convert seconds (with a possible fraction) from epoch to a 2 item array of seconds,
* microseconds from epoch as longs.
*
* @param seconds a PyObject number
* @return a 2 item long[]
*/
private static long[] extractTimeval(PyObject seconds) {
long[] timeval = new long[] {Platform.IS_32_BIT ? seconds.asInt() : seconds.asLong(), 0L};
if (seconds instanceof PyFloat) {
// can't exceed 1000000
long usec = (long)((seconds.asDouble() % 1.0) * 1e6);
if (usec < 0) {
// If rounding gave us a negative number, truncate
usec = 0;
}
timeval[1] = usec;
}
return timeval;
}
示例6: toPy
import org.python.core.PyFloat; //导入依赖的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;
}
}
示例7: asInt
import org.python.core.PyFloat; //导入依赖的package包/类
private int asInt(PyObject value) {
if(value instanceof PyFloat) {
Py.warning(Py.DeprecationWarning, "integer argument expected, got float");
value = value.__int__();
}
return value.asInt();
}
示例8: getFloat
import org.python.core.PyFloat; //导入依赖的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);
/* */ }
示例9: convertObject
import org.python.core.PyFloat; //导入依赖的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;
/* */ }
示例10: AndroidScreen
import org.python.core.PyFloat; //导入依赖的package包/类
public AndroidScreen(String serialNumber) throws AWTException {
MonkeyDevice device = MonkeyRunner.waitForConnection(new PyObject[] { new PyFloat(15), new PyString(serialNumber) }, null);
try { // waitForConnection() never returns null, even the connection cannot be created.
String model = device.getProperty(new PyObject[] {new PyString("build.model")}, null);
Debug.history("Successfully connect to a device. MODEL: " + model);
} catch (Throwable e) {
throw new RuntimeException("Failed to connect to a device (within timeout).", e);
}
_robot = new AndroidRobot(device);
// Region's default constructor doesn't use this screen as the default one.
Rectangle bounds = getBounds();
super.init(bounds.x, bounds.y, bounds.width, bounds.height, this);
}
示例11: getFloat
import org.python.core.PyFloat; //导入依赖的package包/类
/**
* Get double or float column as PyFloat
*
* @return PyFloat
*/
public PyFloat getFloat() {
double value;
if (column.hiveType() == HiveType.FLOAT) {
value = column.getFloat();
} else if (column.hiveType() == HiveType.DOUBLE) {
value = column.getDouble();
} else {
throw new IllegalArgumentException("Column is not a float/double, is " +
column.hiveType());
}
return new PyFloat(value);
}
示例12: pythonToPig
import org.python.core.PyFloat; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Object pythonToPig(PyObject pyObject) throws ExecException {
try {
Object javaObj = null;
// Add code for all supported pig types here
// Tuple, bag, map, int, long, float, double, chararray, bytearray
if (pyObject instanceof PyTuple) {
PyTuple pyTuple = (PyTuple) pyObject;
Object[] tuple = new Object[pyTuple.size()];
int i = 0;
for (PyObject tupleObject : pyTuple.getArray()) {
tuple[i++] = pythonToPig(tupleObject);
}
javaObj = tupleFactory.newTuple(Arrays.asList(tuple));
} else if (pyObject instanceof PyList) {
DataBag list = bagFactory.newDefaultBag();
for (PyObject bagTuple : ((PyList) pyObject).asIterable()) {
// If the item of the array is not a tuple,
// wrap it into tuple before adding to bag
Object pigBagItem = pythonToPig(bagTuple);
Tuple pigBagTuple;
if (!(pigBagItem instanceof Tuple)) {
pigBagTuple = TupleFactory.getInstance().newTuple(1);
pigBagTuple.set(0, pigBagItem);
} else {
pigBagTuple = (Tuple)pigBagItem;
}
list.add(pigBagTuple);
}
javaObj = list;
} else if (pyObject instanceof PyDictionary) {
Map<?, Object> map = Py.tojava(pyObject, Map.class);
Map<Object, Object> newMap = new HashMap<Object, Object>();
for (Map.Entry<?, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof PyObject) {
newMap.put(entry.getKey(), pythonToPig((PyObject) entry.getValue()));
} else {
// Jython sometimes uses directly the java class: for example for integers
newMap.put(entry.getKey(), entry.getValue());
}
}
javaObj = newMap;
} else if (pyObject instanceof PyLong) {
javaObj = pyObject.__tojava__(Long.class);
} else if (pyObject instanceof PyBoolean) {
javaObj = pyObject.__tojava__(Boolean.class);
} else if (pyObject instanceof PyInteger) {
javaObj = pyObject.__tojava__(Integer.class);
} else if (pyObject instanceof PyFloat) {
// J(P)ython is loosely typed, supports only float type,
// hence we convert everything to double to save precision
javaObj = pyObject.__tojava__(Double.class);
} else if (pyObject instanceof PyString) {
javaObj = pyObject.__tojava__(String.class);
} else if (pyObject instanceof PyNone) {
return null;
} else {
javaObj = pyObject.__tojava__(byte[].class);
// if we successfully converted to byte[]
if(javaObj instanceof byte[]) {
javaObj = new DataByteArray((byte[])javaObj);
}
else {
throw new ExecException("Non supported pig datatype found, cast failed: "+(pyObject==null?null:pyObject.getClass().getName()));
}
}
if(javaObj.equals(Py.NoConversion)) {
throw new ExecException("Cannot cast into any pig supported type: "+(pyObject==null?null:pyObject.getClass().getName()));
}
return javaObj;
} catch (Exception e) {
throw new ExecException("Cannot convert jython type ("+(pyObject==null?null:pyObject.getClass().getName())+") to pig datatype "+ e, e);
}
}
示例13: pythonToPig
import org.python.core.PyFloat; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Object pythonToPig(PyObject pyObject) throws ExecException {
try {
Object javaObj = null;
// Add code for all supported pig types here
// Tuple, bag, map, int, long, float, double, chararray, bytearray
if (pyObject instanceof PyTuple) {
PyTuple pyTuple = (PyTuple) pyObject;
Object[] tuple = new Object[pyTuple.size()];
int i = 0;
for (PyObject tupleObject : pyTuple.getArray()) {
tuple[i++] = pythonToPig(tupleObject);
}
javaObj = tupleFactory.newTuple(Arrays.asList(tuple));
} else if (pyObject instanceof PyList) {
DataBag list = bagFactory.newDefaultBag();
for (PyObject bagTuple : ((PyList) pyObject).asIterable()) {
// In jython, list need not be a bag of tuples, as it is in case of pig
// So we fail with cast exception if we dont find tuples inside bag
// This is consistent with java udf (bag should be filled with tuples)
list.add((Tuple) pythonToPig(bagTuple));
}
javaObj = list;
} else if (pyObject instanceof PyDictionary) {
Map<?, Object> map = Py.tojava(pyObject, Map.class);
Map<Object, Object> newMap = new HashMap<Object, Object>();
for (Map.Entry<?, Object> entry : map.entrySet()) {
if (entry.getValue() instanceof PyObject) {
newMap.put(entry.getKey(), pythonToPig((PyObject) entry.getValue()));
} else {
// Jython sometimes uses directly the java class: for example for integers
newMap.put(entry.getKey(), entry.getValue());
}
}
javaObj = newMap;
} else if (pyObject instanceof PyLong) {
javaObj = pyObject.__tojava__(Long.class);
} else if (pyObject instanceof PyInteger) {
javaObj = pyObject.__tojava__(Integer.class);
} else if (pyObject instanceof PyFloat) {
// J(P)ython is loosely typed, supports only float type,
// hence we convert everything to double to save precision
javaObj = pyObject.__tojava__(Double.class);
} else if (pyObject instanceof PyString) {
javaObj = pyObject.__tojava__(String.class);
} else if (pyObject instanceof PyNone) {
return null;
} else {
javaObj = pyObject.__tojava__(byte[].class);
// if we successfully converted to byte[]
if(javaObj instanceof byte[]) {
javaObj = new DataByteArray((byte[])javaObj);
}
else {
throw new ExecException("Non supported pig datatype found, cast failed: "+(pyObject==null?null:pyObject.getClass().getName()));
}
}
if(javaObj.equals(Py.NoConversion)) {
throw new ExecException("Cannot cast into any pig supported type: "+(pyObject==null?null:pyObject.getClass().getName()));
}
return javaObj;
} catch (Exception e) {
throw new ExecException("Cannot convert jython type ("+(pyObject==null?null:pyObject.getClass().getName())+") to pig datatype "+ e, e);
}
}
示例14: getDouble
import org.python.core.PyFloat; //导入依赖的package包/类
/**
* Get PyFloat from a double or float column
*
* @return PyFloat
*/
public PyFloat getDouble() {
return getFloat();
}
示例15: float2py
import org.python.core.PyFloat; //导入依赖的package包/类
public static PyFloat float2py(final float f) { return new PyFloat(f); }