本文整理汇总了Java中org.python.core.PyList类的典型用法代码示例。如果您正苦于以下问题:Java PyList类的具体用法?Java PyList怎么用?Java PyList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PyList类属于org.python.core包,在下文中一共展示了PyList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJavaObject
import org.python.core.PyList; //导入依赖的package包/类
@Override
public Object getJavaObject(Object pyObject) {
if (!(pyObject instanceof PyList))
throw new IllegalArgumentException("pyObject is not instance of PyList");
PyList pyList = (PyList) pyObject;
int count = (pyList.__len__());
ArrayList list = new ArrayList(count);
PyObject obj = null;
PyObjectWrapper wrapper = null;
for (int i = 0; i < count; ++i){
obj = pyList.__getitem__(i);
wrapper = PyObjectWrappersManager.getWrapper(obj.getClass());
list.add(wrapper.getJavaObject(obj));
}
return list;
}
示例2: getNewValue
import org.python.core.PyList; //导入依赖的package包/类
/**
* Accepts Collection<PyObject> as parameter of newValue.
* Returns PyList
*/
@Override
public PyObject getNewValue(Object newValue) {
if (!(newValue instanceof Collection)){
throw new IllegalArgumentException();
}
Collection collection = (Collection)newValue;
PyList list = new PyList();
Iterator iter = collection.iterator();
while (iter.hasNext()){
Object next = iter.next();
if (!(next instanceof PyObject))
throw new IllegalArgumentException("value of the collection is not instance of PyObject");
list.__add__((PyObject) next);
}
return list;
}
示例3: getJavaObject
import org.python.core.PyList; //导入依赖的package包/类
@Override
public Object getJavaObject(Object pyObject) {
if (!(pyObject instanceof PyDictionary))
throw new IllegalArgumentException("pyObject is not instance of PyDictionary");
final PyDictionary pyDict = (PyDictionary)pyObject;
Map map = new HashMap();
PyList keys = pyDict.keys();
int count = keys.__len__();
PyObject pyKey, pyValue;
Object javaKey, javaValue;
for (int i = 0; i < count; ++i){
pyKey = keys.__getitem__(i);
javaKey = PyObjectWrappersManager.getWrapper(pyKey.getClass()).getJavaObject(pyKey);
pyValue = pyDict.__getitem__(pyKey);
javaValue = PyObjectWrappersManager.getWrapper(pyValue.getClass()).getJavaObject(pyValue);
map.put(javaKey, javaValue);
}
return map;
}
示例4: PyObjectWrappersManager
import org.python.core.PyList; //导入依赖的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());
}
示例5: iteratorFromValidModel
import org.python.core.PyList; //导入依赖的package包/类
@Override
public ScanPointIterator iteratorFromValidModel() {
final String xName = model.getFastAxisName();
final String yName = model.getSlowAxisName();
final double width = model.getBoundingBox().getFastAxisLength();
final double height = model.getBoundingBox().getSlowAxisLength();
final JythonObjectFactory<ScanPointIterator> lissajousGeneratorFactory = ScanPointGeneratorFactory.JLissajousGeneratorFactory();
final PyDictionary box = new PyDictionary();
box.put("width", width);
box.put("height", height);
box.put("centre", new double[] {model.getBoundingBox().getFastAxisStart() + width / 2,
model.getBoundingBox().getSlowAxisStart() + height / 2});
final PyList names = new PyList(Arrays.asList(xName, yName));
final PyList units = new PyList(Arrays.asList("mm", "mm"));
final int numLobes = (int) (model.getA() / model.getB());
final int numPoints = model.getPoints();
final ScanPointIterator lissajous = lissajousGeneratorFactory.createObject(
names, units, box, numLobes, numPoints);
final ScanPointIterator pyIterator = CompoundSpgIteratorFactory.createSpgCompoundGenerator(new Iterator[] {lissajous}, getRegions().toArray(),
new String[] {xName, yName}, EMPTY_PY_ARRAY, -1, model.isContinuous());
return new SpgIterator(pyIterator);
}
示例6: iteratorFromValidModel
import org.python.core.PyList; //导入依赖的package包/类
@Override
protected ScanPointIterator iteratorFromValidModel() {
final OneDStepModel model= getModel();
final BoundingLine line = model.getBoundingLine();
final JythonObjectFactory<ScanPointIterator> lineGeneratorFactory = ScanPointGeneratorFactory.JLineGenerator2DFactory();
final int numPoints = (int) Math.floor(line.getLength() / model.getStep()) + 1;
final double xStep = model.getStep() * Math.cos(line.getAngle());
final double yStep = model.getStep() * Math.sin(line.getAngle());
final PyList names = new PyList(Arrays.asList(model.getFastAxisName(), model.getSlowAxisName()));
final PyList units = new PyList(Arrays.asList("mm", "mm"));
final double[] start = {line.getxStart(), line.getyStart()};
final double[] stop = {line.getxStart() + xStep * numPoints, line.getyStart() + yStep * numPoints};
final ScanPointIterator pyIterator = lineGeneratorFactory.createObject(
names, units, start, stop, numPoints);
return new SpgIterator(pyIterator);
}
示例7: iteratorFromValidModel
import org.python.core.PyList; //导入依赖的package包/类
@Override
public ScanPointIterator iteratorFromValidModel() {
final OneDEqualSpacingModel model = getModel();
final BoundingLine line = model.getBoundingLine();
final JythonObjectFactory<ScanPointIterator> lineGeneratorFactory = ScanPointGeneratorFactory.JLineGenerator2DFactory();
final int numPoints = model.getPoints();
final double step = line.getLength() / numPoints;
final double xStep = step * Math.cos(line.getAngle());
final double yStep = step * Math.sin(line.getAngle());
final PyList names = new PyList(Arrays.asList(model.getFastAxisName(), model.getSlowAxisName()));
final PyList units = new PyList(Arrays.asList("mm", "mm"));
final double[] start = {line.getxStart() + xStep/2, line.getyStart() + yStep/2};
final double[] stop = {line.getxStart() + xStep * (numPoints - 0.5), line.getyStart() + yStep * (numPoints - 0.5)};
final ScanPointIterator pyIterator = lineGeneratorFactory.createObject(
names, units, start, stop, numPoints);
return new SpgIterator(pyIterator);
}
示例8: testSimpleToDict
import org.python.core.PyList; //导入依赖的package包/类
@Test
public void testSimpleToDict() throws Exception {
IPointGenerator<StepModel> temp = service.createGenerator(new StepModel("Temperature", 290, 295, 1));
IPointGenerator<?> scan = service.createCompoundGenerator(temp);
Map<?,?> dict = ((PySerializable)scan).toDict();
PyList gens = (PyList) dict.get("generators");
PyDictionary line1 = (PyDictionary) gens.get(0);
assertEquals("Temperature", ((PyList) line1.get("axes")).get(0));
assertEquals("mm", ((PyList) line1.get("units")).get(0));
assertEquals(290.0, (double) ((PyList) line1.get("start")).get(0), 1E-10);
assertEquals(295.0, (double) ((PyList) line1.get("stop")).get(0), 1E-10);
assertEquals(6, (int) line1.get("size"));
PyList excluders = (PyList) dict.get("excluders");
PyList mutators = (PyList) dict.get("mutators");
assertEquals(new PyList(), excluders);
assertEquals(new PyList(), mutators);
}
示例9: completePackageName
import org.python.core.PyList; //导入依赖的package包/类
/**
* Complete package name
*
* @param target Target
* @return Package names
*/
public List<String> completePackageName(String target) {
String[] targetComponents = target.split("\\.");
String base = targetComponents[0];
PySystemState state = interp.getSystemState();
PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__"));
PyObject module = importer.__call__(Py.newString(base));
if (targetComponents.length > 1) {
for (int i = 1; i < targetComponents.length; i++) {
module = module.__getattr__(targetComponents[i]);
}
}
PyList plist = (PyList) module.__dir__();
List<String> list = new ArrayList<>();
String name;
for (int i = 0; i < plist.__len__(); i++) {
name = plist.get(i).toString();
if (!name.startsWith("__")) {
list.add(name);
}
}
//list.add("*");
return list;
}
示例10: getList
import org.python.core.PyList; //导入依赖的package包/类
public static List<Object> getList(ArgParser ap, int position)
/* */ {
/* 169 */ PyObject arg = ap.getPyObject(position, Py.None);
/* 170 */ if (Py.isInstance(arg, PyNone.TYPE)) {
/* 171 */ return Collections.emptyList();
/* */ }
/* */
/* 174 */ List ret = Lists.newArrayList();
/* 175 */ PyList array = (PyList)arg;
/* 176 */ for (int x = 0; x < array.__len__(); x++) {
/* 177 */ PyObject item = array.__getitem__(x);
/* */
/* 179 */ Class javaClass = (Class)PYOBJECT_TO_JAVA_OBJECT_MAP.get(item.getClass());
/* 180 */ if (javaClass != null) {
/* 181 */ ret.add(item.__tojava__(javaClass));
/* */ }
/* */ }
/* 184 */ return ret;
/* */ }
示例11: getMap
import org.python.core.PyList; //导入依赖的package包/类
public static Map<String, Object> getMap(ArgParser ap, int position)
/* */ {
/* 196 */ PyObject arg = ap.getPyObject(position, Py.None);
/* 197 */ if (Py.isInstance(arg, PyNone.TYPE)) {
/* 198 */ return Collections.emptyMap();
/* */ }
/* */
/* 201 */ Map ret = Maps.newHashMap();
/* */
/* 203 */ PyDictionary dict = (PyDictionary)arg;
/* 204 */ PyList items = dict.items();
/* 205 */ for (int x = 0; x < items.__len__(); x++)
/* */ {
/* 207 */ PyTuple item = (PyTuple)items.__getitem__(x);
/* */
/* 209 */ String key = (String)item.__getitem__(0).__str__().__tojava__(String.class);
/* 210 */ PyObject value = item.__getitem__(1);
/* */
/* 213 */ Class javaClass = (Class)PYOBJECT_TO_JAVA_OBJECT_MAP.get(value.getClass());
/* 214 */ if (javaClass != null) {
/* 215 */ ret.put(key, value.__tojava__(javaClass));
/* */ }
/* */ }
/* 218 */ return ret;
/* */ }
示例12: addToPythonPath
import org.python.core.PyList; //导入依赖的package包/类
/** @param path Path to add to head of python search path */
private void addToPythonPath(final String path)
{
// Since using default PySystemState (see above), check if already in paths
final PyList paths = python.getSystemState().path;
// Prevent concurrent modification
synchronized (JythonScriptSupport.class)
{
final int index = paths.indexOf(path);
// Already top entry?
if (index == 0)
return;
// Remove if further down in the list
if (index > 0)
paths.remove(index);
// Add to front of list
paths.add(0, path);
}
logger.log(Level.FINE, "Adding to jython path: {0}", path);
}
示例13: flatMap
import org.python.core.PyList; //导入依赖的package包/类
private void flatMap(IndexedRecord input, ProcessContext context) throws IOException {
// Prepare Python environment
interpretor.set("inputJSON", new PyString(input.toString()));
// Add user command
interpretor.exec(pythonFunction);
// Retrieve results
interpretor.exec("outputJSON = userFunction(inputJSON)");
PyObject outputList = interpretor.get("outputJSON");
if (outputList instanceof PyList) {
PyList list = (PyList) outputList;
for (Object output : list) {
if (jsonGenericRecordConverter == null) {
JsonSchemaInferrer jsonSchemaInferrer = new JsonSchemaInferrer(new ObjectMapper());
Schema jsonSchema = jsonSchemaInferrer.inferSchema(output.toString());
jsonGenericRecordConverter = new JsonGenericRecordConverter(jsonSchema);
}
GenericRecord outputRecord = jsonGenericRecordConverter.convertToAvro(output.toString());
context.output(outputRecord);
}
}
}
示例14: pigToPython
import org.python.core.PyList; //导入依赖的package包/类
public static PyObject pigToPython(Object object) {
if (object instanceof Tuple) {
return pigTupleToPyTuple((Tuple) object);
} else if (object instanceof DataBag) {
PyList list = new PyList();
for (Tuple bagTuple : (DataBag) object) {
list.add(pigTupleToPyTuple(bagTuple));
}
return list;
} else if (object instanceof Map<?, ?>) {
PyDictionary newMap = new PyDictionary();
for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
newMap.put(entry.getKey(), pigToPython(entry.getValue()));
}
return newMap;
} else if (object instanceof DataByteArray) {
return Py.java2py(((DataByteArray) object).get());
} else {
return Py.java2py(object);
}
}
示例15: runCxxTestGen
import org.python.core.PyList; //导入依赖的package包/类
private void runCxxTestGen( String testTarget, List<String> arguments ) throws MojoExecutionException
{
final String cxxTestGenArgVar = "cxxTestGenArgs";
String cxxTestGenPath = cxxTest.getCxxTestHome().getAbsolutePath();
PyList cxxTestGenArgs = new PyList( arguments );
cxxTestGenArgs.add( 0, cxxTestGenPath );
getLog().info( "Executing test runner generation for target " + testTarget + "." );
getLog().debug( "Executing Python script " + cxxTestGenPath + " with arguments=" + cxxTestGenArgs );
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec( "import cxxtest" );
resetCxxTestSuites( pythonInterpreter );
pythonInterpreter.set( cxxTestGenArgVar, cxxTestGenArgs );
pythonInterpreter.exec( "cxxtest.main(" + cxxTestGenArgVar + ")" );
pythonInterpreter.cleanup();
getLog().info( "Test runner generation for target " + testTarget + " succeeded." );
}