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


Java PyLong类代码示例

本文整理汇总了Java中org.python.core.PyLong的典型用法代码示例。如果您正苦于以下问题:Java PyLong类的具体用法?Java PyLong怎么用?Java PyLong使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PyLong类属于org.python.core包,在下文中一共展示了PyLong类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PyObjectWrappersManager

import org.python.core.PyLong; //导入依赖的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.PyLong; //导入依赖的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.PyLong; //导入依赖的package包/类
/**
 * Returns Long instance of the stored value.
 */
@Override
public Object getJavaObject(Object pyObject) {
	if (pyObject instanceof Long) return new Long((Long) pyObject);
	if (pyObject instanceof BigInteger) return ((BigInteger) pyObject).longValue();
	if (pyObject instanceof PyLong){
		PyLong pyLong = (PyLong) pyObject;
		return pyLong.__tojava__(Long.class);
	}
	throw new IllegalArgumentException("pyObject is instance neither of Long nor BigInteger nor PyLong");
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:14,代码来源:PyLongWrapper.java

示例4: getNewValue

import org.python.core.PyLong; //导入依赖的package包/类
/**
 * Returns PyLong instance of the value newValue.
 * NewValue must be of the type Long, otherwise
 * the IllegalCastException will occure.
 */
@Override
public PyObject getNewValue(Object newValue) {
	if (newValue instanceof Long) return new PyLong((Long) newValue);
	if (newValue instanceof Integer) return new PyLong((Integer) newValue);
	if (newValue instanceof BigInteger) return new PyLong(((BigInteger) newValue).longValue());
	throw new IllegalArgumentException("newValue is neither instance of Long nor BigInteger nor Integer");
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:13,代码来源:PyLongWrapper.java

示例5: toPy

import org.python.core.PyLong; //导入依赖的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

示例6: jython

import org.python.core.PyLong; //导入依赖的package包/类
@Benchmark
public Object jython(JythonState jythonState, DataState dataState) throws Throwable {
  if (jythonState.data == null) {
    PyArray array = new PyArray(Long.class, dataState.data.size());
    for (int i = 0; i < dataState.data.size(); i++) {
      array.set(i, new PyLong(dataState.data.get(i)));
    }
    jythonState.data = array;
  }
  return jythonState.run.__call__(jythonState.data);
}
 
开发者ID:golo-lang,项目名称:golo-jmh-benchmarks,代码行数:12,代码来源:FilterMapReduceMicroBenchmark.java

示例7: createExternalTypeFromStringWithPythonException

import org.python.core.PyLong; //导入依赖的package包/类
public BaseExternalType createExternalTypeFromStringWithPythonException(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) throws PythonException {
	String script = customScript.getScript();
	if (script == null) {
		return null;
	}

	CustomScriptType customScriptType = customScript.getScriptType();
	BaseExternalType externalType = null;

	InputStream bis = null;
	try {
           bis = new ByteArrayInputStream(script.getBytes("UTF-8"));
           externalType = pythonService.loadPythonScript(bis, customScriptType.getPythonClass(),
           		customScriptType.getCustomScriptType(), new PyObject[] { new PyLong(System.currentTimeMillis()) });
	} catch (UnsupportedEncodingException e) {
           log.error(e.getMessage(), e);
       } finally {
		IOUtils.closeQuietly(bis);
	}

	if (externalType == null) {
		return null;
	}

	boolean initialized = false;
	try {
		initialized = externalType.init(configurationAttributes);
	} catch (Exception ex) {
           log.error("Failed to initialize custom script: '{}'", ex, customScript.getName());
	}

	if (initialized) {
		return externalType;
	}
	
	return null;
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:38,代码来源:CustomScriptManager.java

示例8: jython_30

import org.python.core.PyLong; //导入依赖的package包/类
@Benchmark
public Object jython_30(State30 state30, JythonState jythonState) throws Throwable {
  return jythonState.fib.__call__(new PyLong(state30.n));
}
 
开发者ID:golo-lang,项目名称:golo-jmh-benchmarks,代码行数:5,代码来源:FibonacciMicroBenchmark.java

示例9: jython_40

import org.python.core.PyLong; //导入依赖的package包/类
public Object jython_40(State40 state40, JythonState jythonState) throws Throwable {
  return jythonState.fib.__call__(new PyLong(state40.n));
}
 
开发者ID:golo-lang,项目名称:golo-jmh-benchmarks,代码行数:4,代码来源:FibonacciMicroBenchmark.java

示例10: pythonToPig

import org.python.core.PyLong; //导入依赖的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

示例11: pythonToPig

import org.python.core.PyLong; //导入依赖的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

示例12: getLong

import org.python.core.PyLong; //导入依赖的package包/类
/**
 * Get PyLong as long
 *
 * @return PyLong
 */
public PyLong getLong() {
  return new PyLong(column.getLong());
}
 
开发者ID:renato2099,项目名称:giraph-gora,代码行数:9,代码来源:JythonReadableColumn.java


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