当前位置: 首页>>代码示例>>Java>>正文


Java PyFloat类代码示例

本文整理汇总了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());
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:17,代码来源:PyObjectWrappersManager.java

示例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;
    }
}
 
开发者ID:nickthecoder,项目名称:itchy,代码行数:27,代码来源:PythonLanguage.java

示例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");
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:14,代码来源:PyFloatWrapper.java

示例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");
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:13,代码来源:PyFloatWrapper.java

示例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;
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:21,代码来源:PosixModule.java

示例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;
	}
}
 
开发者ID:nerdclub-tfg,项目名称:signal-bot-jython,代码行数:32,代码来源:Storage.java

示例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();
}
 
开发者ID:r1chardj0n3s,项目名称:pycode-minecraft,代码行数:9,代码来源:ArgParser.java

示例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);
/*     */   }
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:13,代码来源:JythonUtils.java

示例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;
/*     */   }
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:14,代码来源:JythonUtils.java

示例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);
}
 
开发者ID:imsardine,项目名称:sikuli-monkey,代码行数:16,代码来源:AndroidScreen.java

示例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);
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:18,代码来源:JythonReadableColumn.java

示例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);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:75,代码来源:JythonUtils.java

示例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);
    }
}
 
开发者ID:PonIC,项目名称:PonIC,代码行数:66,代码来源:JythonUtils.java

示例14: getDouble

import org.python.core.PyFloat; //导入依赖的package包/类
/**
 * Get PyFloat from a double or float column
 *
 * @return PyFloat
 */
public PyFloat getDouble() {
  return getFloat();
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:9,代码来源:JythonReadableColumn.java

示例15: float2py

import org.python.core.PyFloat; //导入依赖的package包/类
public static PyFloat float2py(final float f)    { return new PyFloat(f);   } 
开发者ID:MitchWeaver,项目名称:sjgs,代码行数:2,代码来源:PyUtils.java


注:本文中的org.python.core.PyFloat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。