本文整理汇总了Java中org.python.core.PyList.__len__方法的典型用法代码示例。如果您正苦于以下问题:Java PyList.__len__方法的具体用法?Java PyList.__len__怎么用?Java PyList.__len__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.PyList
的用法示例。
在下文中一共展示了PyList.__len__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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;
}
示例4: 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;
/* */ }
示例5: 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;
/* */ }
示例6: getChildren
import org.python.core.PyList; //导入方法依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyList))
throw new IllegalArgumentException("object is not instance of PyList");
final PyList pyList = (PyList) object;
int count = (pyList.__len__());
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
PyObject obj;
for (int i = 0; i < count; ++i){
final int place = i;
obj = pyList.__finditem__(place);
list.add(
new PyObjectAdapter(
String.valueOf(place),
new PyObjectPlace(){
private int myPlace = place;
@Override
public void set(PyObject newValue) {
pyList.__setitem__(myPlace, newValue);
}
@Override
public PyObject get(){
try{
return pyList.__finditem__(myPlace);
} catch (Exception e){
return null;
}
}
}
)
);
}
return list;
}
示例7: getChildren
import org.python.core.PyList; //导入方法依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyDictionary))
throw new IllegalArgumentException("object is not instance of PyDictionary");
final PyDictionary pyDict = (PyDictionary)object;
PyList pyList = pyDict.keys();
int count = pyList.__len__();
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
PyObject obj;
for (int i = 0; i < count; ++i){
final PyObject pyKey = pyList.__getitem__(i);
Object name = pyKey.__tojava__(String.class);
if ((name == Py.NoConversion) || (!(name instanceof String))) continue;
obj = pyDict.__finditem__(pyKey);
list.add(
new PyObjectAdapter(
(String)name,
new PyObjectPlace(){
private PyObject myPlace = pyKey;
@Override
public void set(PyObject newValue) {
pyDict.__setitem__(myPlace, newValue);
}
@Override
public PyObject get(){
try{
return pyDict.__finditem__(myPlace);
} catch (Exception e){
return null;
}
}
}
)
);
}
return list;
}
示例8: getAutoCompleteList
import org.python.core.PyList; //导入方法依赖的package包/类
/**
* Get auto complete list
*
* @param command The command
* @param includeMagic
* @param includeSingle
* @param includeDouble
* @return Auto complete list
* @throws java.io.IOException
*/
public List<String> getAutoCompleteList(String command, boolean includeMagic,
boolean includeSingle, boolean includeDouble) throws IOException {
// Temp KLUDGE here rather than in console.py
//command += ".";
if (command.startsWith("import ") || command.startsWith("from ")) {
String target = getPackageName(command);
if (target == null) {
return null;
}
return completePackageName(target);
}
String root = this.getRoot(command, ".");
if (root.isEmpty())
return null;
try {
PyObject object = this.interp.eval(root);
PyList plist = (PyList) object.__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);
}
}
return list;
} catch (Exception e){
return null;
}
}
示例9: getChildren
import org.python.core.PyList; //导入方法依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyInstance))
throw new IllegalArgumentException("object is not instance of PyInstance");
PyInstance pyInstance = (PyInstance)object;
PyList keys = null;
if (pyInstance.__dict__ instanceof PyDictionary)
keys = ((PyDictionary)pyInstance.__dict__).keys();
if (pyInstance.__dict__ instanceof PyStringMap)
keys = ((PyStringMap)pyInstance.__dict__).keys();
if (keys == null)
return null;
final PyObject pyDict = pyInstance.__dict__;
int count = keys.__len__();
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
PyObject obj;
for (int i = 0; i < count; ++i){
final PyObject key = keys.__getitem__(i);
Object name = (String)key.__tojava__(String.class);
if ((name == Py.NoConversion) || (!(name instanceof String))) continue;
obj = pyDict.__finditem__(key);
list.add(
new PyObjectAdapter(
(String)name,
new PyObjectPlace(){
private PyObject myPlace = key;
@Override
public void set(PyObject newValue) {
pyDict.__setitem__(myPlace, newValue);
}
@Override
public PyObject get(){
try{
return pyDict.__finditem__(myPlace);
} catch (Exception e){
return null;
}
}
}
)
);
}
return list;
}