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


Java PyBoolean类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:nickthecoder,项目名称:itchy,代码行数:27,代码来源:PythonLanguage.java

示例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();
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:18,代码来源:JythonFunctionEventCondition.java

示例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);
}
 
开发者ID:djxy,项目名称:MultiScripts,代码行数:12,代码来源:PythonMap.java

示例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);
}
 
开发者ID:djxy,项目名称:MultiScripts,代码行数:8,代码来源:PythonFunction.java

示例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);
}
 
开发者ID:djxy,项目名称:MultiScripts,代码行数:12,代码来源:PythonArray.java

示例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;
	}
}
 
开发者ID:nerdclub-tfg,项目名称:signal-bot-jython,代码行数:32,代码来源:Storage.java

示例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);
    }
}
 
开发者ID:stefanoberdoerfer,项目名称:exmatrikulator,代码行数:21,代码来源:GradeScriptController.java

示例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);
    }
}
 
开发者ID:antivo,项目名称:Parallel-Machine-Simulator,代码行数:8,代码来源:If.java

示例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);
    }
}
 
开发者ID:antivo,项目名称:Parallel-Machine-Simulator,代码行数:8,代码来源:While.java

示例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;
}
 
开发者ID:antivo,项目名称:Parallel-Machine-Simulator,代码行数:11,代码来源:JythonInterpreter.java

示例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;
    }
}
 
开发者ID:kibertoad,项目名称:swampmachine,代码行数:10,代码来源:PyMapWrapper.java

示例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();
}
 
开发者ID:antivo,项目名称:Parallel-Machine-Simulator,代码行数:6,代码来源:JythonInterpreter.java

示例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);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:75,代码来源:JythonUtils.java

示例14: getBoolean

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

示例15: bool2py

import org.python.core.PyBoolean; //导入依赖的package包/类
public static PyBoolean bool2py(final boolean b) { return b ? True : False; } 
开发者ID:MitchWeaver,项目名称:sjgs,代码行数:2,代码来源:PyUtils.java


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