本文整理汇总了Java中org.python.core.PyBoolean类的典型用法代码示例。如果您正苦于以下问题:Java PyBoolean类的具体用法?Java PyBoolean怎么用?Java PyBoolean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PyBoolean类属于org.python.core包,在下文中一共展示了PyBoolean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttribute
import org.python.core.PyBoolean; //导入依赖的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;
}
}
示例2: condition
import org.python.core.PyBoolean; //导入依赖的package包/类
/**
* Checks rule event condition by evaluating the defined knowledge base rule method.
*
* @param rule rule.
* @param event event.
* @return {@code true} if this condition is met.
*/
@Override
public boolean condition(Rule rule, Event event) {
PyObject pyObject = function._jcall(new Object[] { rule, event });
if (!(pyObject instanceof PyBoolean)) {
throw new IllegalArgumentException("Condition method must return boolean value");
}
return ((PyBoolean) pyObject).getBooleanValue();
}
示例3: __eq__
import org.python.core.PyBoolean; //导入依赖的package包/类
@Override
public PyObject __eq__(PyObject other) {
if(other instanceof PythonMap) {
if(isObjectContainer && ((PythonMap) other).isObjectContainer)
return new PyBoolean(((ObjectContainer) mapObject).getObject().equals(((ObjectContainer) ((PythonMap) other).mapObject).getObject()));
return new PyBoolean(mapObject.equals(((PythonMap) other).mapObject));
}
return super.__eq__(other);
}
示例4: __eq__
import org.python.core.PyBoolean; //导入依赖的package包/类
@Override
public PyObject __eq__(PyObject other) {
if(other instanceof PythonFunction)
return new PyBoolean(functionObject.equals(((PythonFunction) other).functionObject));
return super.__eq__(other);
}
示例5: __eq__
import org.python.core.PyBoolean; //导入依赖的package包/类
@Override
public PyObject __eq__(PyObject other) {
if(other instanceof PythonArray) {
if(isObjectContainer && ((PythonArray) other).isObjectContainer)
return new PyBoolean(((ObjectContainer) arrayObject).getObject().equals(((ObjectContainer) ((PythonArray) other).arrayObject).getObject()));
return new PyBoolean(arrayObject.equals(((PythonArray) other).arrayObject));
}
return super.__eq__(other);
}
示例6: toPy
import org.python.core.PyBoolean; //导入依赖的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;
}
}
示例7: booleanGradeToPyBoolean
import org.python.core.PyBoolean; //导入依赖的package包/类
/**
* Converts a grade of the type boolean grade to a Python Boolean object.
* @param grade A grade of the type GradeType.Boolean. It must have as value
* either "0" for not passed or "1" for passed.
* If the gradeType is not a boolean grade or the value of the
* grade does not match, an None gets returned;
* @return A PyBoolean which is true if the grade has a value of 1, or false
* if the grade has a value of 0.
*/
private PyObject booleanGradeToPyBoolean(Grade grade) {
log.debug("booleanGradeToPyBoolean called with " + grade);
if (grade.getValue().compareTo(new BigDecimal("1")) == 0) {
return new PyBoolean(true);
} else if (grade.getValue().compareTo(new BigDecimal("0")) == 0) {
return new PyBoolean(false);
} else {
log.error("Grade had a GradeType of boolean, but didnt have the right values");
return pyInterpreter.get(PY_NONE);
}
}
示例8: evaluate
import org.python.core.PyBoolean; //导入依赖的package包/类
private boolean evaluate() throws SyntaxException {
try {
return ((PyBoolean) pythonInterpreter.eval(expression)).getBooleanValue();
} catch (Exception e) {
throw SyntaxException.invalidExpression(expression);
}
}
示例9: getValue
import org.python.core.PyBoolean; //导入依赖的package包/类
private boolean getValue() throws SyntaxException {
try {
return ((PyBoolean) pythonInterpreter.eval(expression)).getBooleanValue();
} catch(Exception e) {
throw SyntaxException.invalidExpression(expression);
}
}
示例10: isPrimitiveLocation
import org.python.core.PyBoolean; //导入依赖的package包/类
@Override
public boolean isPrimitiveLocation(String var) {
for(String primitiveLocation : PRIMITIVE_MEMORY_LOCATIONS) {
PyBoolean isObject = (PyBoolean) interactiveConsole.eval("isinstance("+ var + ", " + primitiveLocation + ")");
if(isObject.getBooleanValue()){
return true;
}
}
return false;
}
示例11: convertSupportedValues
import org.python.core.PyBoolean; //导入依赖的package包/类
private Object convertSupportedValues(PyObject object) {
if (object instanceof PyBoolean) {
return ((PyBoolean) object).getBooleanValue();
} else if (object instanceof PyInteger) {
return ((PyInteger) object).getValue();
} else {
return object;
}
}
示例12: is
import org.python.core.PyBoolean; //导入依赖的package包/类
@Override
public boolean is(String x, String y) {
PyBoolean isSame = (PyBoolean) interactiveConsole.eval(x + " is " + y);
return isSame.getBooleanValue();
}
示例13: pythonToPig
import org.python.core.PyBoolean; //导入依赖的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);
}
}
示例14: getBoolean
import org.python.core.PyBoolean; //导入依赖的package包/类
/**
* Get PyBoolean from a boolean column
*
* @return PyBoolean
*/
public PyBoolean getBoolean() {
return new PyBoolean(column.getBoolean());
}
示例15: bool2py
import org.python.core.PyBoolean; //导入依赖的package包/类
public static PyBoolean bool2py(final boolean b) { return b ? True : False; }