本文整理汇总了Java中org.python.core.PyDictionary类的典型用法代码示例。如果您正苦于以下问题:Java PyDictionary类的具体用法?Java PyDictionary怎么用?Java PyDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PyDictionary类属于org.python.core包,在下文中一共展示了PyDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configFromProperties
import org.python.core.PyDictionary; //导入依赖的package包/类
/**
* Copy all properties into jython envirenment
* @param appId
* @param whExecId
* @param properties
* @return PySystemState A PySystemState that contain all the arguments.
*/
private PySystemState configFromProperties(Integer appId, Integer dbId, Long whExecId, Properties properties) {
this.prop = properties;
if (appId != null)
prop.setProperty(Constant.APP_ID_KEY, String.valueOf(appId));
if (dbId != null)
prop.setProperty(Constant.DB_ID_KEY, String.valueOf(dbId));
prop.setProperty(Constant.WH_EXEC_ID_KEY, String.valueOf(whExecId));
PyDictionary config = new PyDictionary();
for (String key : prop.stringPropertyNames()) {
String value = prop.getProperty(key);
config.put(new PyString(key), new PyString(value));
}
PySystemState sys = new PySystemState();
sys.argv.append(config);
return sys;
}
示例2: getJavaObject
import org.python.core.PyDictionary; //导入依赖的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: getNewValue
import org.python.core.PyDictionary; //导入依赖的package包/类
/**
* Accepts Map<String, PyObject> as newValue.
*/
@Override
public PyObject getNewValue(Object newValue) {
if (!(newValue instanceof Map)){
throw new IllegalArgumentException("newValue not of type Map");
}
Map map = (Map)newValue;
Set set = map.keySet();
Iterator iter = set.iterator();
PyDictionary dict = new PyDictionary();
while (iter.hasNext()) {
Object next = iter.next();
if (!(next instanceof String))
throw new IllegalArgumentException("Key of the map is not string.");
String key = (String)next;
if (!(map.get(key) instanceof PyObject))
throw new IllegalArgumentException("Value of the item of the map is not PyObject.");
dict.__setitem__(new PyString(key), (PyObject) map.get(key));
}
return dict;
}
示例4: PyObjectWrappersManager
import org.python.core.PyDictionary; //导入依赖的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.PyDictionary; //导入依赖的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: testSimpleToDict
import org.python.core.PyDictionary; //导入依赖的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);
}
示例7: createStudentInfoDict
import org.python.core.PyDictionary; //导入依赖的package包/类
/**
* Creates a PyDictionary about infos about the student. The infos and their
* stored keys
* first_name: FirstName of the student
* last_name: LastName of the student
* email: email of the student
* matriculation: Matriculation number of the student.
* part_type: participation type of the student.
* @param student The student which infos should be put in the py Dict.
* @return The PyDict with student infos.
*/
private PyDictionary createStudentInfoDict(Student student) {
log.debug("createStudentInfoDict called with student " + student.getUser());
PyDictionary studentDict = new PyDictionary();
studentDict.put(new PyString(KEY_STUDENT_INFO_MATR),
student.getUser().getMatriculationNumber() == null
? new PyString("")
: new PyString(student.getUser().getMatriculationNumber()));
studentDict.put(new PyString(KEY_STUDENT_INFO_FIRST_NAME),
new PyString(student.getUser().getFirstName()));
studentDict.put(new PyString(KEY_STUDENT_INFO_LAST_NAME),
new PyString(student.getUser().getLastName()));
studentDict.put(new PyString(KEY_STUDENT_INFO_EMAIL),
new PyString(student.getUser().getEmail()));
studentDict.put(new PyString(KEY_STUDENT_INFO_PART_TYPE),
new PyString(student.getParticipationType().getName()));
return studentDict;
}
示例8: createOtherStudentGradesDict
import org.python.core.PyDictionary; //导入依赖的package包/类
/**
* Creates a python dictionary of the other student relations of a student
* in which the currently logged in user is lecturer.
* The dictionary has as the first index the semester in which the courses were
* located, which points to a dictionary of courses during this semester.
* This dictionary uses the shortcut of a course to get a grade dictionary
* of the student in that course.
* @param otherStudentRelations The other student relations which should create
* the Python Dictionary
* @return The python dictionary with other grades indexed by semester
* and course shortcut.
*/
private PyDictionary createOtherStudentGradesDict(List<Student> otherStudentRelations) {
List<Semester> semesters = new ArrayList<>();
PyDictionary semesterDict = new PyDictionary();
for (Student otherStudent: otherStudentRelations) {
Semester semester = otherStudent.getCourse().getSemester();
if (!semesters.contains(semester)) {
semesters.add(otherStudent.getCourse().getSemester());
semesterDict.put(new PyString(semester.toString()), new PyDictionary());
}
if (!otherStudent.getCourse().equals(course)) {
PyDictionary courseDict = (PyDictionary)
semesterDict.get(new PyString(semester.toString()));
courseDict.put(new PyString(otherStudent.getCourse().getIdentifier()),
createPyGradeDict(otherStudent.getCourse().getExams(), otherStudent));
}
}
return semesterDict;
}
示例9: getMap
import org.python.core.PyDictionary; //导入依赖的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;
/* */ }
示例10: pigToPython
import org.python.core.PyDictionary; //导入依赖的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);
}
}
示例11: SaveTestDataValues
import org.python.core.PyDictionary; //导入依赖的package包/类
protected PyList SaveTestDataValues(PyDictionary pythonArguments) throws QTasteDataException {
PyList oldValues = new PyList();
for (Object oArg : pythonArguments.items()) {
if (oArg instanceof PyTuple) {
PyTuple argType = (PyTuple) oArg;
PyObject[] pyObj = argType.getArray();
assert pyObj[0] instanceof PyString;
String key = pyObj[0].toString();
// store the old value of the passed argument
Object[] oldValue = new Object[2];
oldValue[0] = key;
try {
oldValue[1] = testData.getValue(key);
} catch (QTasteDataException e) {
// do nothing, no testdata to overwrite
oldValue[1] = null;
}
oldValues.add(oldValue);
testData.setValue(key, pyObj[1].toString());
}
}
return oldValues;
}
示例12: initialise
import org.python.core.PyDictionary; //导入依赖的package包/类
private final void initialise()
{
this.classes = new HashMap<ClassName, PyObject>();
// Create a Python Interpreter with its own "path", and its own namespace
// This ensures that one instance does not interfere with another, so
// you can run one Game, then another without any name clashes.
PySystemState systemState = new PySystemState();
PyList pathList = new PyList();
pathList.add( this.manager.getScriptDirectory().getPath() );
pathList.add( this.manager.getIncludeDirectory(this).getPath() );
systemState.path = pathList;
PyDictionary namespace = new PyDictionary();
this.interpreter = new PythonInterpreter( namespace, systemState );
}
示例13: configFromFile
import org.python.core.PyDictionary; //导入依赖的package包/类
@Deprecated
private PySystemState configFromFile(Integer appId, Integer dbId, long whExecId, String configFile) {
prop = new Properties();
if (appId != null) {
prop.setProperty(Constant.APP_ID_KEY, String.valueOf(appId));
}
if (dbId != null) {
prop.setProperty(Constant.DB_ID_KEY, String.valueOf(dbId));
}
prop.setProperty(Constant.WH_EXEC_ID_KEY, String.valueOf(whExecId));
try {
InputStream propFile = new FileInputStream(configFile);
prop.load(propFile);
propFile.close();
} catch (IOException e) {
logger.error("property file '{}' not found", configFile);
e.printStackTrace();
}
PyDictionary config = new PyDictionary();
for (String key : prop.stringPropertyNames()) {
String value = prop.getProperty(key);
config.put(new PyString(key), new PyString(value));
}
PySystemState sys = new PySystemState();
sys.argv.append(config);
return sys;
}
示例14: onReceive
import org.python.core.PyDictionary; //导入依赖的package包/类
@Override
public void onReceive(Object o) throws Exception {
if (o instanceof String) {
Properties whProps = EtlJobPropertyDao.getWherehowsProperties();
PyDictionary config = new PyDictionary();
for (String key : whProps.stringPropertyNames()) {
String value = whProps.getProperty(key);
config.put(new PyString(key), new PyString(value));
}
sys = new PySystemState();
sys.argv.append(config);
interpreter = new PythonInterpreter(null, sys);
String msg = (String) o;
Logger.info("Start build {} tree", msg);
InputStream in = null;
switch (msg) {
case "dataset":
in = EtlJob.class.getClassLoader().getResourceAsStream("jython/DatasetTreeBuilder.py");
break;
case "flow":
//in = EtlJob.class.getClassLoader().getResourceAsStream("jython/FlowTreeBuilder.py");
break;
default:
Logger.error("unknown message : {}", msg);
}
if (in != null) {
interpreter.execfile(in);
in.close();
Logger.info("Finish build {} tree", msg);
} else {
Logger.error("can not find jython script");
}
} else {
throw new Exception("message type is not supported!");
}
}
示例15: getChildren
import org.python.core.PyDictionary; //导入依赖的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;
}